NPM - how to publish only if tests pass? - testing

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?

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

Related

TeamCity npm update command not run every other time

Having a weird issue in TeamCity npm steps where we update our internal npm packages. When the build is run it does not run the npm update command even though the log says it executes the command. But running the exact same build again triggers the command correctly (image 2).
Tried having the update command together with the following npm install and build commands in a single step and also as in the example images having them in separate steps but all scenarios give the same result; the update commands don't run every other time but all other npm commands runs correctly and trigger the build again makes the update commands execute. Why?!?!

Bamboo Continuous integration with yarn test (JEST framework)

I am very new to Atlassian Bamboo build CI. I want some help from you guys.
My Job is to make a continuous integration build plan for my reactjs application. So I started with Bamboo.
Now my application test cases are written in JEST framework.
In my (local machine) react application when I test the test cases locally I use the following command
"yarn test"
I installed yarn inside Bamboo by "npm install yarn"
My requirement is whenever I will merge my code in GitHub an automatic build will be triggered in Bamboo and if the test cases are passed then it will deploy the code..Now the build plan is getting triggered when ever I merge the code it GitHub (Because in step 1 of the build plan I made a job to checkout code from my GitHub repo)
But I am not understanding how to tell the build plan to run "yarn test" my test cases using JEST framework.
The question might look very easy for you guys...so please help me..
The agent (local or remote) running your builds needs:
Nodejs installed
npm installed - typically by the nodejs install
yarn installed globally (npm i -g yarn)
Then you can use as a script task to run the yarn test command.
You can build on this be seeing if there are plugins that abstract the script task into some sort of yarn task and you can look at processing the test results in Bamboo so that the builds show the test results and fail/pass the build accorindly.

Couldn't find a debug log in the cache or working directory

I want to create a VSTS build with npm package auditing capabilities using npm audit. I added a few tasks to run npm audit. The command runs and I can see the details in the console/logs for all the packages. However, the task fails complaining about not finding a logs file. Any idea on how I can get the builds to stop working if I find a high vulnerability package?
EDIT
This is the final line in the result when I run npm audit locally
Notice how it displays vulnerabilities in categories. I want the build to not proceed if there is a non-zero value for High vulnerability.
I got the same error, but then realize that I am using incorrect custom command for npm task:
it was "npm install gulp -g", but should be "install gulp -g" (without npm).
For me it helps.
There isn’t the way to stop/fail build directly if there is a non-zero value for High vulnerability.
The workaround is that you can do it through PowerShell with Build log REST api to analysis whether there is related information in the log, then fail the build (Write-error …) (Run the powershell through PowerShell task)

Fail TeamCity build when angular-cli reports errors

I'm trying to configure team city to run angular 5 application build.
I have powershell step with this script (it's in the build step definition not separate file). npm run build runs ng build
npm install
npm run build
For some reason even if ng build fails team city build won't fail. Status code from npm run is not propagated back to powershell.
See below screen:
TeamCity Fails the build if got a status code != 0 or when got stderr.
You should add Failure Conditions for verifying that the log has an error.
Edit Configuration Settings -> Failure Conditions -> Add failure condition
Select Fail build on specific text in build log
Secelt options Contains and exact text. Set "npm ERR"
in Failure message write "Error was found in build log"
save
Now your build will be FAILED if build log contains this text.
Also, check an error message is logged by build runner

npm messes up glob path expansion when running scripts

When running npm test, which is defined by:
"test": "mocha test/**/*.spec.js"
The path expansion fails to match scripts at a depth of more than one. Therefore everything in test/lib/*.spec.js gets matched, but a test at test/lib/subdir/*.spec.js does not.
When I run mocha test/**/*.spec.js, however, all the tests are matched and run. I'm at something of a loss as to how to debug this.
EDIT
I'm pretty sure this is due to npm running scripts in sh instead of my shell (zsh). I don't know how to fix this.