Instead of attempting to replicate the Specrunner using Chutzpah on the build server, which I found challenging to set up and use. My goal was to have karma generate test results in the 'trx' format recognized by TFS and then deploy them to the build. Please note that I am utilizing PhantomJs to execute my tests through Karma, but I will not delve into that here as it has been extensively covered elsewhere.
1) Incorporate the karma-trx-reporter plugin from npm into your web project (or a similar plugin).
2) Adjust the Karma.config file to include the trx reporter:
reporters: ['dots', 'trx'],
trxReporter: { outputFile: 'test-results.trx' },
// inform karma of the available plugins
plugins: [
'karma-jasmine',
'karma-phantomjs-launcher',
'karma-trx-reporter',
],
3) Develop a Gulp (or grunt) task for executing the karma tests if one does not already exist. Run this task locally and verify that it produces the 'test-results.trx' file specified earlier (the location where the file is created on the build server is irrelevant):
gulp.task('test', function () {
return gulp.src(['tests/*.js']).pipe(karma({
configFile: __dirname + '/Testing/karma.config.js',
singleRun: true
}));
});
4) Integrate a Gulp (or Grunt) TFS build task to run the karma tests generated in the previous step and output the trx file.
https://i.sstatic.net/0UNAl.png
5) Include a Gulp (or Grunt) TFS build task for Publishing the test results and merging them into the build. Note that the "Test Result Files" path uses a wild card **/*.trx to locate any trx files within the build path (e.g., finding our previously generated file). "Merge Test results" should be selected to combine both our Jasmine test execution and our c# test execution into one session. Ensure that "Continue on error" is unchecked to halt the build process if there are any jasmine test failures.
https://i.sstatic.net/I26cx.png
You will observe two groups of tests that were conducted and incorporated into the build!
https://i.sstatic.net/zk7HX.png