Npm posttest does not start if npm check fails

Is there a way to run npm posttest when the test failed? If package.json contains

"scripts": { "pretest": "echo pretest", "test": "some_failed_test_or_error", "posttest": "echo posttest" } 

$ npm test will echo the "prefix", but not the "posttest".

I get the same behavior if I use mocha and the test fails even if mocha does not raise any exceptions (just a simple assert(true==false) failure assert(true==false) ).

I run the resource on pre-testing, and I would like to kill the resource in posttest, regardless of whether the test passes or fails.

MacOS OS X 10.9.4, npm version 1.4.21, node v0.10.30.

+5
source share
1 answer

Designed it. Not sure if the following will work on Windows. The bash operator || followed by an empty comment : changes the exit code.

For example, using mocha:

 "scripts": { "pretest": "echo pretest", "test": "mocha || :", "posttest": "echo posttest" } 
+9
source

Source: https://habr.com/ru/post/1200250/


All Articles