15 unit-testing node.js npm mocha-phantomjs
我正在使用mocha-phantomjs设置进行单元测试.我有以下package.json scriot来运行测试.
"scripts": {
"test": "npm run testFlickr",
"testFlickr": "mocha-phantomjs ./test/FlickrTest.html"
}
Run Code Online (Sandbox Code Playgroud)
这在浏览器中运行正常.当我npm test
在cmd中运行命令时,测试运行正常,但它也会出现以下错误
3 passing (5s)
6 failing
npm ERR! flickr-test@ testFlickr: `mocha-phantomjs ./test/FlickrTest.html`
npm ERR! Exit status 6
npm ERR!
npm ERR! Failed at the flickr-test@ testFlickr script.
npm ERR! This is most likely a problem with the flickr-test package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! mocha-phantomjs ./test/FlickrTest.html
npm ERR! You can get their info via:
npm ERR! npm owner ls flickr-test
npm ERR! There is likely additional logging output above.
npm ERR! System Windows_NT 6.1.7600
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nod
ejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "testFlickr"
npm ERR! cwd C:\Users\user\Desktop\test
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! C:\Users\user\Desktop\test\npm-debug.log
npm ERR! not ok code 0
npm ERR! Test failed. See above for more details.
npm ERR! not ok code 0
Run Code Online (Sandbox Code Playgroud)
请任何人都可以告诉我如何解决此错误.
Sgn*_*gnl 12
在运行npm test
它时会压制ELIFECYCLE
错误,因此您永远不会遇到这种体验.
将测试脚本移动到其他脚本名称后,您将开始看到ELIFECYCLE
错误.
我的修复是exit 0
在命令的末尾添加一个.对于您的代码,它看起来像这样:
"scripts": {
"test": "npm run testFlickr",
"testFlickr": "mocha-phantomjs ./test/FlickrTest.html; exit 0"
}
Run Code Online (Sandbox Code Playgroud)
Jar*_*red 11
我遇到了同样的问题,为我修复的是当我运行单元测试时,不要使用
npm run test
Run Code Online (Sandbox Code Playgroud)
改为使用:
npm test
Run Code Online (Sandbox Code Playgroud)
小智 6
这是使用时的一个问题npm run
,它与 Mocha 在测试失败时以代码 !== 0 退出有关。如果您使用的是 Windows,请尝试以下操作:
"scripts": {
"test": "npm run testFlickr || ECHO.",
"testFlickr": "mocha-phantomjs ./test/FlickrTest.html || ECHO."
}
Run Code Online (Sandbox Code Playgroud)
当我在 cmd 中运行命令 npm test 时,测试运行正常
不,他们不是。您有 6 个失败的测试。的退出代码mocha-phantomjs
等于失败测试的数量。mocha-phantomjs ./test/FlickrTest.html
直接运行,看看是什么失败了。意识到 PhantomJS 与您的浏览器有点不同——您可能需要调试它。
你的脚本设置很奇怪。你应该有:
"scripts": {
"test": "mocha-phantomjs ./test/FlickrTest.html"
}
Run Code Online (Sandbox Code Playgroud)
然后奇数节点错误应该消失。
归档时间: |
|
查看次数: |
16953 次 |
最近记录: |