我有几个在node中工作的node包.js环境和浏览器.现在我有两个独立的测试(针对每个环境).使用npm test个命令运行这些测试的最佳方式是什么?我还想把这些软件包添加到travis中.

我用mochamocha-phantomjs.

Node test command

node ./node_modules/mocha/bin/mocha ./test/node/index.js --reporter spec

Browser test command

node ./node_modules/mocha-phantomjs/bin/mocha-phantomjs ./test/browser/index.html

What I tried:

  1. Add these commands into npm test script seperated with semicolon
    • Problem:当第一个脚本中有错误,但第二个脚本中没有错误时,命令退出并传递0和travis build.
  2. Let node command test in npm test script and create custom script for browser tests. Than add these two commands (npm test and npm run-script test-browser) into travis.yml as array.
    • Problem:个用户必须手动运行两个独立的测试脚本.
  3. Let node command test in npm test script and add browser tests to npm posttest command. Travis.yml will than have got just one script and users will also have to run one script (everyone is happy).
    • 感觉不太对劲,所以我想知道是否有更好的方法.

推荐答案

我喜欢以下几点:

  "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 _模块内部),而不是全局的,所以直接调用mochamocha-phantomjs没有什么害处.摩卡的-b保释选项会让你的效率更高,一旦出现错误,它就会退出.

Node.js相关问答推荐

node 无法验证第一个证书

Mongoose查询-如何根据当前查找ID获取其他集合并将其插入到当前查找中?

Node.js中Redis的并发问题

Sass-TypeError:无法读取未定义的属性(正在读取';indexOf';)

Puppeteer 的 BrowserFetcher 发生了什么?

找不到 vue-template-compiler@2.6.14 的匹配版本 | Shopware 6.5 更新后的 node 问题

为什么 docker 容器内的应用程序无法访问它自己的 API 端点?

如何修复node.js中的错误代码无法加载资源:服务器响应状态为403(禁止)

我如何保护nodejs中的路由

express 和 mongoose 的新密码不正确

无法关闭 node.js 中的mongoose 连接

Socket IOFlutter 未连接

制作一个接受命令行参数的脚本

使用 Node.js 在内存中缓冲整个文件

为当前目录提供服务的简单文件服务器

AngularJS +sails.js

MongoDB Node findone如何处理没有结果?

对不同对象中的函数使用相同的键时,V8 中的函数调用缓慢

node.js 模块和函数中this的含义

为什么 Node.js 没有原生 DOM?