How to run Typescript tests for Jasmine \ Karma through the TFS build process

I have a web application using Angular 1.5 with bower / npm / gulp encoded in Typescript to make our build. Our back end is C # .net WebApi2. Both are built and deployed on TFS2015. My C # nUnit tests integrate easily as part of the build process. However, Typescript jasmine test cases are harder to integrate. How can I get jasmine Typescript module tests to run as part of a TFS build, and if they fail, the build failed? We run them through the Jasmine Spec runner as well as Karma, but are not integrated.

I read a lot of StackOverflow posts integrating Javascript unit tests, and each prospect took me through an overly complicated solution that didn't work. These include scripts by Powershell, Chutzpah amoungst others.

+6
source share
1 answer

Instead of trying to recreate Specrunner via Chutzpah on a build server, which is hard for me to configure and work. The goal was to get karma to output current tests in the trx test format that TFS recognizes and then publish to the assembly. Please note that I use PhantomJs to run my tests through Karma, but I will not describe it here, since it is well lit elsewhere.

1) install the karma-trx-reporter plugin via npm in your web project (or a similar plugin)

2) Configure Karma.config to enable trx reporter

reporters: ['dots', 'trx'], trxReporter: { outputFile: 'test-results.trx' }, // notify karma of the available plugins plugins: [ 'karma-jasmine', 'karma-phantomjs-launcher', 'karma-trx-reporter', ], 

3) Create a Gulp (or grunt) task to run karma tests if you don’t already have it. Run the task locally and make sure that it creates the test-results.trx above. (It doesn't matter where the file is created on the build server):

 gulp.task('test', function () { return gulp.src(['tests/*.js']).pipe(karma({ configFile: __dirname + '/Testing/karma.config.js', singleRun: true })); }); 

4) Add the GFS (or Grunt) TFS build task to run the karma tests created in the previous step and output the trx file. enter image description here

5) Add the GFS (or Grunt) TFS build task to publish the test results and merge them into a build. Note that the "Test Result Files" path is a wild card ** / *. Trx to find any trx files in the build path (i.e., find our previously created file). The "Results Merge Results" is checked to merge both Jasmine test runs and our C # test in the same session. "Continue on error" is not brushed aside to ensure that any failures of the jasmine test will break the assembly.

enter image description here

You will see two sets of tests that were run and included as part of the assembly!

enter image description here

+7
source

All Articles