提交 b8557693 编写于 作者: taohebin@dcloud.io's avatar taohebin@dcloud.io

update: 补充部分ext-api的自动化测试

上级 8f325407
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);
});
});
...@@ -27,7 +27,9 @@ export default { ...@@ -27,7 +27,9 @@ export default {
title: 'downloadFile', title: 'downloadFile',
imageSrc: '', imageSrc: '',
task: null as DownloadTask | null, task: null as DownloadTask | null,
pageVisible: false pageVisible: false,
//自动化测试例专用
jest_result: false
} }
}, },
onLoad() { onLoad() {
...@@ -66,7 +68,19 @@ export default { ...@@ -66,7 +68,19 @@ export default {
console.log("progress : ", update.progress); 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> </script>
......
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)
});
});
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);
}
}
});
});
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);
}
}
});
});
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);
});
});
...@@ -27,7 +27,9 @@ ...@@ -27,7 +27,9 @@
hasNetworkType: false, hasNetworkType: false,
networkType: '', networkType: '',
connectedWifi: '', connectedWifi: '',
pageVisible: false pageVisible: false,
//自动化测试例专用
jest_result:false,
} }
}, },
onLoad() { onLoad() {
...@@ -60,7 +62,18 @@ ...@@ -60,7 +62,18 @@
this.hasNetworkType = false; this.hasNetworkType = false;
this.networkType = ''; this.networkType = '';
this.connectedWifi = ''; this.connectedWifi = '';
}, },
//自动化测试例专用
jest_getNetworkType(){
uni.getNetworkType({
success: () => {
this.jest_result = true;
},
fail: () => {
this.jest_result = false;
}
})
}
} }
} }
</script> </script>
......
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
...@@ -69,7 +69,11 @@ export default { ...@@ -69,7 +69,11 @@ export default {
} }
}, },
}) })
} },
//自动化测试例专用
jest_getSystemInfo():GetSystemInfoResult{
return uni.getSystemInfoSync();
},
} }
} }
</script> </script>
......
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);
}
}
});
});
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);
}
}
});
});
...@@ -47,7 +47,11 @@ ...@@ -47,7 +47,11 @@
this.items.push(item); this.items.push(item);
} }
} }
} },
//自动化测试例专用
jest_getWindowInfo():GetWindowInfoResult{
return uni.getWindowInfo();
},
} }
} }
</script> </script>
......
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');
});
});
<template> <template>
<view style="flex: 1;"> <view style="flex: 1;">
<view class="uni-padding-wrap uni-common-mt"> <view class="uni-padding-wrap uni-common-mt">
<view class="uni-common-mt" style="border-width: 2rpx;border-radius: 4rpx;"> <view class="uni-common-mt" style="border-width: 2rpx;border-radius: 4rpx;">
<textarea :value="res" class="uni-textarea"></textarea> <textarea :value="res" class="uni-textarea"></textarea>
</view> </view>
<view> <view>
<text>地址 : {{ host + url}}</text> <text>地址 : {{ host + url}}</text>
<text>请求方式 : {{method}}</text> <text>请求方式 : {{method}}</text>
</view> </view>
<view class="uni-btn-v uni-common-mt"> <view class="uni-btn-v uni-common-mt">
<button type="primary" @click="sendRequest">发起请求</button> <button type="primary" @click="sendRequest">发起请求</button>
</view> </view>
</view> </view>
<scroll-view style="flex: 1;" show-scrollbar="true"> <scroll-view style="flex: 1;" show-scrollbar="true">
<view style="padding: 20rpx;"> <view style="padding: 20rpx;">
<text>设置请求方式</text> <text>设置请求方式</text>
<view class="uni-common-pb"></view> <view class="uni-common-pb"></view>
<view style="flex-direction: row;flex-wrap: wrap;"> <view style="flex-direction: row;flex-wrap: wrap;">
<button style="padding: 5rpx; margin-right: 10rpx;" type="primary" size="mini" <button style="padding: 5rpx; margin-right: 10rpx;" type="primary" size="mini"
@click="changeMethod('GET')">GET</button> @click="changeMethod('GET')">GET</button>
<button style="padding: 5rpx; margin-right: 10rpx; " type="primary" size="mini" <button style="padding: 5rpx; margin-right: 10rpx; " type="primary" size="mini"
@click="changeMethod('POST')">POST</button> @click="changeMethod('POST')">POST</button>
<button style="padding: 5rpx; margin-right: 10rpx; " type="primary" size="mini" <button style="padding: 5rpx; margin-right: 10rpx; " type="primary" size="mini"
@click="changeMethod('PUT')">PUT</button> @click="changeMethod('PUT')">PUT</button>
<button style="padding: 5rpx; margin-right: 10rpx;" type="primary" size="mini" <button style="padding: 5rpx; margin-right: 10rpx;" type="primary" size="mini"
@click="changeMethod('DELETE')">DELETE</button> @click="changeMethod('DELETE')">DELETE</button>
<button style="padding: 5rpx; margin-right: 10rpx; " type="primary" size="mini" <button style="padding: 5rpx; margin-right: 10rpx; " type="primary" size="mini"
@click="changeMethod('PATCH')">PATCH</button> @click="changeMethod('PATCH')">PATCH</button>
<button style="padding: 5rpx;margin-right: 10rpx;" type="primary" size="mini" <button style="padding: 5rpx;margin-right: 10rpx;" type="primary" size="mini"
@click="changeMethod('OPTIONS')">OPTIONS</button> @click="changeMethod('OPTIONS')">OPTIONS</button>
<button style="padding: 5rpx;" type="primary" size="mini" <button style="padding: 5rpx;" type="primary" size="mini" @click="changeMethod('HEAD')">HEAD</button>
@click="changeMethod('HEAD')">HEAD</button> </view>
</view> </view>
</view> <view style="padding: 20rpx;">
<view style="padding: 20rpx;"> <text>请求返回错误码的接口(默认为GET)</text>
<text>请求返回错误码的接口(默认为GET)</text> <view class="uni-common-pb"></view>
<view class="uni-common-pb"></view> <view style="flex-direction: row;flex-wrap: wrap;">
<view style="flex-direction: row;flex-wrap: wrap;"> <button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in errorCodeUrls" :key="index"
<button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in errorCodeUrls" @click="changeUrl(item)">{{item}}</button>
:key="index" @click="changeUrl(item)">{{item}}</button> </view>
</view> </view>
</view> <view style="padding: 20rpx;">
<view style="padding: 20rpx;"> <text>请求不同header的接口(默认为GET)</text>
<text>请求不同header的接口(默认为GET)</text> <view class="uni-common-pb"></view>
<view class="uni-common-pb"></view> <view style="flex-direction: row;flex-wrap: wrap;">
<view style="flex-direction: row;flex-wrap: wrap;"> <button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in headerUrls" :key="index"
<button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in headerUrls" @click="changeUrl(item)">{{item}}</button>
:key="index" @click="changeUrl(item)">{{item}}</button> </view>
</view> </view>
</view> <view style="padding: 20rpx;">
<view style="padding: 20rpx;"> <text>请求不同content-type的接口(默认为GET)</text>
<text>请求不同content-type的接口(默认为GET)</text> <view class="uni-common-pb"></view>
<view class="uni-common-pb"></view> <view style="flex-direction: row;flex-wrap: wrap;">
<view style="flex-direction: row;flex-wrap: wrap;"> <button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in contentTypeUrls"
<button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in contentTypeUrls" :key="index" @click="changeUrl(item)">{{item}}</button>
:key="index" @click="changeUrl(item)">{{item}}</button> </view>
</view> </view>
</view>
<view style="padding: 20rpx;"> <view style="padding: 20rpx;">
<text>POST请求(有body)</text> <text>POST请求(有body)</text>
<view class="uni-common-pb"></view> <view class="uni-common-pb"></view>
<view style="flex-direction: row;flex-wrap: wrap;"> <view style="flex-direction: row;flex-wrap: wrap;">
<button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in postUrls" <button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in postUrls" :key="index"
:key="index" @click="changeUrlFromPost(item)">{{item}}</button> @click="changeUrlFromPost(item)">{{item}}</button>
</view> </view>
</view> </view>
</scroll-view> </scroll-view>
</view> </view>
</template> </template>
<script> <script>
const duration = 2000 const duration = 2000
const methodMap = { const methodMap = {
"GET": "/api/http/method/get", "GET": "/api/http/method/get",
"POST": "/api/http/method/post", "POST": "/api/http/method/post",
"PUT": "/api/http/method/put", "PUT": "/api/http/method/put",
"DELETE": "/api/http/method/delete", "DELETE": "/api/http/method/delete",
"PATCH": "/api/http/method/patch", "PATCH": "/api/http/method/patch",
"OPTIONS": "/api/http/method/options", "OPTIONS": "/api/http/method/options",
"HEAD": "/api/http/method/head" "HEAD": "/api/http/method/head"
} }
export default { export default {
data() { data() {
return { return {
title: 'request', title: 'request',
res: '', res: '',
task: null as RequestTask | null, task: null as RequestTask | null,
pageVisible: false, pageVisible: false,
host: "http://request.dcloud.net.cn", host: "http://request.dcloud.net.cn",
url: "/api/http/method/get", url: "/api/http/method/get",
method: "GET", method: "GET",
data: null as any | null, data: null as any | null,
header: null as UTSJSONObject | null, header: null as UTSJSONObject | null,
errorCodeUrls: [ errorCodeUrls: [
"/api/http/statusCode/200", "/api/http/statusCode/200",
"/api/http/statusCode/204", "/api/http/statusCode/204",
"/api/http/statusCode/301", "/api/http/statusCode/301",
"/api/http/statusCode/302", "/api/http/statusCode/302",
"/api/http/statusCode/307", "/api/http/statusCode/307",
"/api/http/statusCode/400", "/api/http/statusCode/400",
"/api/http/statusCode/401", "/api/http/statusCode/401",
"/api/http/statusCode/403", "/api/http/statusCode/403",
"/api/http/statusCode/404", "/api/http/statusCode/404",
"/api/http/statusCode/405", "/api/http/statusCode/405",
"/api/http/statusCode/500", "/api/http/statusCode/500",
"/api/http/statusCode/502", "/api/http/statusCode/502",
"/api/http/statusCode/503", "/api/http/statusCode/503",
"/api/http/statusCode/504", "/api/http/statusCode/504",
], ],
headerUrls: [ headerUrls: [
"/api/http/header/ua", "/api/http/header/ua",
"/api/http/header/referer", "/api/http/header/referer",
"/api/http/header/requestCookie", "/api/http/header/requestCookie",
"/api/http/header/setCookie", "/api/http/header/setCookie",
"/api/http/header/deleteCookie" "/api/http/header/deleteCookie"
], ],
contentTypeUrls: [ contentTypeUrls: [
"/api/http/contentType/text/plain", "/api/http/contentType/text/plain",
"/api/http/contentType/text/html", "/api/http/contentType/text/html",
"/api/http/contentType/text/xml", "/api/http/contentType/text/xml",
"/api/http/contentType/image/gif", "/api/http/contentType/image/gif",
"/api/http/contentType/image/jpeg", "/api/http/contentType/image/jpeg",
"/api/http/contentType/image/png", "/api/http/contentType/image/png",
"/api/http/contentType/application/json", "/api/http/contentType/application/json",
"/api/http/contentType/application/octetStream", "/api/http/contentType/application/octetStream",
], ],
postUrls: [ postUrls: [
"/api/http/contentType/json", "/api/http/contentType/json",
"/api/http/contentType/xWwwFormUrlencoded", "/api/http/contentType/xWwwFormUrlencoded",
], ],
} //自动化测试例专用
}, jest_result: false
onLoad() { }
this.pageVisible = true; },
}, onLoad() {
onUnload() { this.pageVisible = true;
this.pageVisible = false; },
uni.hideLoading(); onUnload() {
this.task?.abort(); this.pageVisible = false;
}, uni.hideLoading();
methods: { this.task?.abort();
changeMethod(e : string) { },
this.method = e; methods: {
this.url = methodMap[e] as string; changeMethod(e : string) {
this.data = null; this.method = e;
this.header = null; this.url = methodMap[e] as string;
}, this.data = null;
changeUrl(e : string) { this.header = null;
this.method = "GET"; },
this.url = e; changeUrl(e : string) {
this.data = null; this.method = "GET";
this.header = null; this.url = e;
}, this.data = null;
changeUrlFromPost(e : string) { this.header = null;
this.method = "POST"; },
this.url = e; changeUrlFromPost(e : string) {
switch (e) { this.method = "POST";
case "/api/http/contentType/json": this.url = e;
this.header = { switch (e) {
"Content-Type": "application/json" case "/api/http/contentType/json":
}; this.header = {
this.data = { "Content-Type": "application/json"
"hello": "world" };
}; this.data = {
break; "hello": "world"
case "/api/http/contentType/xWwwFormUrlencoded": };
this.header = { break;
"Content-Type": "application/x-www-form-urlencoded" case "/api/http/contentType/xWwwFormUrlencoded":
}; this.header = {
this.data = "hello=world"; "Content-Type": "application/x-www-form-urlencoded"
break; };
} this.data = "hello=world";
}, break;
sendRequest() { }
uni.showLoading({ },
title: "请求中..." sendRequest() {
}) uni.showLoading({
this.task = uni.request({ title: "请求中..."
url: this.host + this.url, })
// dataType: "json", this.task = uni.request({
// responseType: "json", url: this.host + this.url,
method: this.method, // dataType: "json",
data: this.data, // responseType: "json",
header: this.header, method: this.method,
timeout: 6000, data: this.data,
sslVerify: false, header: this.header,
withCredentials: false, timeout: 6000,
firstIpv4: false, sslVerify: false,
success(res) { withCredentials: false,
if (this.pageVisible) { firstIpv4: false,
console.log('request success', JSON.stringify(res.data)) success(res) {
uni.showToast({ if (this.pageVisible) {
title: '请求成功', console.log('request success', JSON.stringify(res.data))
icon: 'success', uni.showToast({
mask: true, title: '请求成功',
duration: duration icon: 'success',
}); mask: true,
this.res = '请求结果 : ' + JSON.stringify(res); duration: duration
} });
}, this.res = '请求结果 : ' + JSON.stringify(res);
fail(err) { }
if (this.pageVisible) { },
console.log('request fail', err); fail(err) {
uni.showModal({ if (this.pageVisible) {
content: err.errMsg, console.log('request fail', err);
showCancel: false uni.showModal({
}); content: err.errMsg,
} showCancel: false
}, });
complete() { }
uni.hideLoading() },
}, 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> </script>
\ No newline at end of file
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);
});
});
...@@ -29,7 +29,9 @@ export default { ...@@ -29,7 +29,9 @@ export default {
title: 'uploadFile', title: 'uploadFile',
imageSrc: '', imageSrc: '',
task: null as UploadTask | null, task: null as UploadTask | null,
pageVisible: false pageVisible: false,
//自动化测试例专用
jest_result:false,
} }
}, },
onLoad() { onLoad() {
...@@ -52,7 +54,7 @@ export default { ...@@ -52,7 +54,7 @@ export default {
var imageSrc = res.tempFilePaths[0] var imageSrc = res.tempFilePaths[0]
uni.showLoading({ uni.showLoading({
title: '上传中' title: '上传中'
}) })
this.task = uni.uploadFile({ this.task = uni.uploadFile({
url: 'https://unidemo.dcloud.net.cn/upload', //仅为示例,非真实的接口地址 url: 'https://unidemo.dcloud.net.cn/upload', //仅为示例,非真实的接口地址
filePath: imageSrc, filePath: imageSrc,
...@@ -88,7 +90,25 @@ export default { ...@@ -88,7 +90,25 @@ export default {
console.log('chooseImage fail', err) 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> </script>
......
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);
});
});
...@@ -35,7 +35,9 @@ export default { ...@@ -35,7 +35,9 @@ export default {
socketTask: null as SocketTask | null, socketTask: null as SocketTask | null,
msg: '', msg: '',
platform: '', platform: '',
pageVisible: false, pageVisible: false,
//自动化测试例专用
jest_result: 0,
} }
}, },
computed: { computed: {
...@@ -144,7 +146,7 @@ export default { ...@@ -144,7 +146,7 @@ export default {
this.socketTask?.send({ this.socketTask?.send({
data, data,
success(res: any) { success(res: any) {
console.log(res) console.log(res)
}, },
fail(err: any) { fail(err: any) {
console.log(err) console.log(err)
...@@ -162,7 +164,38 @@ export default { ...@@ -162,7 +164,38 @@ export default {
console.log('uni.closeSocket fail', err) console.log('uni.closeSocket fail', err)
}, },
} as CloseSocketOptions) } 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> </script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册