简体   繁体   中英

Integrating javascripts unit tests code coverage in MSBuild

I am using Jasmine and Karma for writing unit tests and code coverage. I have created the tasks using Gulp and running them through task runner explorer in VS 2015 update 3.

 var gulp = require("gulp"); var Server = require('karma').Server; var remapIstanbul = require('remap-istanbul/lib/gulpRemapIstanbul'); gulp.task('unit-tests', function (done) { new Server({ configFile: __dirname + '/karma.conf.js' }, done).start(); }); gulp.task('code-coverage', function () { return gulp.src('_reports/coverage-javascript.json') .pipe(remapIstanbul({ reports: { 'json': '_reports/coverage-typescript.json', 'html': '_reports/html-report' } })); }); 

I want to read the generated html results file, ie from _reports/html-report/index.html file during Gated Builds or Nightly builds. I want to use this code coverage to perform certain actions like stopping the build if code coverage is below 80% or when a test failed.

How can I do that?

I have implemented one solution which fails MSBuild whenever any Unit Test failed. Basically I wrote a Custom Target in my project.csproj file which runs after 'CompileTypeScript' target.

 <PropertyGroup> <CompileDependsOn> $(CompileDependsOn); GulpBuild; </CompileDependsOn> </PropertyGroup> <Target Name="GulpBuild" DependsOnTargets="CompileTypeScript"> <Exec Command="./node_modules/.bin/gulp task-name" /> </Target> 

This task will run after Visual studio compiles TS to JS. In build server 'Path' variable is not set for 'gulp', that's why passing the command through node_modules .bin folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM