Run “node test” as part of Visual Studio Team Services build task with results in “tests” tab

后端 未结 2 363
生来不讨喜
生来不讨喜 2021-02-03 14:54

I have a project that contains tests that I am running with Mocha from the command line. I have set up a test script in my packages.json, which looks as follows:

2条回答
  •  野的像风
    2021-02-03 15:24

    I've found a good way of doing it that requires no third-party adapter (eg. Chutzpah). It involves getting Mocha to output its report in an XML format, and setting up Visual Studio Team Services to publish the results in an extra step of the build definition.

    I installed mocha-junit-reporter (https://www.npmjs.com/package/mocha-junit-reporter) and altered my test script to the following:

    "test": "mocha ./temp/**/*.spec.js --reporter mocha-junit-reporter --require jsdom-global/register"

    I then created a new step in my build definition using the "Publish Test Results" task. I set the result format to "JUnit" and added the correct path for the outputted test-results.xml file created by the reporter.

    It is worth noting that although Mocha comes with an "XUnit" reporter, this format appears to not work correctly with VSTS even though it's listed as an option.

    The results of npm test now show up in the "tests" tab alongside any other tests from MSTest etc.

提交回复
热议问题