refactor: 确立独立子工程架构 (backend, admin, mpuniapp) 并同步更新 AGENTS.md 规范
这个提交包含在:
@@ -0,0 +1,119 @@
|
||||
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
|
||||
const isMP = platformInfo.startsWith('mp')
|
||||
const isWeb = platformInfo.startsWith('web')
|
||||
const isAndroid = platformInfo.startsWith('android')
|
||||
const isAppWebView = process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true'
|
||||
|
||||
|
||||
describe('ExtApi-DownloadFile', () => {
|
||||
if (isMP) {
|
||||
it('skip', () => {
|
||||
expect(1).toBe(1)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const PAGE_PATH = '/pages/API/download-file/download-file'
|
||||
let page;
|
||||
let res;
|
||||
let timeout = 15000
|
||||
let waitForStartTime
|
||||
async function waitCallbackTriggredOrTimeout(){
|
||||
waitForStartTime = Date.now()
|
||||
await page.waitFor(async () => {
|
||||
const callbackTriggred = await page.data('data.jest_callback_triggred')
|
||||
return callbackTriggred || (Date.now() - waitForStartTime > timeout)
|
||||
})
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
page = await program.reLaunch(PAGE_PATH)
|
||||
await page.waitFor('view');
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
await page.setData({
|
||||
data:{
|
||||
jest_result: false,
|
||||
jest_callback_triggred: false
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
it('Check ', async () => {
|
||||
await page.callMethod('jest_downloadFile');
|
||||
await waitCallbackTriggredOrTimeout()
|
||||
res = await page.data('data.jest_result');
|
||||
expect(res).toBe(true);
|
||||
});
|
||||
|
||||
it('Check Special characters Url download file', async () => {
|
||||
res = await page.callMethod('jest_special_characters_download')
|
||||
await waitCallbackTriggredOrTimeout()
|
||||
res = await page.data('data.jest_result');
|
||||
expect(res).toBe(true)
|
||||
});
|
||||
|
||||
it('Check download call timeout', async () => {
|
||||
res = await page.callMethod('jest_download_call_timeout')
|
||||
await page.waitFor(5000);
|
||||
res = await page.data('data.jest_result');
|
||||
expect(res).toBe(true)
|
||||
})
|
||||
|
||||
if (!(isMP || isWeb)) {
|
||||
it('Check download file long url', async () => {
|
||||
res = await page.callMethod('jest_download_long_url')
|
||||
await waitCallbackTriggredOrTimeout()
|
||||
res = await page.data('data.jest_result');
|
||||
expect(res).toBe(true)
|
||||
});
|
||||
|
||||
it('Check uni.env', async () => {
|
||||
await page.callMethod('jest_downloadFile_with_uni_env');
|
||||
await waitCallbackTriggredOrTimeout()
|
||||
res = await page.data('data.jest_result');
|
||||
expect(res).toBe(true);
|
||||
});
|
||||
|
||||
// 15以下的模拟器所对应的xcode不能编译自定义插件,大于15是因为某台设备,会用xcode14.1跑15.5的设备
|
||||
let version = process.env.uniTestPlatformInfo
|
||||
let split = version.split(" ")
|
||||
version = parseInt(split[split.length - 1])
|
||||
if (!process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios') || version > 15) {
|
||||
it('Check Download File In UTS Module', async () => {
|
||||
res = await page.callMethod('jest_uts_module_invoked')
|
||||
await waitCallbackTriggredOrTimeout()
|
||||
res = await page.data('data.jest_result');
|
||||
expect(res).toBe(true)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let shouldTestCookie = false
|
||||
if (isAndroid && isAppWebView) {
|
||||
let version = process.env.uniTestPlatformInfo
|
||||
version = parseInt(version.split(" ")[1])
|
||||
shouldTestCookie = version > 9
|
||||
} else if (isWeb) {
|
||||
// TODO 测试网址调整后放开此测试
|
||||
shouldTestCookie = false
|
||||
}
|
||||
if (!shouldTestCookie) {
|
||||
return
|
||||
}
|
||||
|
||||
it('Check Set Cookie', async () => {
|
||||
res = await page.callMethod('jest_set_cookie')
|
||||
await waitCallbackTriggredOrTimeout()
|
||||
res = await page.data('data.jest_result');
|
||||
expect(res).toBe(true)
|
||||
});
|
||||
it('Check Delete Cookie', async () => {
|
||||
res = await page.callMethod('jest_delete_cookie')
|
||||
await waitCallbackTriggredOrTimeout()
|
||||
res = await page.data('data.jest_result');
|
||||
expect(res).toBe(true)
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,263 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view style="flex: 1">
|
||||
<!-- #endif -->
|
||||
<view>
|
||||
<page-head :title="data.title"></page-head>
|
||||
<view>
|
||||
<view v-if="data.imageSrc">
|
||||
<image class="img" :src="data.imageSrc" mode="aspectFit" />
|
||||
</view>
|
||||
<view v-else style="margin: 10px;">
|
||||
<text class="uni-hello-text">点击按钮下载服务端示例图片(下载网络文件到本地临时目录)</text>
|
||||
<button type="primary" @tap="downloadImage">下载</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
<script setup lang="uts">
|
||||
// #ifdef APP-ANDROID || APP-IOS || APP-HARMONY
|
||||
import {
|
||||
testInovkeDownloadFile,
|
||||
CommonOptions
|
||||
} from '@/uni_modules/test-invoke-network-api'
|
||||
// #endif
|
||||
|
||||
type DataType = {
|
||||
title: string;
|
||||
imageSrc: string;
|
||||
task: DownloadTask | null;
|
||||
jest_result: boolean;
|
||||
jest_callback_triggred: boolean;
|
||||
}
|
||||
|
||||
const data = reactive({
|
||||
title: 'downloadFile',
|
||||
imageSrc: '',
|
||||
task: null,
|
||||
//自动化测试例专用
|
||||
jest_result: false,
|
||||
jest_callback_triggred: false
|
||||
} as DataType)
|
||||
|
||||
onUnload(() => {
|
||||
// data.imageSrc = '';
|
||||
uni.hideLoading();
|
||||
data.task?.abort();
|
||||
})
|
||||
|
||||
const downloadImage = () => {
|
||||
uni.showLoading({
|
||||
title: '下载中'
|
||||
})
|
||||
data.task = uni.downloadFile({
|
||||
url: "https://web-assets.dcloud.net.cn/hello-uni-app-x/uni-app.png",
|
||||
success: (res) => {
|
||||
console.log('downloadFile success, res is', res.tempFilePath)
|
||||
data.imageSrc = res.tempFilePath;
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log('downloadFile fail, err is:', err)
|
||||
},
|
||||
complete: (res) => {
|
||||
uni.hideLoading();
|
||||
data.task = null;
|
||||
}
|
||||
});
|
||||
data.task?.onProgressUpdate((update) => {
|
||||
console.log("progress : ", update.progress);
|
||||
})
|
||||
}
|
||||
|
||||
const downloadErrorFilename = () => {
|
||||
data.task = uni.downloadFile({
|
||||
url:"https://qiniu-web-assets.dcloud.net.cn/uni-app-x/static/file/test9.txt",
|
||||
success: (res) => {
|
||||
console.log('downloadFile success, res is', res.tempFilePath)
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log('downloadFile fail, err is:', err)
|
||||
},
|
||||
complete: () => {
|
||||
data.task = null
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//自动化测试例专用
|
||||
const jest_downloadFile = () => {
|
||||
data.task = uni.downloadFile({
|
||||
url: "https://web-assets.dcloud.net.cn/hello-uni-app-x/uni-app.png",
|
||||
success: () => {
|
||||
data.jest_result = true
|
||||
data.jest_callback_triggred = true
|
||||
},
|
||||
fail: () => {
|
||||
data.jest_result = false
|
||||
data.jest_callback_triggred = true
|
||||
},
|
||||
complete: () => {
|
||||
data.task = null
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const jest_downloadFile_with_uni_env = () => {
|
||||
data.task = uni.downloadFile({
|
||||
url: "https://web-assets.dcloud.net.cn/hello-uni-app-x/uni-app.png",
|
||||
filePath: `${uni.env.CACHE_PATH}/a/b/`,
|
||||
success: () => {
|
||||
data.jest_result = true
|
||||
data.jest_callback_triggred = true
|
||||
},
|
||||
fail: () => {
|
||||
data.jest_result = false
|
||||
data.jest_callback_triggred = true
|
||||
},
|
||||
complete: () => {
|
||||
data.task = null
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const jest_cookie_download = (needCookie : boolean) => {
|
||||
data.task = uni.downloadFile({
|
||||
url: "https://request.dcloud.net.cn/api/http/header/download",
|
||||
success: () => {
|
||||
data.jest_result = needCookie ? true : false;
|
||||
data.jest_callback_triggred = true
|
||||
},
|
||||
fail: () => {
|
||||
data.jest_result = needCookie ? false : true;
|
||||
},
|
||||
complete: () => {
|
||||
data.task = null
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const jest_set_cookie = () => {
|
||||
uni.request({
|
||||
url: "https://request.dcloud.net.cn/api/http/header/setCookie",
|
||||
method: "GET",
|
||||
timeout: 6000,
|
||||
sslVerify: false,
|
||||
withCredentials: true,
|
||||
firstIpv4: false,
|
||||
success: () => {
|
||||
jest_cookie_download(true)
|
||||
},
|
||||
fail: () => {
|
||||
data.jest_result = false;
|
||||
data.jest_callback_triggred = true
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const jest_delete_cookie = () => {
|
||||
uni.request({
|
||||
url: "https://request.dcloud.net.cn/api/http/header/deleteCookie",
|
||||
method: "GET",
|
||||
timeout: 6000,
|
||||
sslVerify: false,
|
||||
withCredentials: true,
|
||||
firstIpv4: false,
|
||||
success: () => {
|
||||
jest_cookie_download(false)
|
||||
},
|
||||
fail: () => {
|
||||
data.jest_result = false;
|
||||
data.jest_callback_triggred = true
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const jest_uts_module_invoked = () => {
|
||||
// #ifdef APP-ANDROID || APP-IOS || APP-HARMONY
|
||||
testInovkeDownloadFile({
|
||||
success: (res : any) => {
|
||||
data.jest_result = true
|
||||
data.jest_callback_triggred = true
|
||||
},
|
||||
fail: (err : any) => {
|
||||
data.jest_result = false
|
||||
data.jest_callback_triggred = true
|
||||
}
|
||||
} as CommonOptions)
|
||||
// #endif
|
||||
}
|
||||
|
||||
const jest_special_characters_download = () => {
|
||||
data.task = uni.downloadFile({
|
||||
url: "https://web-assets.dcloud.net.cn/hello-uni-app-x/1789834995055525889-你好%23你好.png",
|
||||
success: () => {
|
||||
data.jest_result = true;
|
||||
data.jest_callback_triggred = true
|
||||
},
|
||||
fail: () => {
|
||||
data.jest_result = false;
|
||||
data.jest_callback_triggred = true
|
||||
},
|
||||
complete: () => {
|
||||
data.task = null
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const jest_download_call_timeout = () => {
|
||||
data.task = uni.downloadFile({
|
||||
url: "https://web-assets.dcloud.net.cn/video/sample/2minute-demo-10k.mp4",
|
||||
timeout: 3000,
|
||||
fail: () => {
|
||||
data.jest_result = false;
|
||||
},
|
||||
complete: () => {
|
||||
data.task = null
|
||||
}
|
||||
})
|
||||
setTimeout(() => {
|
||||
data.jest_result = true;
|
||||
}, 4000)
|
||||
}
|
||||
|
||||
const jest_download_long_url = () => {
|
||||
data.task = uni.downloadFile({
|
||||
url: "https://request.dcloud.net.cn/WsQkvvoLPbLFRoZB3NZOhgR8bMbjvpMZMmnzhlH1UtAzbVaOqokI9NBhqgc0pUVesJVQeJoTXjCbuAHqsoGJryxzjo4xf2bR75GTfOgJ5mfDDoX31DY9HTQ0mgLwTlt43MWsRobR22r6qwJYRaZW4yLthUX1BSzckZS9OeKzyV2r3dizxkbAPV3j5toN5qjUq5gYJOHbWfOEdwCA6tftgEGzc3eb6Deed0ngLtNnYYcVOWCzXk24jhYP87g9yh1o9kowdQXUMv4mhwxbvvulLTDC470HqLT1cLm7iuh38L1c8EdMJ6xSCO8y1mxKDzczA0W29mzf54jUfuO7OodX9ZJeFQhCptm73P8oSzyc57BaP9zecVN0u1LwPa4cyj1vMleUSfI2lSzT5PIt2YCojkFEunuFWHRq5vtDQ2ZXQGYIJqSmBDDsVXMAlHAC91F1uWsuC67GgcAPMtrXAyB8HbCA4fiP9iYsKmkKKwMUFx04ehsabTuWnOO6Oms14wrqghKGUJKKXdCaYomcCrRDRUOjIm3NwRKqUN1cHiHI9cxXQbWD8FFb8qBEPrrFscog2dHhQyM8nBbdrk9Lc99ao7bE1s39qiYxSZPnSdfHVb0zfgg9vkm0DTd47pTHz3qOhtWLgNLBLTsCf3HMVG4yZgGcenX3XG2Z6OgG6Pm1DsimJfZtzYU78Cbbp395mdnX6bj3bNNzraV6JVLLiI6diJwtdipIMBFle0t0S0eWMNSGUiZHDwjVTGibHK4PTSd6VkJbBcxSxdmdApn1LiSmxJTciH0auKrSzriVxjDGyQ2bnqyStG",
|
||||
success: () => {
|
||||
data.jest_result = true;
|
||||
data.jest_callback_triggred = true
|
||||
},
|
||||
fail: () => {
|
||||
data.jest_result = false;
|
||||
data.jest_callback_triggred = true
|
||||
},
|
||||
complete: () => {
|
||||
data.task = null
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
data,
|
||||
jest_downloadFile,
|
||||
jest_downloadFile_with_uni_env,
|
||||
jest_set_cookie,
|
||||
jest_delete_cookie,
|
||||
jest_uts_module_invoked,
|
||||
jest_special_characters_download,
|
||||
jest_download_call_timeout,
|
||||
jest_download_long_url
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.img {
|
||||
margin: 0 auto;
|
||||
}
|
||||
</style>
|
||||
在新工单中引用
屏蔽一个用户