Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NPM - how to publish only if tests pass?

I have tests setup for a package I maintain - create-new-app. When I run npm publish, I want the tests to run first and only if they pass, move on to the publish portion. I thought this is what prepublishOnly was for. My prepublishOnly value looks like this:

prepublishOnly: "npm run test"

That successfully runs the tests prior to publishing, but if the tests fail, it still publishes! How can I get the publish to happen only when tests pass?

like image 574
The Qodesmith Avatar asked Sep 20 '25 22:09

The Qodesmith


1 Answers

it's possible that your npm run test command is not returning a proper error code of non-zero

like image 58
rob2d Avatar answered Sep 23 '25 11:09

rob2d