Reputation: 1339
I am trying to build a JS application with unit tests.
So when i give npm run build
build should be successful only if all the Jest tests have passed.
I have two npm scripts now.
One for testing and one for building production build
"scripts": {
"build": "sudo webpack --mode=production",
"test": "jest"
}
Upvotes: 0
Views: 1450
Reputation: 1339
A simple solution which will work with all environments including windows is appending both the scripts with && operator.
So the created new script will be like build:test below
"scripts": {
"build:test": "npm run test && npm run build ",
"build": "sudo webpack --mode=production",
"test": "jest",
}
&&
operator will see to that npm run build
will be executed only if npm run test
exits with successful return code and jest takes care of returning error code to terminal when any tests fail.
Upvotes: 1