Integrating javascripts unit tests code coverage in MSBuild

青春壹個敷衍的年華 提交于 2019-12-25 04:22:23

问题


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, i.e. 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?


回答1:


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.



来源:https://stackoverflow.com/questions/38851178/integrating-javascripts-unit-tests-code-coverage-in-msbuild

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!