Jest 单元测试用例未从 Azure DevOps Pipeline 执行

问题描述 投票:0回答:1

在React项目中,它有前端单元测试用例。 从 VS Code 终端,当我使用

npm run test

运行这些命令时
>npm run test

> [email protected] test
> react-scripts test --env=jsdom

测试用例正在运行并产生结果。 这是package.json文件的一部分

 "devDependencies": {
        "@babel/core": "^7.21.0",
        "@babel/plugin-proposal-private-property-in-object": "^7.21.11",
        "@types/applicationinsights-js": "^1.0.9",
        "@types/history": "^4.7.8",
        "@types/node": "^15.0.3",
        "@types/react": "^17.0.5",
        "@types/react-dom": "^17.0.4",
        "@types/react-select": "^5.0.1",
        "eslint-plugin-biis": "^1.0.2",
        "fetch-mock": "^9.11.0",
        "postcss": "^8.4.21",
        "postcss-flexbugs-fixes": "^5.0.2",
        "postcss-loader": "^7.0.2",
        "postcss-normalize": "^10.0.1",
        "postcss-preset-env": "^8.0.1",
        "prettier": "^2.8.8",
        "prettier-plugin-jsdoc": "^0.3.38",
        "prettier-plugin-organize-imports": "^2.3.3",
        "react-scripts": "^5.0.1",
        "typescript": "^4.9.3"
    },
    "scripts": {
        "start": "react-scripts --openssl-legacy-provider start",
        "build": "react-scripts build",
        "test": "react-scripts test --env=jsdom",
        "eject": "react-scripts eject",
        "eslint": "eslint src/**/*.js",
        "legacy-install": "npm install --legacy-peer-deps",
        "clean-start": "rm -rf node_modules && npm run legacy-install && npm run start"        
    },

现在,我尝试从 Azure DevOps 管道执行单元测试用例。 为此,在构建管道中添加了 npm 命令来运行命令

npm run test
。 package.json 文件是由
$(WorkingDirectory)
定义的根目录。 这是设置:

当管道运行并到达任务“运行单元测试”时,它不会执行测试用例。 在调试日志中,它没有显示任何错误,但运行 60 分钟后管道超时。 这是管道日志的输出:

##[debug]arguments:
##[debug]   run
##[debug]   test
C:\Windows\system32\cmd.exe /D /S /C "C:\hostedtoolcache\windows\node\16.3.0\x64\npm.cmd run test"

这里缺少什么?

我用谷歌搜索了这个问题以找到解决方案,但没有运气。

reactjs unit-testing jestjs azure-pipelines
1个回答
0
投票

使用 NPM 任务版本 1 时,我可以重现相同的问题。它将卡在 npm run test 命令处,没有任何输出。

问题似乎来自 NPM 任务版本 1 本身。建议您可以在开发者社区

反馈问题

您可以参考以下方法解决此问题:

方法1:您可以更改为使用NPM任务版本0并设置npm run test命令。

例如:

方法2:您可以更改为使用CommandLine/PowerShell/Bash任务来运行npm run test命令:

例如:

在这种情况下,npm run test 命令可以按预期工作。

结果:

© www.soinside.com 2019 - 2024. All rights reserved.