Is there a way to trigger npm's posttest when test fails? If package.json contains
"scripts": {
"pretest": "echo pretest",
"test": "some_failed_test_or_error",
"posttest": "echo posttest"
}
$ npm test
will echo "pretest" but not "posttest".
I get the same behavior if I use mocha and a test fails, even if mocha doesn't trigger any exceptions (just some simple failure assert(true==false)
).
I'm launching a resource on pretest, and I'd like to kill the resource on posttest, whether the test itself passes or fails.
MacOS OS X 10.9.4, npm version 1.4.21, node v0.10.30.
Worked it out. Not sure if the following will work in Windows. The bash ||
operator followed by an empty comment :
changes the exit code.
For instance, using mocha:
"scripts": {
"pretest": "echo pretest",
"test": "mocha || :",
"posttest": "echo posttest"
}