Kick off mocha tests in Visual Studio Team Services Build
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
, ie 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 box Queue a build, you should see Mocha test results in your VSO build.
BONUS! You can also add code coverage to your Mocha run with Istanbul.
On top of the steps above:
package.json
npm install istanbul --save-dev
package.json
{ "scripts": { "test": "istanbul test node_modules/mocha/bin/_mocha" } }
test -- --report cobertura --report html -- --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've configured you package.json to be able to run tests, adding a npm step that executes npm run test
should do it. If you want to publish the test results you need to make sure that Mocha is writing its results to a format understood by Visual Studio Team Services. JUnit format would be a safe bet. Then follow up with a Publish test Results step that uploads the test results.
You can also use the Visual Studio Test Runner, combined with Chutzpah to run your tests, but I suppose that's going to be a lot of additional work to setup and isn't going to add much.
After quite a bit of fiddling around i got it to work by adding a "Command line task" to my build definition, i used the following parameters:
node
$(Build.SourcesDirectory)node_modulesjasmine-nodebinjasmine-node --verbose test
My tests are under a "test" folder, also make sure you have jasmine-node as a dev dependency
链接地址: http://www.djcxy.com/p/27010.html