Setting up a task in package.json

Bubble Trouble

I am trying to setup a task in package.json

"scripts": {
    "unit-test": "mocha './test/unit/**/*.spec.js'",
 }

However when I run

npm run unit-test

the following errors are thrown in the console at the end of the run:

npm ERR! Darwin 16.6.0
npm ERR! argv "/Users/shreya.vakil/.nvm/v6.9.5/bin/node" "/Users/d.bubble/.nvm/v6.9.5/bin/npm" "run" "unit-test"
npm ERR! node v6.9.5
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! [email protected] unit-test: `mocha './test/unit/**/*.spec.js'`
npm ERR! Exit status 1

However, if I change the command to

"scripts" : {
 "unit-test": "mocha './test/unit/**/*.spec.js'; exit 0",
}

this error is not thrown. However, I am not sure if this is the right approach.

Joe Clay

The original behavior is correct, if a little ugly - if your tests fail, Mocha returns an exit code of 1, which is technically an error. Your second example makes the output prettier, but it'll cause you issues if you try to integrate your build scripts into other tools (for example, Travis), as they won't be able to detect when your tests fail.

The best solution to this would be to get rid of the exit 0 and upgrade your version of NPM - the output was made much shorter in v4.6.1. You can do this by running the following command:

npm install npm -g

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Setting up process.env variable from package json script

From Dev

Setting up ROS package in CLion

From Dev

Setting up a task schedule with batch code

From Dev

Setting up Integration tests in a laravel package

From Dev

Setting up apt package manager in Yocto image

From Dev

Setting package.json defaults

From Dev

Setting up a rake task with Resque Scheduler - Rails 4

From Dev

Setting up URL base for JSON with expressjs

From Dev

Setting up header and getting JSON using $http

From Dev

Setting up URL base for JSON with expressjs

From Dev

Setting environment variables in package.json scripts under Windows

From Dev

create-react-app proxy setting in package.json not working

From Dev

Setting up gradle org.sonarqube plugin sonar analysis task (sonarqube) in jenkins

From Dev

Extract value of verison defined in package.json in bamboo task

From Dev

Meteor not starting due to Meteorite package (setting up an older Meteor version with Meteorite packages)

From Dev

Task not setting variables properly?

From Dev

Setting a wallpaper in background task

From Dev

Sublime package LANG setting

From Dev

Setting package in Scala REPL

From Dev

Setting up Azure CDN

From Dev

Setting up Sessions?

From Dev

Setting up CIFilter in Swift

From Dev

Setting up the network for Kubernetes

From Dev

Setting up MongoDB + Django

From Dev

Setting Up Docker Dnsmasq

From Dev

Setting up UIScrollview and autolayout

From Dev

Setting Up Environments with SaltStack

From Dev

Setting up ACL on a VPS?

From Java

Setting up buttons in SKScene