I have a shell script that recursively searches for package.json from a base directory and runs npm test like so.
find "$parent_dir" -name package.json -maxdepth 2 -execdir npm test \;
I want to intercept tests failure in the form of:
npm ERR! Test failed. See above for more details.
npm ERR! not ok code 0
So I can have the shell script exit with an error status.
Any help is appreciated.
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.
To solve the npm ERR! Missing script: "start" error, make sure to add a start command to the scripts object in your package. json file and open your shell or IDE in the root directory of your project before running the npm start command.
Another 3 year late and was looking for solution in this too.
Finally found it and if these help others in future. I used shell script $? command, which returns the exit status of the last executed command. I.e. if a shell script fails it returns 1 while a 0 if it's success. NPM implements this return hence.
npm run test
if [ $? -eq 0 ]
then
echo "SUCCESS"
else
echo "FAIL"
fi
If I understood you correctly you want to execute something or stop execution of script if npm ERR! has been thrown? This might help:
if ./somecommand | grep -q 'npm ERR!'; then
#what you want to do
# exit executing the script
return
fi
Sorry what I am two years late, just joined the SO community.
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