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:

  • Add a "npm" task to install JUnit reporter
  • Run custom command install mocha-junit-reporter
  • Add a "npm" task
  • Run custom command test -- --reporter mocha-junit-reporter
  • Tips: You may want to increase timeout by adding --timeout 30000 because the build agent maybe running slower than your dev box
  • Then, add a "Publish Test Results" task
  • Set "Test result format" to "JUnit"
  • Check the box on "Continue on error"
  • Under "Control Options" > "Run this task", set it to "Even if a previous task has failed, unless the build was canceled"
  • 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:

  • Install Istanbul locally to your package.json
  • Run npm install istanbul --save-dev
  • Modify your scripts in package.json
  • Update { "scripts": { "test": "istanbul test node_modules/mocha/bin/_mocha" } }
  • Modify the "npm test" task
  • Run custom command test -- --report cobertura --report html -- --reporter mocha-junit-reporter
  • Add a "Publish Code Coverage Results" task
  • Set "Code Coverage Tool" to "Cobertura"
  • Set "Summary File" to $(System.DefaultWorkingDirectory)/coverage/cobertura-coverage.xml
  • Set "Report Directory" to $(System.DefaultWorkingDirectory)/coverage/
  • Check the box on "Continue on error"
  • Under "Control Options" > "Run this task", set it to "Even if a previous task has failed, unless the build was canceled"
  • Add a new build variable 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:

  • Set Tool to node
  • Set Arguments to $(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

    上一篇: Aspectj:lambda表达式的切入点

    下一篇: 在Visual Studio Team Services Build中启动摩卡测试