Catch npm ERR! when running npm test from shell script
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 testif [ $? -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.