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.
The npm test command is used to test a package. This command runs the test script that is contained in a package, if you provided one.
TL;DR there is no difference. It's just a shortcut for npm tests which run the test command in the package. json file. npm run test performs the same action in this case.
In order to run a specific test, you'll need to use the jest command. npm test will not work. To access jest directly on the command line, install it via npm i -g jest-cli or yarn global add jest-cli . Then simply run your specific test with jest bar.
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"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With