我有几个节点包可以在node.js环境中运行,也可以在浏览器中运行.现在我有两个单独的测试(针对每个环境).使用npm test
命令运行这些测试的最佳方法是什么?另外我想将这些包添加到travis.
我正在使用mocha
和mocha-phantomjs
.
节点测试命令
node ./node_modules/mocha/bin/mocha ./test/node/index.js --reporter spec
浏览器测试命令
node ./node_modules/mocha-phantomjs/bin/mocha-phantomjs ./test/browser/index.html
我尝试了什么:
将这些命令添加到npm test
以分号分隔的脚本中
问题:当第一个脚本中出现错误但第二个脚本中没有错误时,命令退出0并传递travis构建.
让node命令在npm test
脚本中测试并为浏览器测试创建自定义脚本.然后将这两个命令(npm test
和npm run-script test-browser
)添加到travis.yml作为数组.
问题:用户必须手动运行两个独立的测试脚本.
让node命令在npm test
脚本中测试并将浏览器测试添加到npm posttest
命令.Travis.yml将只有一个脚本,用户也必须运行一个脚本(每个人都很高兴).
问题:感觉不对,所以我想知道是否有更好的方法.
Dan Kohn.. 77
我喜欢以下内容:
"scripts": { "test": "npm run test-node && npm run test-browser", "test-node": "mocha -R spec ./test/node/index.js", "test-browser": "mocha-phantomjs ./test/browser/index.html"}
在&&
只运行第二,如果第一关,你可以,如果你想要么单独运行.请注意,npm总是使用相对的mocha(在node_modules内),而不是全局的mocha,所以直接调用mocha
并没有任何危害mocha-phantomjs
.使用mocha的-b
保释选项可以提高效率,保释会在遇到错误时立即退出.
我喜欢以下内容:
"scripts": { "test": "npm run test-node && npm run test-browser", "test-node": "mocha -R spec ./test/node/index.js", "test-browser": "mocha-phantomjs ./test/browser/index.html"}
在&&
只运行第二,如果第一关,你可以,如果你想要么单独运行.请注意,npm总是使用相对的mocha(在node_modules内),而不是全局的mocha,所以直接调用mocha
并没有任何危害mocha-phantomjs
.使用mocha的-b
保释选项可以提高效率,保释会在遇到错误时立即退出.