【问题标题】:Running Mocha on windows for jsx test在 Windows 上运行 Mocha 进行 jsx 测试
【发布时间】:2015-11-25 20:03:52
【问题描述】:

我正在尝试阅读有关 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"

},

【问题讨论】:

    标签: node.js reactjs mocha.js


    【解决方案1】:

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

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

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

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

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

    【讨论】:

    • 我喜欢这个想法,但我不喜欢安装另一个 shell 只是为了让测试正常工作。我可能应该看看在这种情况下通配符是如何工作的。
    【解决方案2】:

    感谢 skrillcosby 指出命令中失败的特定部分。我能够在不安装其他软件的情况下更正该问题。

    问题当然是测试命令的最后一部分

    'test/**/*.@(js|jsx)'
    

    这有两个问题是 |符号和@ 符号。用以下内容替换此文本可解决问题。

    test/**/*.js*
    

    是的,也去掉引号。

    另外,在发现修复后,我搜索了我正在工作的教程,发现其他人在 2 个月前提到了修复。 http://teropa.info/blog/2015/09/10/full-stack-redux-tutorial.html#comment-2264530944

    【讨论】:

      猜你喜欢
      • 2018-01-11
      • 1970-01-01
      • 1970-01-01
      • 2020-08-26
      • 1970-01-01
      • 2016-06-28
      • 2023-04-05
      • 2015-12-27
      • 1970-01-01
      相关资源
      最近更新 更多