How to run mocha and mocha-phantomjs tests from one “npm test” command in node.js?

I like the following:

  "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"}

The && only runs the second if the first passes, and you can run either separately if you want. Note that npm always uses the relative mocha (inside node_modules), not the global one, so there’s no harm in just calling mocha and mocha-phantomjs directly. You can be even more efficient with mocha’s -b option for bail, which will quit as soon as it encounters an error.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)