I can't for the life of me find documentation or a tutorial for kicking off mocha unit tests in Visual Studio Online builds.
I have node.js app that is building in VSO and being deployed to Azure. That all works wonderfully. I can't seem to figure out how to kick off the spec files through the build process.
How is this done? Is there documentation available somewhere that I'm missing.
Assume you have setup Mocha tests with your package.json
, i.e. you run tests with npm test
. For more information, refer to https://docs.npmjs.com/cli/test.
In your Visual Studio Online build/release:
install mocha-junit-reporter
test -- --reporter mocha-junit-reporter
--timeout 30000
because the build agent maybe running slower than your dev boxQueue a build, you should see Mocha test results in your VSO build.
BONUS! You can also add code coverage to your Mocha run with nyc (formerly known as Istanbul)
On top of the steps above:
package.json
npm install nyc--save-dev
package.json
{ "scripts": { "test": "nyc --repoter=cobertura mocha" } }
test -- --reporter mocha-junit-reporter
$(System.DefaultWorkingDirectory)/coverage/cobertura-coverage.xml
$(System.DefaultWorkingDirectory)/coverage/
NPM_CONFIG_COVERAGE
and set it to true
Now you got both unit tests and code coverage results in your build report.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With