gpt4 book ai didi

node.js - 在 Windows 上运行 Mocha 进行 jsx 测试

转载 作者:太空宇宙 更新时间:2023-11-03 21:58:33 25 4
gpt4 key购买 nike

我正在尝试阅读有关 React/Redux 的教程,但在使用 mocha 运行单元测试时遇到了错误。

当我运行“npm run test”时,出现以下错误(我怀疑这与路径或 .jsx 扩展名有关)。

17 error Windows_NT 6.3.9600
18 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\xenoputtss\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "test"
19 error node v5.1.0
20 error npm v3.4.1
21 error code ELIFECYCLE
22 error voting-client@1.0.0 test: `mocha --compilers js:babel-core/register --require ./test/test_helper.js 'test/**/*.@(js|jsx)'`
22 error Exit status 255
23 error Failed at the voting-client@1.0.0 test script 'mocha --compilers js:babel-core/register --require ./test/test_helper.js 'test/**/*.@(js|jsx)''.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the voting-client package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error mocha --compilers js:babel-core/register --require ./test/test_helper.js 'test/**/*.@(js|jsx)'
23 error You can get their info via:
23 error npm owner ls voting-client
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]

我的 package.json 的脚本设置如下。

"scripts": {
"test": "mocha --compilers js:babel-core/register --require ./test/test_helper.js 'test/**/*.@(js|jsx)'",
"test:watch": "npm run test -- --watch"

},

最佳答案

哈哈 - 我正在研究相同的教程并遇到了相同的问题。

所以 Windows 不支持像这样的 UNIX 风格的通配符,但我确实找到了修复/解决方法。

1) 使用 BASH shell(即 Git Bash、CMDer 或 cygwin)
2)用双引号替换 glob 周围的单引号

"test": "mocha --compilers js:babel-core/register --require ./test/test_helper.js \"test/**/*.@(js|jsx)\""

这应该对所有 *.js 和 *.jsx 文件运行测试。在 Git Bash、CMDer 和 cygwin 中进行了测试。

关于node.js - 在 Windows 上运行 Mocha 进行 jsx 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33925466/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com