提交 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 {
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>
......
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 @@
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>
......
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 {
}
},
})
}
},
//自动化测试例专用
jest_getSystemInfo():GetSystemInfoResult{
return uni.getSystemInfoSync();
},
}
}
</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 @@
this.items.push(item);
}
}
}
},
//自动化测试例专用
jest_getWindowInfo():GetWindowInfoResult{
return uni.getWindowInfo();
},
}
}
</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>
<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
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 {
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>
......
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 {
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.
先完成此消息的编辑!
想要评论请 注册