Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Accustomed_
hello uni-app x
提交
b8557693
H
hello uni-app x
项目概览
Accustomed_
/
hello uni-app x
与 Fork 源项目一致
Fork自
DCloud / hello uni-app x
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
b8557693
编写于
9月 25, 2023
作者:
taohebin@dcloud.io
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update: 补充部分ext-api的自动化测试
上级
8f325407
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
679 addition
and
225 deletion
+679
-225
pages/API/download-file/download-file.test.js
pages/API/download-file/download-file.test.js
+18
-0
pages/API/download-file/download-file.uvue
pages/API/download-file/download-file.uvue
+16
-2
pages/API/get-app-authorize-setting/get-app-authorize-setting.test.js
...t-app-authorize-setting/get-app-authorize-setting.test.js
+34
-0
pages/API/get-app-base-info/get-app-base-info.test.js
pages/API/get-app-base-info/get-app-base-info.test.js
+31
-0
pages/API/get-device-info/get-device-info.test.js
pages/API/get-device-info/get-device-info.test.js
+28
-0
pages/API/get-network-type/get-network-type.test.js
pages/API/get-network-type/get-network-type.test.js
+18
-0
pages/API/get-network-type/get-network-type.uvue
pages/API/get-network-type/get-network-type.uvue
+15
-2
pages/API/get-system-info/get-system-info.test.js
pages/API/get-system-info/get-system-info.test.js
+40
-0
pages/API/get-system-info/get-system-info.uvue
pages/API/get-system-info/get-system-info.uvue
+5
-1
pages/API/get-system-setting/get-system-setting.test.js
pages/API/get-system-setting/get-system-setting.test.js
+32
-0
pages/API/get-window-info/get-window-info.test.js
pages/API/get-window-info/get-window-info.test.js
+28
-0
pages/API/get-window-info/get-window-info.uvue
pages/API/get-window-info/get-window-info.uvue
+5
-1
pages/API/request/request.test.js
pages/API/request/request.test.js
+79
-0
pages/API/request/request.uvue
pages/API/request/request.uvue
+235
-213
pages/API/upload-file/upload-file.test.js
pages/API/upload-file/upload-file.test.js
+18
-0
pages/API/upload-file/upload-file.uvue
pages/API/upload-file/upload-file.uvue
+23
-3
pages/API/websocket-socketTask/websocket-socketTask.test.js
pages/API/websocket-socketTask/websocket-socketTask.test.js
+18
-0
pages/API/websocket-socketTask/websocket-socketTask.uvue
pages/API/websocket-socketTask/websocket-socketTask.uvue
+36
-3
未找到文件。
pages/API/download-file/download-file.test.js
0 → 100644
浏览文件 @
b8557693
const
PAGE_PATH
=
'
/pages/API/download-file/download-file
'
describe
(
'
ExtApi-DownloadFile
'
,
()
=>
{
let
page
;
let
res
;
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
600
);
await
page
.
callMethod
(
'
jest_downloadFile
'
);
await
page
.
waitFor
(
500
);
res
=
await
page
.
data
(
'
jest_result
'
);
});
it
(
'
Check
'
,
async
()
=>
{
expect
(
res
).
toBe
(
true
);
});
});
pages/API/download-file/download-file.uvue
浏览文件 @
b8557693
...
...
@@ -27,7 +27,9 @@ export default {
title: 'downloadFile',
imageSrc: '',
task: null as DownloadTask | null,
pageVisible: false
pageVisible: false,
//自动化测试例专用
jest_result: false
}
},
onLoad() {
...
...
@@ -66,7 +68,19 @@ export default {
console.log("progress : ", update.progress);
}
})
}
},
//自动化测试例专用
jest_downloadFile(){
uni.downloadFile({
url: "https://web-assets.dcloud.net.cn/unidoc/zh/uni-app.png",
success() {
this.jest_result = true
},
fail: () => {
this.jest_result = false
}
});
}
}
}
</script>
...
...
pages/API/get-app-authorize-setting/get-app-authorize-setting.test.js
0 → 100644
浏览文件 @
b8557693
const
PAGE_PATH
=
'
/pages/API/get-app-authorize-setting/get-app-authorize-setting
'
describe
(
'
ExtApi-GetAppAuthorizeSetting
'
,
()
=>
{
let
page
;
let
res
;
let
commonSupportList
=
[
'
authorized
'
,
'
denied
'
,
'
not determined
'
,
'
config error
'
]
let
locationAccuracySupportList
=
[
'
reduced
'
,
'
full
'
,
'
unsupported
'
]
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
600
);
res
=
await
uni
.
getAppAuthorizeSetting
();
});
it
(
'
Check cameraAuthorized
'
,
async
()
=>
{
expect
(
commonSupportList
).
toContain
(
res
.
cameraAuthorized
)
});
it
(
'
Check locationAuthorized
'
,
async
()
=>
{
expect
(
commonSupportList
).
toContain
(
res
.
locationAuthorized
)
});
it
(
'
Check locationAccuracy
'
,
async
()
=>
{
expect
(
locationAccuracySupportList
).
toContain
(
res
.
locationAccuracy
)
});
it
(
'
Check microphoneAuthorized
'
,
async
()
=>
{
expect
(
commonSupportList
).
toContain
(
res
.
microphoneAuthorized
)
});
it
(
'
Check notificationAuthorized
'
,
async
()
=>
{
expect
(
commonSupportList
).
toContain
(
res
.
notificationAuthorized
)
});
});
pages/API/get-app-base-info/get-app-base-info.test.js
0 → 100644
浏览文件 @
b8557693
const
PAGE_PATH
=
'
/pages/API/get-app-base-info/get-app-base-info
'
describe
(
'
ExtApi-GetAppBaseInfo
'
,
()
=>
{
let
page
;
let
res
;
const
stringProperties
=
[
'
appId
'
,
'
appName
'
,
'
appVersion
'
,
'
appVersionCode
'
,
'
appLanguage
'
,
'
language
'
,
'
version
'
,
'
uniCompileVersion
'
,
'
uniPlatform
'
,
'
uniRuntimeVersion
'
,
]
const
numberProperties
=
[
'
uniCompileVersionCode
'
,
'
uniRuntimeVersionCode
'
]
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
600
);
res
=
await
uni
.
getAppBaseInfo
();
});
it
(
'
Check properties
'
,
async
()
=>
{
for
(
const
key
in
res
)
{
const
value
=
res
[
key
];
expect
(
value
).
not
.
toBeNull
();
if
(
stringProperties
.
indexOf
(
key
)
!=
-
1
)
{
expect
(
value
).
not
.
toBe
(
""
);
}
if
(
numberProperties
.
indexOf
(
key
)
!=
-
1
)
{
expect
(
value
).
toBeGreaterThanOrEqual
(
3.90
);
}
}
});
});
pages/API/get-device-info/get-device-info.test.js
0 → 100644
浏览文件 @
b8557693
const
PAGE_PATH
=
'
/pages/API/get-device-info/get-device-info
'
describe
(
'
ExtApi-GetDeviceInfo
'
,
()
=>
{
let
page
;
let
res
;
const
stringProperties
=
[
'
brand
'
,
'
deviceBrand
'
,
'
deviceId
'
,
'
model
'
,
'
deviceModel
'
,
'
deviceType
'
,
'
devicePixelRatio
'
,
'
system
'
,
'
platform
'
,
'
uniRuntimeVersion
'
,
]
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
600
);
res
=
await
uni
.
getDeviceInfo
();
});
it
(
'
Check properties
'
,
async
()
=>
{
for
(
const
key
in
res
)
{
const
value
=
res
[
key
];
expect
(
value
).
not
.
toBeNull
();
if
(
stringProperties
.
indexOf
(
key
)
!=
-
1
)
{
expect
(
value
).
not
.
toBe
(
""
);
}
if
(
key
==
'
deviceOrientation
'
)
{
expect
([
'
portrait
'
,
'
landscape
'
]).
toContain
(
value
);
}
}
});
});
pages/API/get-network-type/get-network-type.test.js
0 → 100644
浏览文件 @
b8557693
const
PAGE_PATH
=
'
/pages/API/get-network-type/get-network-type
'
describe
(
'
ExtApi-GetNetworkType
'
,
()
=>
{
let
page
;
let
res
;
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
600
);
await
page
.
callMethod
(
'
jest_getNetworkType
'
);
await
page
.
waitFor
(
200
);
res
=
await
page
.
data
(
'
jest_result
'
);
});
it
(
'
Check
'
,
async
()
=>
{
expect
(
res
).
toBe
(
true
);
});
});
pages/API/get-network-type/get-network-type.uvue
浏览文件 @
b8557693
...
...
@@ -27,7 +27,9 @@
hasNetworkType: false,
networkType: '',
connectedWifi: '',
pageVisible: false
pageVisible: false,
//自动化测试例专用
jest_result:false,
}
},
onLoad() {
...
...
@@ -60,7 +62,18 @@
this.hasNetworkType = false;
this.networkType = '';
this.connectedWifi = '';
},
},
//自动化测试例专用
jest_getNetworkType(){
uni.getNetworkType({
success: () => {
this.jest_result = true;
},
fail: () => {
this.jest_result = false;
}
})
}
}
}
</script>
...
...
pages/API/get-system-info/get-system-info.test.js
0 → 100644
浏览文件 @
b8557693
const
PAGE_PATH
=
'
/pages/API/get-system-info/get-system-info
'
describe
(
'
ExtApi-GetSystemInfo
'
,
()
=>
{
let
page
;
let
res
;
const
stringProperties
=
[
'
appId
'
,
'
appLanguage
'
,
'
appName
'
,
'
appVersion
'
,
'
appVersionCode
'
,
'
brand
'
,
'
deviceId
'
,
'
deviceBrand
'
,
'
deviceModel
'
,
'
deviceType
'
,
'
language
'
,
'
model
'
,
'
version
'
,
'
osName
'
,
'
osVersion
'
,
'
osLanguage
'
,
'
platform
'
,
'
system
'
,
'
ua
'
,
'
uniCompileVersion
'
,
'
uniPlatform
'
,
'
uniRuntimeVersion
'
,
'
romName
'
,
'
romVersion
'
,
]
const
numberProperties
=
[
'
osAndroidAPILevel
'
,
'
devicePixelRatio
'
,
'
pixelRatio
'
,
'
screenWidth
'
,
'
screenHeight
'
,
'
statusBarHeight
'
,
'
windowWidth
'
,
'
windowHeight
'
,
'
windowTop
'
,
'
windowBottom
'
,
'
screenTop
'
,
'
uniCompileVersionCode
'
,
'
uniRuntimeVersionCode
'
]
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
600
);
res
=
await
page
.
callMethod
(
'
jest_getSystemInfo
'
)
});
it
(
'
Check GetSystemInfoSync
'
,
async
()
=>
{
for
(
const
key
in
res
)
{
const
value
=
res
[
key
];
expect
(
value
).
not
.
toBeNull
();
if
(
stringProperties
.
indexOf
(
key
)
!=
-
1
)
{
expect
(
value
).
not
.
toBe
(
""
);
}
if
(
numberProperties
.
indexOf
(
key
)
!=
-
1
)
{
expect
(
value
).
toBeGreaterThanOrEqual
(
0
);
}
if
(
key
==
'
deviceOrientation
'
)
{
expect
([
'
portrait
'
,
'
landscape
'
]).
toContain
(
value
);
}
}
});
});
\ No newline at end of file
pages/API/get-system-info/get-system-info.uvue
浏览文件 @
b8557693
...
...
@@ -69,7 +69,11 @@ export default {
}
},
})
}
},
//自动化测试例专用
jest_getSystemInfo():GetSystemInfoResult{
return uni.getSystemInfoSync();
},
}
}
</script>
...
...
pages/API/get-system-setting/get-system-setting.test.js
0 → 100644
浏览文件 @
b8557693
const
PAGE_PATH
=
'
/pages/API/get-system-setting/get-system-setting
'
describe
(
'
ExtApi-GetSystemSetting
'
,
()
=>
{
let
page
;
let
res
;
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
600
);
res
=
await
uni
.
getSystemSetting
()
});
it
(
'
Check GetSystemSetting
'
,
async
()
=>
{
for
(
const
key
in
res
)
{
const
value
=
res
[
key
];
if
(
res
[
'
bluetoothEnabled
'
]
==
undefined
)
{
expect
(
res
[
'
bluetoothError
'
]).
not
.
toBe
(
""
)
}
else
{
expect
(
res
[
'
bluetoothError
'
]
==
undefined
).
toBe
(
true
)
}
if
(
res
[
'
wifiEnabled
'
]
==
undefined
)
{
expect
(
res
[
'
wifiError
'
]).
not
.
toBe
(
""
)
}
else
{
expect
(
res
[
'
wifiError
'
]
==
undefined
).
toBe
(
true
)
}
if
(
key
==
'
deviceOrientation
'
)
{
expect
([
'
portrait
'
,
'
landscape
'
]).
toContain
(
value
);
}
}
});
});
pages/API/get-window-info/get-window-info.test.js
0 → 100644
浏览文件 @
b8557693
const
PAGE_PATH
=
'
/pages/API/get-window-info/get-window-info
'
describe
(
'
ExtApi-GetWindowInfo
'
,
()
=>
{
let
page
;
let
res
;
const
numberProperties
=
[
'
pixelRatio
'
,
'
screenWidth
'
,
'
screenHeight
'
,
'
statusBarHeight
'
,
'
windowWidth
'
,
'
windowHeight
'
,
'
windowTop
'
,
'
windowBottom
'
,
'
screenTop
'
]
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
600
);
res
=
await
page
.
callMethod
(
'
jest_getWindowInfo
'
)
});
it
(
'
Check GetWindowInfo
'
,
async
()
=>
{
for
(
const
key
in
res
)
{
const
value
=
res
[
key
];
expect
(
value
).
not
.
toBeNull
();
if
(
numberProperties
.
indexOf
(
key
)
!=
-
1
)
{
expect
(
value
).
toBeGreaterThanOrEqual
(
0
);
}
}
});
});
pages/API/get-window-info/get-window-info.uvue
浏览文件 @
b8557693
...
...
@@ -47,7 +47,11 @@
this.items.push(item);
}
}
}
},
//自动化测试例专用
jest_getWindowInfo():GetWindowInfoResult{
return uni.getWindowInfo();
},
}
}
</script>
...
...
pages/API/request/request.test.js
0 → 100644
浏览文件 @
b8557693
const
PAGE_PATH
=
'
/pages/API/request/request
'
const
methodMap
=
{
"
GET
"
:
"
/api/http/method/get
"
,
"
POST
"
:
"
/api/http/method/post
"
,
"
PUT
"
:
"
/api/http/method/put
"
,
"
DELETE
"
:
"
/api/http/method/delete
"
,
"
PATCH
"
:
"
/api/http/method/patch
"
,
"
OPTIONS
"
:
"
/api/http/method/options
"
,
"
HEAD
"
:
"
/api/http/method/head
"
}
async
function
request
(
page
,
method
,
header
,
data
,
url
)
{
if
(
url
==
null
)
{
url
=
methodMap
[
method
]
}
await
page
.
setData
({
url
:
url
,
method
:
method
,
data
:
data
,
header
:
header
})
res
=
await
page
.
callMethod
(
'
jest_request
'
)
await
page
.
waitFor
(
200
);
res
=
await
page
.
data
(
'
jest_result
'
);
expect
(
res
).
toBe
(
true
)
}
describe
(
'
ExtApi-Request
'
,
()
=>
{
let
page
;
let
res
;
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
600
);
});
beforeEach
(
async
()
=>
{
await
page
.
setData
({
jest_result
:
false
,
data
:
null
,
header
:
null
})
});
it
(
'
Check GET
'
,
async
()
=>
{
await
request
(
page
,
'
GET
'
);
});
it
(
'
Check POST ContentType Json
'
,
async
()
=>
{
await
request
(
page
,
'
POST
'
,
{
"
Content-Type
"
:
"
application/json
"
},
{
"
hello
"
:
"
world
"
},
"
/api/http/contentType/json
"
);
});
it
(
'
Check POST ContentType Form
'
,
async
()
=>
{
await
request
(
page
,
'
POST
'
,
{
"
Content-Type
"
:
"
application/x-www-form-urlencoded
"
},
"
hello=world
"
,
"
/api/http/contentType/xWwwFormUrlencoded
"
);
});
it
(
'
Check PUT
'
,
async
()
=>
{
await
request
(
page
,
'
PUT
'
);
});
it
(
'
Check DELETE
'
,
async
()
=>
{
await
request
(
page
,
'
DELETE
'
);
});
it
(
'
Check PATCH
'
,
async
()
=>
{
await
request
(
page
,
'
PATCH
'
);
});
it
(
'
Check OPTIONS
'
,
async
()
=>
{
await
request
(
page
,
'
OPTIONS
'
);
});
it
(
'
Check HEAD
'
,
async
()
=>
{
await
request
(
page
,
'
HEAD
'
);
});
});
pages/API/request/request.uvue
浏览文件 @
b8557693
<template>
<view style="flex: 1;">
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-common-mt" style="border-width: 2rpx;border-radius: 4rpx;">
<textarea :value="res" class="uni-textarea"></textarea>
</view>
<view>
<text>地址 : {{ host + url}}</text>
<text>请求方式 : {{method}}</text>
</view>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @click="sendRequest">发起请求</button>
</view>
</view>
<scroll-view style="flex: 1;" show-scrollbar="true">
<view style="padding: 20rpx;">
<text>设置请求方式</text>
<view class="uni-common-pb"></view>
<view style="flex-direction: row;flex-wrap: wrap;">
<button style="padding: 5rpx; margin-right: 10rpx;" type="primary" size="mini"
@click="changeMethod('GET')">GET</button>
<button style="padding: 5rpx; margin-right: 10rpx; " type="primary" size="mini"
@click="changeMethod('POST')">POST</button>
<button style="padding: 5rpx; margin-right: 10rpx; " type="primary" size="mini"
@click="changeMethod('PUT')">PUT</button>
<button style="padding: 5rpx; margin-right: 10rpx;" type="primary" size="mini"
@click="changeMethod('DELETE')">DELETE</button>
<button style="padding: 5rpx; margin-right: 10rpx; " type="primary" size="mini"
@click="changeMethod('PATCH')">PATCH</button>
<button style="padding: 5rpx;margin-right: 10rpx;" type="primary" size="mini"
@click="changeMethod('OPTIONS')">OPTIONS</button>
<button style="padding: 5rpx;" type="primary" size="mini"
@click="changeMethod('HEAD')">HEAD</button>
</view>
</view>
<view style="padding: 20rpx;">
<text>请求返回错误码的接口(默认为GET)</text>
<view class="uni-common-pb"></view>
<view style="flex-direction: row;flex-wrap: wrap;">
<button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in errorCodeUrls"
:key="index" @click="changeUrl(item)">{{item}}</button>
</view>
</view>
<view style="padding: 20rpx;">
<text>请求不同header的接口(默认为GET)</text>
<view class="uni-common-pb"></view>
<view style="flex-direction: row;flex-wrap: wrap;">
<button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in headerUrls"
:key="index" @click="changeUrl(item)">{{item}}</button>
</view>
</view>
<view style="padding: 20rpx;">
<text>请求不同content-type的接口(默认为GET)</text>
<view class="uni-common-pb"></view>
<view style="flex-direction: row;flex-wrap: wrap;">
<button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in contentTypeUrls"
:key="index" @click="changeUrl(item)">{{item}}</button>
</view>
</view>
<view style="flex: 1;">
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-common-mt" style="border-width: 2rpx;border-radius: 4rpx;">
<textarea :value="res" class="uni-textarea"></textarea>
</view>
<view>
<text>地址 : {{ host + url}}</text>
<text>请求方式 : {{method}}</text>
</view>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @click="sendRequest">发起请求</button>
</view>
</view>
<scroll-view style="flex: 1;" show-scrollbar="true">
<view style="padding: 20rpx;">
<text>设置请求方式</text>
<view class="uni-common-pb"></view>
<view style="flex-direction: row;flex-wrap: wrap;">
<button style="padding: 5rpx; margin-right: 10rpx;" type="primary" size="mini"
@click="changeMethod('GET')">GET</button>
<button style="padding: 5rpx; margin-right: 10rpx; " type="primary" size="mini"
@click="changeMethod('POST')">POST</button>
<button style="padding: 5rpx; margin-right: 10rpx; " type="primary" size="mini"
@click="changeMethod('PUT')">PUT</button>
<button style="padding: 5rpx; margin-right: 10rpx;" type="primary" size="mini"
@click="changeMethod('DELETE')">DELETE</button>
<button style="padding: 5rpx; margin-right: 10rpx; " type="primary" size="mini"
@click="changeMethod('PATCH')">PATCH</button>
<button style="padding: 5rpx;margin-right: 10rpx;" type="primary" size="mini"
@click="changeMethod('OPTIONS')">OPTIONS</button>
<button style="padding: 5rpx;" type="primary" size="mini" @click="changeMethod('HEAD')">HEAD</button>
</view>
</view>
<view style="padding: 20rpx;">
<text>请求返回错误码的接口(默认为GET)</text>
<view class="uni-common-pb"></view>
<view style="flex-direction: row;flex-wrap: wrap;">
<button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in errorCodeUrls" :key="index"
@click="changeUrl(item)">{{item}}</button>
</view>
</view>
<view style="padding: 20rpx;">
<text>请求不同header的接口(默认为GET)</text>
<view class="uni-common-pb"></view>
<view style="flex-direction: row;flex-wrap: wrap;">
<button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in headerUrls" :key="index"
@click="changeUrl(item)">{{item}}</button>
</view>
</view>
<view style="padding: 20rpx;">
<text>请求不同content-type的接口(默认为GET)</text>
<view class="uni-common-pb"></view>
<view style="flex-direction: row;flex-wrap: wrap;">
<button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in contentTypeUrls"
:key="index" @click="changeUrl(item)">{{item}}</button>
</view>
</view>
<view style="padding: 20rpx;">
<text>POST请求(有body)</text>
<view class="uni-common-pb"></view>
<view style="flex-direction: row;flex-wrap: wrap;">
<button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in postUrls
"
:key="index"
@click="changeUrlFromPost(item)">{{item}}</button>
</view>
</view>
</scroll-view>
</view>
<view style="padding: 20rpx;">
<text>POST请求(有body)</text>
<view class="uni-common-pb"></view>
<view style="flex-direction: row;flex-wrap: wrap;">
<button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in postUrls" :key="index
"
@click="changeUrlFromPost(item)">{{item}}</button>
</view>
</view>
</scroll-view>
</view>
</template>
<script>
const duration = 2000
const methodMap = {
"GET": "/api/http/method/get",
"POST": "/api/http/method/post",
"PUT": "/api/http/method/put",
"DELETE": "/api/http/method/delete",
"PATCH": "/api/http/method/patch",
"OPTIONS": "/api/http/method/options",
"HEAD": "/api/http/method/head"
}
const duration = 2000
const methodMap = {
"GET": "/api/http/method/get",
"POST": "/api/http/method/post",
"PUT": "/api/http/method/put",
"DELETE": "/api/http/method/delete",
"PATCH": "/api/http/method/patch",
"OPTIONS": "/api/http/method/options",
"HEAD": "/api/http/method/head"
}
export default {
data() {
return {
title: 'request',
res: '',
task: null as RequestTask | null,
pageVisible: false,
host: "http://request.dcloud.net.cn",
url: "/api/http/method/get",
method: "GET",
data: null as any | null,
header: null as UTSJSONObject | null,
errorCodeUrls: [
"/api/http/statusCode/200",
"/api/http/statusCode/204",
"/api/http/statusCode/301",
"/api/http/statusCode/302",
"/api/http/statusCode/307",
"/api/http/statusCode/400",
"/api/http/statusCode/401",
"/api/http/statusCode/403",
"/api/http/statusCode/404",
"/api/http/statusCode/405",
"/api/http/statusCode/500",
"/api/http/statusCode/502",
"/api/http/statusCode/503",
"/api/http/statusCode/504",
],
headerUrls: [
"/api/http/header/ua",
"/api/http/header/referer",
"/api/http/header/requestCookie",
"/api/http/header/setCookie",
"/api/http/header/deleteCookie"
],
contentTypeUrls: [
"/api/http/contentType/text/plain",
"/api/http/contentType/text/html",
"/api/http/contentType/text/xml",
"/api/http/contentType/image/gif",
"/api/http/contentType/image/jpeg",
"/api/http/contentType/image/png",
"/api/http/contentType/application/json",
"/api/http/contentType/application/octetStream",
],
postUrls: [
"/api/http/contentType/json",
"/api/http/contentType/xWwwFormUrlencoded",
],
}
},
onLoad() {
this.pageVisible = true;
},
onUnload() {
this.pageVisible = false;
uni.hideLoading();
this.task?.abort();
},
methods: {
changeMethod(e : string) {
this.method = e;
this.url = methodMap[e] as string;
this.data = null;
this.header = null;
},
changeUrl(e : string) {
this.method = "GET";
this.url = e;
this.data = null;
this.header = null;
},
changeUrlFromPost(e : string) {
this.method = "POST";
this.url = e;
switch (e) {
case "/api/http/contentType/json":
this.header = {
"Content-Type": "application/json"
};
this.data = {
"hello": "world"
};
break;
case "/api/http/contentType/xWwwFormUrlencoded":
this.header = {
"Content-Type": "application/x-www-form-urlencoded"
};
this.data = "hello=world";
break;
}
},
sendRequest() {
uni.showLoading({
title: "请求中..."
})
this.task = uni.request({
url: this.host + this.url,
// dataType: "json",
// responseType: "json",
method: this.method,
data: this.data,
header: this.header,
timeout: 6000,
sslVerify: false,
withCredentials: false,
firstIpv4: false,
success(res) {
if (this.pageVisible) {
console.log('request success', JSON.stringify(res.data))
uni.showToast({
title: '请求成功',
icon: 'success',
mask: true,
duration: duration
});
this.res = '请求结果 : ' + JSON.stringify(res);
}
},
fail(err) {
if (this.pageVisible) {
console.log('request fail', err);
uni.showModal({
content: err.errMsg,
showCancel: false
});
}
},
complete() {
uni.hideLoading()
},
});
}
}
}
export default {
data() {
return {
title: 'request',
res: '',
task: null as RequestTask | null,
pageVisible: false,
host: "http://request.dcloud.net.cn",
url: "/api/http/method/get",
method: "GET",
data: null as any | null,
header: null as UTSJSONObject | null,
errorCodeUrls: [
"/api/http/statusCode/200",
"/api/http/statusCode/204",
"/api/http/statusCode/301",
"/api/http/statusCode/302",
"/api/http/statusCode/307",
"/api/http/statusCode/400",
"/api/http/statusCode/401",
"/api/http/statusCode/403",
"/api/http/statusCode/404",
"/api/http/statusCode/405",
"/api/http/statusCode/500",
"/api/http/statusCode/502",
"/api/http/statusCode/503",
"/api/http/statusCode/504",
],
headerUrls: [
"/api/http/header/ua",
"/api/http/header/referer",
"/api/http/header/requestCookie",
"/api/http/header/setCookie",
"/api/http/header/deleteCookie"
],
contentTypeUrls: [
"/api/http/contentType/text/plain",
"/api/http/contentType/text/html",
"/api/http/contentType/text/xml",
"/api/http/contentType/image/gif",
"/api/http/contentType/image/jpeg",
"/api/http/contentType/image/png",
"/api/http/contentType/application/json",
"/api/http/contentType/application/octetStream",
],
postUrls: [
"/api/http/contentType/json",
"/api/http/contentType/xWwwFormUrlencoded",
],
//自动化测试例专用
jest_result: false
}
},
onLoad() {
this.pageVisible = true;
},
onUnload() {
this.pageVisible = false;
uni.hideLoading();
this.task?.abort();
},
methods: {
changeMethod(e : string) {
this.method = e;
this.url = methodMap[e] as string;
this.data = null;
this.header = null;
},
changeUrl(e : string) {
this.method = "GET";
this.url = e;
this.data = null;
this.header = null;
},
changeUrlFromPost(e : string) {
this.method = "POST";
this.url = e;
switch (e) {
case "/api/http/contentType/json":
this.header = {
"Content-Type": "application/json"
};
this.data = {
"hello": "world"
};
break;
case "/api/http/contentType/xWwwFormUrlencoded":
this.header = {
"Content-Type": "application/x-www-form-urlencoded"
};
this.data = "hello=world";
break;
}
},
sendRequest() {
uni.showLoading({
title: "请求中..."
})
this.task = uni.request({
url: this.host + this.url,
// dataType: "json",
// responseType: "json",
method: this.method,
data: this.data,
header: this.header,
timeout: 6000,
sslVerify: false,
withCredentials: false,
firstIpv4: false,
success(res) {
if (this.pageVisible) {
console.log('request success', JSON.stringify(res.data))
uni.showToast({
title: '请求成功',
icon: 'success',
mask: true,
duration: duration
});
this.res = '请求结果 : ' + JSON.stringify(res);
}
},
fail(err) {
if (this.pageVisible) {
console.log('request fail', err);
uni.showModal({
content: err.errMsg,
showCancel: false
});
}
},
complete() {
uni.hideLoading()
},
});
},
//自动化测试例专用
jest_request() {
uni.request({
url: this.host + this.url,
// dataType: "json",
// responseType: "json",
method: this.method,
data: this.data,
header: this.header,
timeout: 6000,
sslVerify: false,
withCredentials: false,
firstIpv4: false,
success() {
this.jest_result = true;
},
fail() {
this.jest_result = false;
},
});
}
}
}
</script>
\ No newline at end of file
pages/API/upload-file/upload-file.test.js
0 → 100644
浏览文件 @
b8557693
const
PAGE_PATH
=
'
/pages/API/upload-file/upload-file
'
describe
(
'
ExtApi-UploadFile
'
,
()
=>
{
let
page
;
let
res
;
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
600
);
await
page
.
callMethod
(
'
jest_uploadFile
'
);
await
page
.
waitFor
(
500
);
res
=
await
page
.
data
(
'
jest_result
'
);
});
it
(
'
Check
'
,
async
()
=>
{
expect
(
res
).
toBe
(
true
);
});
});
pages/API/upload-file/upload-file.uvue
浏览文件 @
b8557693
...
...
@@ -29,7 +29,9 @@ export default {
title: 'uploadFile',
imageSrc: '',
task: null as UploadTask | null,
pageVisible: false
pageVisible: false,
//自动化测试例专用
jest_result:false,
}
},
onLoad() {
...
...
@@ -52,7 +54,7 @@ export default {
var imageSrc = res.tempFilePaths[0]
uni.showLoading({
title: '上传中'
})
})
this.task = uni.uploadFile({
url: 'https://unidemo.dcloud.net.cn/upload', //仅为示例,非真实的接口地址
filePath: imageSrc,
...
...
@@ -88,7 +90,25 @@ export default {
console.log('chooseImage fail', err)
}
})
}
},
//自动化测试例专用
jest_uploadFile(){
const imageSrc = "/static/uni.png";
this.task = uni.uploadFile({
url: 'https://unidemo.dcloud.net.cn/upload', //仅为示例,非真实的接口地址
filePath: imageSrc,
name: 'file',
formData: {
'user': 'test'
},
success: () => {
this.jest_result = true;
},
fail: () => {
this.jest_result = false;
},
})
}
}
}
</script>
...
...
pages/API/websocket-socketTask/websocket-socketTask.test.js
0 → 100644
浏览文件 @
b8557693
const
PAGE_PATH
=
'
/pages/API/websocket-socketTask/websocket-socketTask
'
describe
(
'
ExtApi-WebSocket
'
,
()
=>
{
let
page
;
let
res
;
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
600
);
await
page
.
callMethod
(
'
jest_connectSocket
'
);
await
page
.
waitFor
(
500
);
res
=
await
page
.
data
(
'
jest_result
'
);
});
it
(
'
Check
'
,
async
()
=>
{
expect
(
res
).
toBe
(
2
);
});
});
pages/API/websocket-socketTask/websocket-socketTask.uvue
浏览文件 @
b8557693
...
...
@@ -35,7 +35,9 @@ export default {
socketTask: null as SocketTask | null,
msg: '',
platform: '',
pageVisible: false,
pageVisible: false,
//自动化测试例专用
jest_result: 0,
}
},
computed: {
...
...
@@ -144,7 +146,7 @@ export default {
this.socketTask?.send({
data,
success(res: any) {
console.log(res)
console.log(res)
},
fail(err: any) {
console.log(err)
...
...
@@ -162,7 +164,38 @@ export default {
console.log('uni.closeSocket fail', err)
},
} as CloseSocketOptions)
},
},
//自动化测试例专用
jest_connectSocket(){
this.socketTask = uni.connectSocket({
url: 'ws://websocket.dcloud.net.cn',
success:(_) => {
this.jest_result++
},
fail:(_) => {
this.jest_result = 0
},
})
this.socketTask?.onOpen((_) => {
const data =
'from ' +
this.platform +
' : ' +
parseInt(Math.random() * 10000 + '').toString()
this.socketTask?.send({
data,
success(_) {
this.jest_result++
},
fail(_) {
this.jest_result = 0
},
} as SendSocketMessageOptions)
})
this.socketTask?.onError((_) => {
this.jest_result = 0;
})
}
},
}
</script>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录