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

后端 未结 2 356
生来不讨喜
生来不讨喜 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:20

    I'm using karma and got this to work in the same way as @dylan-parry suggested. Some excepts below in case it helps others:

    package.json

      "scripts": {
        "test": "cross-env NODE_ENV=test karma start"
      }
    

    karma.conf.js

    const webpackCfg = require('./webpack.config')('test');
    
    module.exports = function karmaConfig(config) {
    
      config.set({
        reporters: ['mocha', 'coverage', 'junit'],
        junitReporter: {
          outputDir: 'coverage',
          outputFile: 'junit-result.xml',
          useBrowserName: false
        }
      })
    ...
    

    TFS

    It may also be worth adding I'm using branch policies on my git branch to prevent PR's being merged if the tests fail, info via this link:

    https://www.visualstudio.com/en-us/docs/git/branch-policies

    Here's the output in TFS:

    Next step is to get the coverage working too!

提交回复
热议问题