uniapp vue3 cli项目集成自动化测试,h5、ios和android的自动化测试出错,信息如下:
$ cross-env UNI_PLATFORM=app-plus UNI_OS_NAME=ios jest -i
FAIL src/pages/index/index.test.js
● Test suite failed to run
TypeError: Cannot read properties of undefined (reading 'platform')
at module.exports.setup (node_modules/@dcloudio/uni-automator/dist/environment.js:1:476)
at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:317:13)
at runJest (node_modules/@jest/core/build/runJest.js:407:19)
at _run10000 (node_modules/@jest/core/build/cli/index.js:339:7)
at runCLI (node_modules/@jest/core/build/cli/index.js:190:3)
请问,上述问题如何解决?uniapp vue3项目怎样才能正确集成自动化测试?
附上项目创建流程。
- 参考官网说明(https://uniapp.dcloud.io/quickstart-cli.html#%E5%88%9B%E5%BB%BAuni-app),
使用npx degit dcloudio/uni-preset-vue#vite-ts my-vue3-project
创建项目 - 参考自动化测试uni-app cli项目说明(https://uniapp.dcloud.io/worktile/auto/uniapp-cli-project.html),安装了依赖包。
- 创建了jest.config.js及相应测试代码
以下是最终package.json文件内容{ "name": "uni-preset-vue", "version": "0.0.0", "scripts": { "dev:app": "uni -p app", "dev:custom": "uni -p", "dev:h5": "uni", "dev:h5:ssr": "uni --ssr", "dev:mp-alipay": "uni -p mp-alipay", "dev:mp-baidu": "uni -p mp-baidu", "dev:mp-kuaishou": "uni -p mp-kuaishou", "dev:mp-lark": "uni -p mp-lark", "dev:mp-qq": "uni -p mp-qq", "dev:mp-toutiao": "uni -p mp-toutiao", "dev:mp-weixin": "uni -p mp-weixin", "dev:quickapp-webview": "uni -p quickapp-webview", "dev:quickapp-webview-huawei": "uni -p quickapp-webview-huawei", "dev:quickapp-webview-union": "uni -p quickapp-webview-union", "build:app": "uni build -p app", "build:custom": "uni build -p", "build:h5": "uni build", "build:h5:ssr": "uni build --ssr", "build:mp-alipay": "uni build -p mp-alipay", "build:mp-baidu": "uni build -p mp-baidu", "build:mp-kuaishou": "uni build -p mp-kuaishou", "build:mp-lark": "uni build -p mp-lark", "build:mp-qq": "uni build -p mp-qq", "build:mp-toutiao": "uni build -p mp-toutiao", "build:mp-weixin": "uni build -p mp-weixin", "build:quickapp-webview": "uni build -p quickapp-webview", "build:quickapp-webview-huawei": "uni build -p quickapp-webview-huawei", "build:quickapp-webview-union": "uni build -p quickapp-webview-union", "test:h5": "cross-env UNI_PLATFORM=h5 jest -i", "test:android": "cross-env UNI_PLATFORM=app-plus UNI_OS_NAME=android jest -i", "test:ios": "cross-env UNI_PLATFORM=app-plus UNI_OS_NAME=ios jest -i", "test:mp-weixin": "cross-env UNI_PLATFORM=mp-weixin jest -i", "test:mp-baidu": "cross-env UNI_PLATFORM=mp-baidu jest -i" }, "dependencies": { "@dcloudio/uni-app": "3.0.0-alpha-3041520220609002", "@dcloudio/uni-app-plus": "3.0.0-alpha-3041520220609002", "@dcloudio/uni-components": "3.0.0-alpha-3041520220609002", "@dcloudio/uni-h5": "3.0.0-alpha-3041520220609002", "@dcloudio/uni-mp-alipay": "3.0.0-alpha-3041520220609002", "@dcloudio/uni-mp-baidu": "3.0.0-alpha-3041520220609002", "@dcloudio/uni-mp-kuaishou": "3.0.0-alpha-3041520220609002", "@dcloudio/uni-mp-lark": "3.0.0-alpha-3041520220609002", "@dcloudio/uni-mp-qq": "3.0.0-alpha-3041520220609002", "@dcloudio/uni-mp-toutiao": "3.0.0-alpha-3041520220609002", "@dcloudio/uni-mp-weixin": "3.0.0-alpha-3041520220609002", "@dcloudio/uni-quickapp-webview": "3.0.0-alpha-3041520220609002", "@playwright/test": "^1.22.2", "adbkit": "^2.11.1", "jest": "^28.1.1", "node-simctl": "^7.0.3", "playwright": "^1.22.2", "puppeteer": "^14.4.1", "vue": "^3.2.33", "vue-i18n": "^9.1.9", "vuex": "^4.0.2" }, "devDependencies": { "@dcloudio/types": "^2.6.4", "@dcloudio/uni-automator": "3.0.0-alpha-3041520220609002", "@dcloudio/uni-cli-shared": "3.0.0-alpha-3041520220609002", "@dcloudio/vite-plugin-uni": "3.0.0-alpha-3041520220609002", "cross-env": "^7.0.3", "postcss": "^8.4.14", "sass": "^1.52.3", "typescript": "^4.7.3", "vite": "^2.9.6" } }
m***@126.com (作者)
更新了jest版本后,npm run test:h5 成功,但是npm run test:ios 出现了新的出错信息
2022-06-28 23:24