Search code examples
testingnpmpublishpackage.jsonpackage-management

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?


Solution

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