作者热门文章
- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我有几个 Node 包可以在 node.js 环境和浏览器中工作。现在我有两个单独的测试(针对每个环境)。仅使用 npm test
命令运行这些测试的最佳方法是什么?我也想将这些包添加到 travis 中。
我正在使用 mocha
和 mocha-phantomjs
。
Node 测试命令
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
脚本中,用分号分隔
npm test
脚本中进行测试,并为浏览器测试创建自定义脚本。然后将这两个命令(npm test
和 npm run-script test-browser
)作为数组添加到 travis.yml 中。
npm test
脚本中进行测试,并将浏览器测试添加到 npm posttest
命令中。 Travis.yml 将只有一个脚本,用户还必须运行一个脚本(每个人都很高兴)。
最佳答案
我喜欢以下内容:
"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 总是使用 relative mocha (在 node_modules 中),而不是全局的,所以直接调用 mocha
和 mocha-phantomjs
并没有什么坏处。使用 mocha 的 -b
选项可以提高效率,一旦遇到错误就会退出。
关于node.js - 如何从 node.js 中的一个 "npm test"命令运行 mocha 和 mocha-phantomjs 测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20376269/
我是一名优秀的程序员,十分优秀!