在windows上运行摩卡以获得jsxtesting

我正在尝试通过一个关于react / redux的教程,而且在运行摩卡unit testing时遇到了一个错误。

当我运行'npm运行testing'我得到以下错误(我怀疑必须与path或.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样式的globbing,但是我find了一个修复/解决方法。

1)使用BASH shell(即,Git Bash,CMDer或cygwin)
2)用双引号replace单引号

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

这应该对所有* .js和* .jsx文件运行testing。 在Git Bash,CMDer和cygwin中进行testing。

所以感谢skrillcosby指出在命令中失败的具体部分。 我能够解决这个问题,而无需安装其他软件。

这个问题当然是testing命令的最后一部分

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

与此有关的两个问题是| 符号和@符号。 用以下内容replace本文可以解决问题。

 test/**/*.js* 

是的,也删除报价。

另外,在发现修复程序后,我在我正在使用的教程上进行了一次search,发现有人在2个月前提到了修复程序。 http://teropa.info/blog/2015/09/10/full-stack-redux-tutorial.html#comment-2264530944