Catch npm ERR! when running npm test from shell script

I have a shell script that recursively searches for package.json from the base directory and runs an npm test as follows.

find "$parent_dir" -name package.json -maxdepth 2 -execdir npm test \;

I want to catch the failures of tests in the form:

npm ERR! Test failed.  See above for more details.
npm ERR! not ok code 0

That way I can get a shell script with an error condition.

Any help is appreciated.

+4
source share

All Articles