在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):dylanb/gulp-coverage开源软件地址(OpenSource Url):https://github.com/dylanb/gulp-coverage开源编程语言(OpenSource Language):JavaScript 80.3%开源软件介绍(OpenSource Introduction):gulp-coverageGulp coverage reporting for Node.js that is independent of the test runner Reportgulp-coverage generates block, line, chainable and statement coverage for Node.js JavaScript files. This is equivalent to function, statement, branch and "modified condition/decision" coverage, where a "statement" is equivalent to a "modified condition/decision". The HTML report gives summary information for the block, line and statement covereage across all the files as well as for each file. ChainablesThe chainable coverage supports Array-like chainables and will record misses where the chained member calls both receive and result-in an empty array. HTML reportFor each covered file, a chain of links is built allowing you to click through from the summary to the first and then all subsequent instances of each type of miss (line misses and statement misses). The HTML report format has been desiged to be accessible and conformant with WCAG 2 Level AA. Excluding code from coverage reportingTo exclude a single line from the coverage report, you can append a comment with the content of "cover:false" to the end of the line.
If you would like to exclude a block of code from coverage reporting, then wrap the block in a pair of comments to turn coverage off and then back on. Note that the start and end comments should be at the same indent level or the outcome will not be what you expect. To turn off the coverage, put the text "#JSCOVERAGE_IF" into a comment. To turn it back on, use a comment with one of the following texts "#JSCOVERAGE_IF 0", or "#JSCOVERAGE_ENDIF".
ExampleTo instrument and report on a file using Mocha as your test runner: mocha = require('gulp-mocha');
cover = require('gulp-coverage');
gulp.task('test', function () {
return gulp.src('tests/**/*.js', { read: false })
.pipe(cover.instrument({
pattern: ['src/**/*.js'],
debugDirectory: 'debug'
}))
.pipe(mocha())
.pipe(cover.gather())
.pipe(cover.format())
.pipe(gulp.dest('reports'));
}); To instrument and report using Jasmine as your test system: jasmine = require('gulp-jasmine');
cover = require('gulp-coverage');
gulp.task('jasmine', function () {
return gulp.src('tests/**/*.js')
.pipe(cover.instrument({
pattern: ['src/**/*.js'],
debugDirectory: 'debug'
}))
.pipe(jasmine())
.pipe(cover.gather())
.pipe(cover.format())
.pipe(gulp.dest('reports'));
}); To report coverage with gulp-coveralls: mocha = require('gulp-mocha');
cover = require('gulp-coverage');
coveralls = require('gulp-coveralls');
gulp.task('coveralls', function () {
return gulp.src('tests/**/*.js', { read: false })
.pipe(cover.instrument({
pattern: ['src/**/*.js']
}))
.pipe(mocha()) // or .pipe(jasmine()) if using jasmine
.pipe(cover.gather())
.pipe(cover.format({ reporter: 'lcov' }))
.pipe(coveralls());
}); TasksThere are five different tasks, After the The gulp-coverage The Instrument taskoptions
The patterns can include match and exclude patterns. In the Mocha and Jasmine examples shown above, there are two JavaScript files
The Gather TaskThe gather task will collate all of the collected data and form this data into a JSON structure that will be placed into the Gulp task stream. It will not pass the original stream files into the stream, so gather cannot be used before another Gulp task that requires the original stream contents. The format of the JSON structure is a Modified LCOV format. The format has been modified to make it much easier for a template engine like JADE or HAML to generate decorated source code output. The Modified LCOV JSON format
Each
Source contains
Each statement
The Enforce TaskThe optionsIf you would like to specify thresholds lower than 100%, pass in the thresholds in the first argument to the task. The defaults are:
If uncovered is undefined, no threshold will be defined, otherwise it must be an integer of the number of files that are allowed to not be covered. Setting this to 0 will enforce that there are no uncovered files that match the patterm passed into the instrument task. The Format TaskThe The coverage file will be called "coverage.{reporter}" by default and can be output to the disk using gulp.dest(). if the reporter is You must call optionsThe task takes one optional argument that is either an object that contains the options, or is an array of objects that contain options. If the argument is an array, then two vinyl files will be created and added to the gulp stream. There are 2 options, here are the default values:
Calling format with the following arguments will all create two vinyl files in the gulp stream that have a path of coverage.html and coverage.json respectively: Multiple Formats Example 1
Multiple Formats Example 2
Multiple Formats Example 3
The Report Task (Deprecated)This task is deprecated because it does not support the gulp.dest task and will probably be removed before the first 1.0.0 release. Use The Gather Task and The Format Task instead. Report will generate the reports for the instrumented files and can only be called after options
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论