将JavaScripts单元测试代码覆盖率集成到MSBuild中 [英] Integrating javascripts unit tests code coverage in MSBuild
问题描述
我使用Jasmine和Karma编写单元测试和代码覆盖。我已经使用Gulp创建了这些任务,并通过VS 2015更新3中的任务运行器资源管理器运行它们。
var gulp = require(gulp); var Server = require('karma')。Server; var remapIstanbul = require('remap-istanbul / lib / gulpRemapIstanbul'); gulp.task('unit-测试',功能(完成){新服务器({configFile:__dirname +'/karma.conf.js',完成).start();}); gulp.task('code-coverage',function(){返回gulp.src('_ reports / coverage-javascript.json').pipe(remapIstanbul({reports:{'json':'_reports / coverage-typecript.json','html':'_reports / html-report'} }));});
html结果文件,即来自 _r eated / html-report / index.html 文件在Gated Builds或Nightly构建中。如果代码覆盖率低于80%或测试失败,我希望使用此代码覆盖范围来执行某些操作,例如停止构建。
我该怎么做?
我已经实现了一个解决方案,当任何单元测试失败时,它将失败MSBuild。基本上,我在我的project.csproj文件中编写了一个自定义目标,该文件在'CompileTypeScript'目标之后运行。
$ b
< PropertyGroup> < CompileDependsOn> $(CompileDependsOn); GulpBuild; < / CompileDependsOn>< / PropertyGroup>< Target Name =GulpBuildDependsOnTargets =CompileTypeScript> < Exec Command =./ node_modules / .bin / gulp task-name/>< / Target>
p>
在Visual Studio将TS编译成JS之后,将执行此任务。在构建服务器中,'Path'变量未设置为'gulp',这就是为什么通过node_modules .bin文件夹传递命令的原因。
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?
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.
这篇关于将JavaScripts单元测试代码覆盖率集成到MSBuild中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!