dylanb / gulp-coverage Goto Github PK
View Code? Open in Web Editor NEWGulp coverage reporting for Node.js that is independent of the test runner
License: MIT License
Gulp coverage reporting for Node.js that is independent of the test runner
License: MIT License
Hi,
Curious:) Would there be any templates for coverage report?
Regards,
Denis.
When im testing my project, sometimes they fail because an "__instrumented_miss" property is added inside objects
Hey, this looks very handy. The problem is I'm new to Node & Gulp. I was surprised to see this has an outFile
param. How can the output be piped into something? For example if I want to do something to coverage.html
before I use gulp.dest
to store it somewhere else. Or if I wanted to get gulp-coverage
to return JSON and pipe that into something that'll fail the build if the test coverage is too low.
My tests are failing when I use gulp-coverage
and rewire __set__
method. Running mocha
from terminal or just gulp-mocha
seems to be working fine. This is the current configuration I have:
gulp.task('test', function () {
gulp.src('./test/*', { read: false })
.pipe(cover.instrument({
pattern: ['index.js', 'src/**/*.js']
}))
.pipe(mocha())
.pipe(cover.gather())
.pipe(cover.format({
reporter: 'html',
outFile: 'coverage.html'
}))
.pipe(gulp.dest('.'))
.pipe(exit());
});
And the error I'm getting (It applies for any var):
1) Providers should return 500 updating state on database error:
ReferenceError: Provider is not defined
at Object.eval (eval at __set__ (/Users/nakes/Projects/api-admin/src/handlers/provider.js:206:63), <anonymous>:1:1)
at Object.__set__ (/Users/nakes/Projects/api-admin/src/handlers/provider.js:206:49)
at Context.<anonymous> (/Users/nakes/Projects/api-admin/test/providers.js:87:14)
at Test.Runnable.run (/Users/nakes/Projects/api-admin/node_modules/gulp-mocha/node_modules/mocha/lib/runnable.js:216:15)
at Runner.runTest (/Users/nakes/Projects/api-admin/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:373:10)
at /Users/nakes/Projects/api-admin/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:451:12
at next (/Users/nakes/Projects/api-admin/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:298:14)
at /Users/nakes/Projects/api-admin/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:308:7
at next (/Users/nakes/Projects/api-admin/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:246:23)
at Object._onImmediate (/Users/nakes/Projects/api-admin/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:275:5)
Any ideas?. Thanks!
format
task should take the JSON that is produced by the gather
task and add another format to the stream. The default and first formatter will be the HTML formatter. It should be additive in that it should still be possible to use gather->format->enforce.
I want to get the condition coverage report, it seems that only line coverage can be reported.
/Users/bbigelow/work/DAW/scriptsure_platform/node_modules/gulp-coverage/contrib/cover.js:519
splintered.reduce(function(p, c) {
^
TypeError: Reduce of empty array with no initial value
at Array.reduce (native)
at getSegments (/Users/bbigelow/work/DAW/scriptsure_platform/node_modules/gulp-coverage/contrib/cover.js:519:16)
at /Users/bbigelow/work/DAW/scriptsure_platform/node_modules/gulp-coverage/contrib/cover.js:828:28
at Array.forEach (native)
at /Users/bbigelow/work/DAW/scriptsure_platform/node_modules/gulp-coverage/contrib/cover.js:811:14
at Array.forEach (native)
at CoverageSession.allStats (/Users/bbigelow/work/DAW/scriptsure_platform/node_modules/gulp-coverage/contrib/cover.js:796:31)
at Transform._flush (/Users/bbigelow/work/DAW/scriptsure_platform/node_modules/gulp-coverage/index.js:76:31)
at Transform. (/Users/bbigelow/work/DAW/scriptsure_platform/node_modules/gulp-coverage/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:135:12)
at Transform.g (events.js:199:16)
at Transform.emit (events.js:129:20)
at finishMaybe (/Users/bbigelow/work/DAW/scriptsure_platform/node_modules/gulp-coverage/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:371:12)
at endWritable (/Users/bbigelow/work/DAW/scriptsure_platform/node_modules/gulp-coverage/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:378:3)
at Transform.Writable.end (/Users/bbigelow/work/DAW/scriptsure_platform/node_modules/gulp-coverage/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:356:5)
at DestroyableTransform.onend (/Users/bbigelow/work/DAW/scriptsure_platform/node_modules/gulp-jasmine/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:523:10)
at DestroyableTransform.g (events.js:199:16)
Hi,
Currently code coverage for es6 generators won't work due to esprimajs not supporting them right?
Example err:
events.js:85
throw er; // Unhandled 'error' event
^
Error: Line 9: Unexpected token *
at throwError (/projects/node_modules/gulp-coverage/contrib/esprima.js:1470:21)
at throwUnexpected (/projects/node_modules/gulp-coverage/contrib/esprima.js:1527:9)
I'm tinkering with KoaJS and was trying to test some routes which use generator functions.
Gulp task is:
gulp.task('test', function () {
return gulp.src(['app/**/*.spec.js'], { read: false })
.pipe(cover.instrument({
pattern: [
'app/**/*.js',
'!app/**/*.spec.js'
],
debugDirectory: 'test/debug'
}))
.pipe(mocha())
.pipe(cover.report({
outFile: 'test/coverage.html'
}));
Using mocha manually on the command line (no coverage) the tests run OK with the --harmony flag.
Have tinkered with this (no joy):
.pipe(mocha({harmony: true}))
Thanks.
I was thinking of using this on a project, but I want to pipe the lcov file to coveralls, not just consume it in format() - but the object put into the stream by gather() isn't a vinyl file object. This breaks all the downstream plugins I've tried to use with it.
Any objection to me submitting a PR for this - making the thing passed between the separate plugins a vinyl object?
Any problem you would see with doing this? You've modified the lcov format, do you think it would still work with other reporting tools like coveralls?
Add support for JSON output to a file. Make the output pretty.
I don't have any tests for the bootstrap
directory. I think the files should still show up in the coverage report (showing 0% coverage). This is very important for the enforce
task, as someone could just not write any tests and pass. What are your thoughts?
'use strict';
// Load other modules
var gulp = require( 'gulp' );
var glob = require( 'glob' );
var mocha = require( 'gulp-mocha' );
var cover = require( 'gulp-coverage' );
// File patterns to instrument
var bootstrap = 'bootstrap/*.js';
var controllers = 'controllers/**/*.js';
var events = 'events/**/*.js';
var middleware = 'middleware/**/*.js';
var models = 'models/**/*.js';
// Test files pattern
var tests = glob.sync( 'test/**/*.js' );
gulp.task( 'default', function () {
gulp.src( tests, { 'read' : false } )
.pipe( cover.instrument( {
'pattern' : [ bootstrap, controllers, events, middleware, models ],
'debugDirectory' : 'debug'
} ) )
.pipe( mocha( { } ) )
.pipe( cover.report( {
'outFile' : 'coverage.html'
} ) )
.pipe( cover.enforce() );
} );
physical lines : 21163
lines of source code : 16045
total comment : 2533
singleline : 1044
multiline : 1489
empty : 2585
number of files read : 65
gulp-coverage reports this:
"sloc": 3587,
"ssoc": 6711,
"sboc": 1251,
"coverage": 37.97044884304432,
"statements": 35.2853524064968,
"blocks": 27.018385291766588,
And lists only 35 files
Why are files missing ?
FYI:
Notice that the source lists are the same
// ==========================
gulp.task('linesOfCode', function(){
gulp.src(['./../Server/source//.js'])
.pipe(sloc());
});
// ==========================
gulp.task('nodeuniter', ['clean_uniter'], function () {
var stream = gulp.src(['./testing/.js'], {read: false})
.pipe(cover.instrument({
pattern: ['./../Server/source//*.js'],
debugDirectory: './.debug'
}))
.pipe(nodeunit({
reporter: 'junit',
reporterOptions: {
output: './.unitReport'
}
}))
.pipe(cover.gather())
.pipe(cover.format([{reporter: 'html'}, {reporter: 'json'}]))
.pipe(gulp.dest('./.covReport'));
return stream;
});
// ==========================
gulpfile.js
:
gulp.src('./index.js')
.pipe(coverage.instrument({
pattern: ['./test/main.js'],
debugDirectory: 'debug'
}))
.pipe(mocha())
.pipe(coverage.gather());
What happens:
debug
directory..coverdata
directory is created. It contains an empty .cover_5097043255809695
directory..coverrun
file is created. It contains { "run" : ".cover_5097043255809695" }
.The instrument cover
option seems to having some problems.
src/**/*.js
doesn't work even though the src
directory is present . **/src/**/*.js
works, however.
The problem is that the full file path will be present in the coverage report, which is not good. I noticed you also had this issue in the screenshot.
I believe the multi globbing is not picking up the right base dir.
A glob like './directory/file.js' should be equivalent to 'directory/file.js'
TypeError: Object.defineProperty called on non-object
at Function.defineProperty (native)
at __intro_MDZac7 (/xxx/src/main.js:24:41)
at Object.randomString (/xxx/src/main.js:95:64)
at Context.<anonymous> (/xxx/test/main.js:11:16)
at callFn (/xxx/node_modules/mocha/lib/runnable.js:223:21)
at Test.Runnable.run (/xxx/node_modules/mocha/lib/runnable.js:216:7)
at Runner.runTest (/xxx/node_modules/mocha/lib/runner.js:374:10)
at /xxx/node_modules/mocha/lib/runner.js:452:12
at next (/xxx/node_modules/mocha/lib/runner.js:299:14)
at /xxx/node_modules/mocha/lib/runner.js:309:7
The relevant code is:
var crypto = require('crypto');
var self = {};
var bytesMapper = {
ascii: 1,
utf8: 2,
utf16le: 4,
ucs2: 8,
base64: 1.5,
binary: 0.25,
hex: 0.5
};
self.randomString = function randomString(length, encoding) {
encoding = encoding || 'ascii';
var buf = crypto.pseudoRandomBytes(length * bytesMapper[encoding] * 2);
return buf.toString(encoding).substr(0, length);
};
module.exports = self;
Here is the instrumented code:
// Instrumentation Header
{
var fs = require('fs');
var __statement_Y9dYKY, __expression_s_b1xL, __block_QpunSS;
var store = require('/xxx/node_modules/gulp-coverage/contrib/coverage_store.js');
__statement_Y9dYKY = function(i) {
var fd = store.register('/xxx/src/main.js');
fs.writeSync(fd, '{"statement": {"node": ' + i + '}},\n');
};
__expression_s_b1xL = function(i) {
var fd = store.register('/xxx/src/main.js');
fs.writeSync(fd, '{"expression": {"node": ' + i + '}},\n');
};
__block_QpunSS = function(i) {
var fd = store.register('/xxx/src/main.js');
fs.writeSync(fd, '{"block": ' + i + '},\n');
};
__intro_MDZac7 = function(id, obj) {
// console.log('__intro: ', id, ', obj.__instrumented_miss: ', obj.__instrumented_miss, ', obj.length: ', obj.length);
Object.defineProperty && Object.defineProperty(obj, '__instrumented_miss', {enumerable: false, writable: true});
obj.__instrumented_miss = obj.__instrumented_miss || [];
if ('undefined' !== typeof obj && null !== obj && 'undefined' !== typeof obj.__instrumented_miss) {
if (obj.length === 0) {
// console.log('interim miss: ', id);
obj.__instrumented_miss[id] = true;
} else {
obj.__instrumented_miss[id] = false;
}
}
return obj;
};
function isProbablyChainable(obj, id) {
return obj &&
obj.__instrumented_miss[id] !== undefined &&
'number' === typeof obj.length;
}
__extro_japAko = function(id, obj) {
var fd = store.register('/xxx/src/main.js');
// console.log('__extro: ', id, ', obj.__instrumented_miss: ', obj.__instrumented_miss, ', obj.length: ', obj.length);
if ('undefined' !== typeof obj && null !== obj && 'undefined' !== typeof obj.__instrumented_miss) {
if (isProbablyChainable(obj, id) && obj.length === 0 && obj.__instrumented_miss[id]) {
// if the call was not a "constructor" - i.e. it did not add things to the chainable
// and it did not return anything from the chainable, it is a miss
// console.log('miss: ', id);
} else {
fs.writeSync(fd, '{"chain": {"node": ' + id + '}},\n');
}
obj.__instrumented_miss[id] = undefined;
} else {
fs.writeSync(fd, '{"chain": {"node": ' + id + '}},\n');
}
return obj;
};
};
////////////////////////
// Instrumented Code
(function () {
{
__statement_Y9dYKY(0);
var crypto = (__expression_s_b1xL(1), require('crypto'));
}
{
__statement_Y9dYKY(2);
var self = {};
}
{
__statement_Y9dYKY(3);
var bytesMapper = {
ascii: 1,
utf8: 2,
utf16le: 4,
ucs2: 8,
base64: 1.5,
binary: 0.25,
hex: 0.5
};
}
{
__statement_Y9dYKY(4);
self.randomString = function randomString(length, encoding) {
__block_QpunSS(0);
{
__statement_Y9dYKY(5);
encoding = (__expression_s_b1xL(6), (__expression_s_b1xL(7), encoding) || 'ascii');
}
{
__statement_Y9dYKY(8);
var buf = __extro_japAko(9, __intro_MDZac7(9, crypto).pseudoRandomBytes((__expression_s_b1xL(10), (__expression_s_b1xL(11), (__expression_s_b1xL(12), length) * bytesMapper[encoding]) * 2)));
}
return __expression_s_b1xL(13), __extro_japAko(14, __intro_MDZac7(14, __extro_japAko(15, __intro_MDZac7(15, buf).toString(encoding))).substr(0, length));
};
}
{
__statement_Y9dYKY(16);
module.exports = self;
}
}());
I try to load coffeescript to cover but it seems not work.
Will it support coffeescript?
I've been unable to ignore certain lines of code, as stated on the JSCoverage docs. I'm doing something like on the following snippet:
//#JSCOVERAGE_IF
if (!module.parent) {
server.start(function () {
server.log('info', 'Server running at: ' + server.info.uri);
});
}
Same applies enclosing the code using the form //#JSCOVERAGE_IF 0
, //#JSCOVERAGE_ENDIF
.
Is this currently supported or am I doing something wrong?
Thanks!
Ok, this is working great for me on Mac / Linux but not Windows. It seems the stats aren't being gathered. enforce
doesn't fail when it should and report
isn't showing any code or stats.
I know this isn't a problem with a missing dependency or something like that because it's being tested with Travis. See build #9 where I set each of the enforce options to 100
to deliberately fail the build.
I just tried pulling the latest revision of this project (from GitHub) and running the tests. I got this:
stream.js:94
throw er; // Unhandled stream error in pipe.
^
TypeError: Cannot call method 'stats' of undefined
at Suite.<anonymous> (C:\Users\Digital\Code\GitHub\gulp-coverage\test\cover.js:95:50)
at context.describe.context.context (C:\Users\Digital\Code\GitHub\gulp-coverage\node_modules\gulp-mocha\node_modules\mocha\lib\interfaces\bdd.js:73:10)
at Suite.<anonymous> (C:\Users\Digital\Code\GitHub\gulp-coverage\test\cover.js:87:5)
at context.describe.context.context (C:\Users\Digital\Code\GitHub\gulp-coverage\node_modules\gulp-mocha\node_modules\mocha\lib\interfaces\bdd.js:73:10)
at Object.<anonymous> (C:\Users\Digital\Code\GitHub\gulp-coverage\test\cover.js:23:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
npm ERR! weird error 8
npm ERR! not ok code 0
I would be happy to investigate this and see if I can find the issue but I wasn't sure if I was just implementing this incorrectly.
Here's the html coverage report for my chromewut extension: https://rawgit.com/natedsaint/chromewut/master/reports/coverage.html
As you can see, each class looks good except that the line that contains the method definitions after the first one appear to be cut off. I'm not sure if it's that my code is formatted in such a way it doesn't know how to generate the report, or if there's a config I'm missing, or it's simply a bug.
Let me know if I can be of any assistance.
I have been unable to successfully generate code coverage for my nodejs test code and wondered if there may be in issue with either the version of gulp-jasmine or some other dependency I am using?
The gulp task I am running looks like this:
gulp.task('server-unit-tests', function () {
return gulp.src('./server/**/*.js', { read: false })
.pipe(cover.instrument({
pattern: ['./server/test/**/*.spec.js']
}))
.pipe(jasmine({
verbose: true,
includeStackTrace: true
}))
.pipe(cover.gather())
.pipe(cover.format([
{ reporter: 'html', outFile: 'coverage.html' },
{ reporter: 'json', outFile: 'coverage.json' }
]))
.pipe(gulp.dest('./server/coverage'));
});
This generates the following .json
file:
{
"files": [],
"sloc": 0,
"ssoc": 0,
"sboc": 0,
"coverage": null,
"statements": null,
"blocks": null,
"uncovered": [
"server/test/config.spec.js",
"server/test/utils/cypher-promise.spec.js"
]
}
I originally thought it maybe due to a different version of one of the libraries but when I checked out the latest code from here and when I run gulp
on gulp-coverage
I always see one of the jasmine test showing as 0% coverage and wondered if this could be related?
My package versions:
{
"gulp": "^3.8.8",
"gulp-coverage": "^0.3.31",
"gulp-jasmine": "^1.0.0"
}
Have I missed something obvious?
Running npm audit
against latest package version reveals several problems which likely need dependency updates in this library.
First and foremost is the fact that this package still relies on jade
rather modern pug
replacement. There are 5 vulnerabilities related to this package alone.
Second, an update should be made to multimatch
to get latest version which would eliminate underlying lodash
vulnerabilities as multimatch
no longer uses this package as dependency.
This would leave only a single remaining vulnerability exposed by the multimatch
library for which I have already opened an issue - sindresorhus/multimatch#26
I have tried implementing gulp-coverage in my angular 4 project but it's not working!
The code which creates the debugDirectory only checks if the directory does not exist, it does not check or create any parent directories and thus fails.
Steps to reproduce the issue:
cover.instrument
options: debugDirectory : "foo/bar/spam"
The problem is near the fs.mkdirSync()
calls in contrib/covers.js
.
A simple solution would be to use a function which ensures all parent directories are created:
e.g.
function mkdirs(path){
var dirs = path.split('/');
for(var i=1,l=dirs.length; i<=l; i++){
path = dirs.slice(0, i).join('/');
if (! fs.existsSync(path) ) {
fs.mkdirSync(path);
}
}
}
Paraphrasing:
jade has been renamed to pug, please install the latest version of pug instead of jade
mini match: please update to minimatch 3.0.2 or higher to avoid a regexp DoS issue
Jade => transformers: deprecated, use jstransformer
Is there a way to turn these off, or update the package to new versions that fix these problems?
This gulpfile
:
gulp = require('gulp');
mocha = require('gulp-mocha');
cover = require('gulp-coverage');
gulp.task('test', function () {
return gulp.src('test/**/*.js', { read: false })
.pipe(cover.instrument({
pattern: ['src/**/*.js'],
debugDirectory: 'debug'
}))
.pipe(mocha())
.pipe(cover.gather())
.pipe(cover.format({reporter: 'html'}))
.pipe(gulp.dest('reports'));
});
When I run gulp test
I get
[email protected])
λ gulp test
[20:44:16] Using gulpfile ~\Documents\GitHub\node-cognitive-services\gulpfile.
js
[20:44:16] Starting 'test'...
API Test
√ should throw an error if a body parameter is required for json and not p
resent
√ should throw an error if the boolean body parameter has a value other th
an true or false
√ should throw an error if a body parameter is required and its value is n
ot in the list of options
√ should throw an error if a parameter is required and not present
√ should throw an error if more than one parameter is required but not pre
sent
√ should throw an error if a parameter is required and its value is not in
the list of options
√ should accept a list of options for parameters
√ should throw an error if the boolean parameter has a value other than tr
ue or false
√ should not throw an error if the endpoint is supported
√ should throw an error if the endpoint is not supported
√ should throw an error if a header is required but not present
√ should throw an error if more than one headers are required but not pres
ent
12 passing (8ms)
[20:44:19] 'test' errored after 3.06 s
[20:44:19] Error: Received a non-Vinyl object in `dest()`
at DestroyableTransform.normalize [as _transform] (C:\Users\mparn\Document
s\GitHub\node-cognitive-services\node_modules\vinyl-fs\lib\dest\prepare.js:16:
17)
at DestroyableTransform.Transform._read (C:\Users\mparn\Documents\GitHub\n
ode-cognitive-services\node_modules\readable-stream\lib\_stream_transform.js:1
82:10)
at DestroyableTransform.Transform._write (C:\Users\mparn\Documents\GitHub\
node-cognitive-services\node_modules\readable-stream\lib\_stream_transform.js:
170:83)
at doWrite (C:\Users\mparn\Documents\GitHub\node-cognitive-services\node_m
odules\readable-stream\lib\_stream_writable.js:406:64)
at writeOrBuffer (C:\Users\mparn\Documents\GitHub\node-cognitive-services\
node_modules\readable-stream\lib\_stream_writable.js:395:5)
at DestroyableTransform.Writable.write (C:\Users\mparn\Documents\GitHub\no
de-cognitive-services\node_modules\readable-stream\lib\_stream_writable.js:322
:11)
at Pumpify.Duplexify._write (C:\Users\mparn\Documents\GitHub\node-cognitiv
e-services\node_modules\duplexify\index.js:208:22)
at doWrite (C:\Users\mparn\Documents\GitHub\node-cognitive-services\node_m
odules\readable-stream\lib\_stream_writable.js:406:64)
at writeOrBuffer (C:\Users\mparn\Documents\GitHub\node-cognitive-services\
node_modules\readable-stream\lib\_stream_writable.js:395:5)
at Pumpify.Writable.write (C:\Users\mparn\Documents\GitHub\node-cognitive-
services\node_modules\readable-stream\lib\_stream_writable.js:322:11)
Any ideas on how to fix this?
How can I output a summary of coverage as text? Preferably, I'd like to pass the json output to a function so that I can pick the parts I want and console.log them. I tried playing with format/report but I was not able to. Am I missing something?
I am getting the following error when I try to run gulp in Travis CI;
[17:27:22] Starting 'coveralls'...
[error] "2016-01-15T17:27:23.420Z" 'error from lcovParse: ' 'Failed to parse string'
[error] "2016-01-15T17:27:23.421Z" 'input: ' ''
[17:27:23] 'coveralls' errored after 529 ms
[17:27:23] Error in plugin 'gulp-coveralls'
Message:
Failed to parse string
[17:27:27] Finished 'static' after 5.94 s
npm ERR! Test failed. See above for more details.
The command "npm test" exited with 1.
It runs without incident locally, but it fails to run in Travis CI. What am I doing wrong?
Cannot read property 'statements' of undefined
I received the following error after making this change. Coverage worked fine before than.
PROJECT_DIR/backbone/kinView/node_modules/gulp-coverage/contrib/cover.js:660
interim.reduce(function(p, c) {
^
TypeError: Reduce of empty array with no initial value
at Array.reduce (native)
at linesWithData (PROJECT_DIR/backbone/kinView/node_modules/gulp-coverage/contrib/cover.js:660:13)
at PROJECT_DIR/backbone/kinView/node_modules/gulp-coverage/contrib/cover.js:770:21
at Array.forEach (native)
at CoverageSession.allStats (PROJECT_DIR/backbone/kinView/node_modules/gulp-coverage/contrib/cover.js:758:31)
at Transform._flush (PROJECT_DIR/backbone/kinView/node_modules/gulp-coverage/index.js:76:31)
at Transform.<anonymous> (PROJECT_DIR/backbone/kinView/node_modules/gulp-coverage/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:135:12)
at Transform.g (events.js:180:16)
at Transform.emit (events.js:92:17)
at finishMaybe (PROJECT_DIR/backbone/kinView/node_modules/gulp-coverage/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:371:12)
I'd like to be able to wire this up with https://www.npmjs.org/package/gulp-coveralls (or something else that reports to coveralls), but that consumes the raw LCOV data; not the JSON-formatted output
Ideally:
gulp.task('test:unit', function() {
return gulp.src('test//*.js')
.pipe(coverage.instrument({pattern: ['lib//*.js']}))
.pipe(mocha())
.pipe(coverage.gather())
.pipe(coverage.format({reporter: 'lcov'}))
.pipe(coveralls());
});
gulp-coverage unable to create the coverage.html
reporter file and my coverage test hangs up. I am using mocha as test runner. Below is my gulpfile.js:
gulp.src( tests, { 'read' : false } )
.pipe( cover.instrument( {
'pattern' : [ handlers, services ],
'debugDirectory' : 'instrumented'
} ) )
.pipe( mocha( options ) )
.pipe( cover.gather() )
.pipe( cover.format( {
'reporter' : 'html',
'outFile' : 'coverage.html'
} ) )
.pipe( cover.enforce( {
'statements' : 70,
'blocks' : 70,
'lines' : 70
} ) )
.once( 'error', function () {
process.exit( 1 );
} )
.once( 'end', function () {
process.exit();
} );
Help to avoid issues like the one faced by @adam-lynch in issue #4
With [email protected] / [email protected] / [email protected]
Currently, piping format()
to gulp.dest()
will fail because there is no relative
property specified when writing to the stream.
It's entirely possible that I'm doing something wrong here because my gulp-fu isn't the strongest, but I find it more likely that something in gulp
has changed recently which broke this, because this happens frequently with gulp and it's a source of massive frustration for everyone who ever uses it.
But yeah, we're going to want to output ~lcov-ish files to json, and to do that we are going to want to use the format()
tool, but maybe report()
will be a suitable workaround for now
@dylanb thanks for accepting my contribution, Can you publish the latest changes to npm?
To address the concern raised by @p3drosola in issue #3
I'm using gulp-coverage in my gulpfile like so:
gulp.task('test', () => {
return gulp.src('test/**/*.js', {read: false})
.pipe(cover.instrument({
pattern: [`${srcDir}/**/*.js`, `!${srcDir}/configure.js`],
debugDirectory: 'debug',
}))
.pipe(mocha({reporter: 'nyan'}))
.pipe(cover.gather())
.pipe(cover.format())
.pipe(gulp.dest('reports'));
});
This the error I'm getting when running the task:
c:\Users\ketsu\Documents\Development\plexacious>gulp test
(node:14780) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
[23:57:50] Using gulpfile c:\Users\ketsu\Documents\Development\plexacious\gulpfile.js
[23:57:50] Starting 'test'...
events.js:160
throw er; // Unhandled 'error' event
^
Error: Line 23: Unexpected reserved word
at throwError (c:\Users\ketsu\Documents\Development\plexacious\node_modules\instrumentjs\esprima.js:1470:21)
at throwUnexpected (c:\Users\ketsu\Documents\Development\plexacious\node_modules\instrumentjs\esprima.js:1518:17)
at parsePrimaryExpression (c:\Users\ketsu\Documents\Development\plexacious\node_modules\instrumentjs\esprima.js:1832:16)
at c:\Users\ketsu\Documents\Development\plexacious\node_modules\instrumentjs\esprima.js:3577:38
at trackLeftHandSideExpressionAllowCall (c:\Users\ketsu\Documents\Development\plexacious\node_modules\instrumentjs\esprima.js:3483:61)
at parsePostfixExpression (c:\Users\ketsu\Documents\Development\plexacious\node_modules\instrumentjs\esprima.js:1938:20)
at c:\Users\ketsu\Documents\Development\plexacious\node_modules\instrumentjs\esprima.js:3577:38
at parseUnaryExpression (c:\Users\ketsu\Documents\Development\plexacious\node_modules\instrumentjs\esprima.js:2001:16)
at c:\Users\ketsu\Documents\Development\plexacious\node_modules\instrumentjs\esprima.js:3577:38
at parseBinaryExpression (c:\Users\ketsu\Documents\Development\plexacious\node_modules\instrumentjs\esprima.js:2103:16)
In my source code file, line 23 is
class Plexacious extends EventEmitter {
If I replace this with a function declaration, the file seems to parse that line correctly. If I only remove the extends
portion, I get the same error, so it seems that it's the class
keyword itself that's causing the error.
Adding // cover: false
to the end of the line does not help.
gulp-coverage
version 0.3.38
instrumentjs
version 0.0.2 is the one installed as a dependency of gulp-coverage
, but I still get the same error after manually updating to 0.0.3.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.