-
๐ญ Iโm currently working on Inquirer
-
๐ซ How to reach me [email protected]
sboudrias / gulp-istanbul Goto Github PK
View Code? Open in Web Editor NEWIstanbul unit test coverage plugin for gulp.
License: MIT License
Istanbul unit test coverage plugin for gulp.
License: MIT License
๐ญ Iโm currently working on Inquirer
๐ซ How to reach me [email protected]
Given I run the gulp-istanbul plugin
And I have provided a glob of source files
And none of the source files are required in the test files
Then I get the error "Object.keys called on non-object"
C:\Work\<Your Project>\node_modules\gulp-istanbul\node_modules\istanbul\lib\collector.js:67
Object.keys(coverage).forEach(function (key) {
^
TypeError: Object.keys called on non-object
at Function.keys (native)
at Object.Collector.add (C:\Work\<Your Project>\node_modules\gulp-istanbul\node_modules\istanbul\lib\collector.js:67:16)
at Transform.<anonymous> (C:\Work\<Your Project>\node_modules\gulp-istanbul\index.js:81:15)
at Transform.emit (events.js:117:20)
at C:\Work\<Your Project>\node_modules\gulp-istanbul\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:942:16
at process._tickCallback (node.js:419:13)
When running in Node 6.3.1 the coverage report is incorrect and shows no test coverage. I've included the summary reports from identical code run in both environments.
Node 6
=============================== Coverage summary ===============================
Statements : 6.27% ( 24/383 )
Branches : 0% ( 0/97 )
Functions : 0% ( 0/111 )
Lines : 7.06% ( 24/340 )
================================================================================
Node 4
=============================== Coverage summary ===============================
Statements : 40.47% ( 155/383 )
Branches : 8.25% ( 8/97 )
Functions : 8.11% ( 9/111 )
Lines : 38.82% ( 132/340 )
================================================================================
.pipe($.istanbul.writeReports({
reporters: ['cobertura'],
reportOpts: {
dir: './testResults/coverage',
file: 'server.xml'
}
}))
This configuration used to output an xml cobertura coverage report. since 1.1.0 it outputs this
=============================== Coverage summary ===============================
Statements : 79.59% ( 386/485 )
Branches : 68.75% ( 121/176 )
Functions : 63.41% ( 52/82 )
Lines : 80.04% ( 385/481 )
================================================================================
This is a breaking change that should not happen in a minor version update, but what is done is done, how do we get the xml back in 1.1?
My task:
gulp.task('mocha', ['env:test'], function() {
var mongoose = require('./config/mongoose');
gulp.src(['app/**/*.js', 'config/**/*.js', 'public/**/*.js'])
.pipe(istanbul())
.on('finish', function() {
mongoose
.connect()
.then(function(db) {
return gulp.src('./test/**/*.js')
.pipe(mocha({}))
.pipe(istanbul.writeReports())
.once('end', function() {
mongoose.disconnect();
});
});
});
});
Error:
events.js:72
throw er; // Unhandled 'error' event
^
Error: Line 46: Unexpected token ;
at throwError (node_modules/gulp-istanbul/node_modules/istanbul/node_modules/esprima/esprima.js:1831:21)
at throwUnexpected (node_modules/gulp-istanbul/node_modules/istanbul/node_modules/esprima/esprima.js:1889:9)
at expect (node_modules/gulp-istanbul/node_modules/istanbul/node_modules/esprima/esprima.js:1898:13)
at parseGroupExpression (node_modules/gulp-istanbul/node_modules/istanbul/node_modules/esprima/esprima.js:2139:9)
at parsePrimaryExpression (node_modules/gulp-istanbul/node_modules/istanbul/node_modules/esprima/esprima.js:2151:20)
at parseLeftHandSideExpressionAllowCall (node_modules/gulp-istanbul/node_modules/istanbul/node_modules/esprima/esprima.js:2275:61)
at parsePostfixExpression (node_modules/gulp-istanbul/node_modules/istanbul/node_modules/esprima/esprima.js:2325:16)
at parseUnaryExpression (node_modules/gulp-istanbul/node_modules/istanbul/node_modules/esprima/esprima.js:2384:20)
at parseBinaryExpression (node_modules/gulp-istanbul/node_modules/istanbul/node_modules/esprima/esprima.js:2473:16)
at parseConditionalExpression (node_modules/gulp-istanbul/node_modules/istanbul/node_modules/esprima/esprima.js:2533:16)
at parseAssignmentExpression (node_modules/gulp-istanbul/node_modules/istanbul/node_modules/esprima/esprima.js:2559:23)
at parseExpression (node_modules/gulp-istanbul/node_modules/istanbul/node_modules/esprima/esprima.js:2585:16)
Istanbul does not appear to support reporting 0% coverage on non-required files, but this is possible through gulp-istanbul by:
Then when the istanbul reporter runs, it'll overwrite all required files' structures with actual coverage data leaving the non-required files' structures at 0%.
Is gulp-istanbul currently compatible with Gulp 4.0?
Many istanbul reporters (ex. cobertura) take 'file' as an option in addition to 'dir'. gulp-istanbul currently only passes 'dir' through in the reporter opts via:
reportOpts: { dir: opts.dir || defaultDir }
if this is changed to
reportOpts: { dir: opts.dir || defaultDir, file: opts.file }
multiple runs of gulp-istanbul can create individual report files in the same dir without overwriting.
I used previously gulp-istanbul version "0.3.1" with mocha to generate code coverage report and its working fine but when i upgraded to latest version i..e "0.10.3" i am not able to get proper code coverage report.Below is the code snippet :-
gulp.task('default', ['jshint', 'test', 'api-coverage']);
gulp.task('api-coverage', function(cb) {
gulp.src(['src//.js', 'server.js'])
.pipe(istanbul()) // Covering files
.on('finish', function() {
require(path.join(process.cwd(), 'server.js'));
gulp.src(['tests/functional/*.js'])
.pipe(mocha({
timeout: 60000
}))
.pipe(istanbul.writeReports()) // Creating the reports after tests run
.on('finish', function() {
cb();
setTimeout(process.exit, 1000);
})
})
.on('end', cb);
});
Output when i used version "0.10.3" :-
----------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
----------|----------|----------|----------|----------|----------------|
All files | 100 | 100 | 100 | 100 | |
----------|----------|----------|----------|----------|----------------|
=============================== Coverage summary ===============================
Statements : 100% ( 0/0 )
Branches : 100% ( 0/0 )
Functions : 100% ( 0/0 )
But its working fine with version "0.3.1" and here is the output :-
=============================== Coverage summary ===============================
Statements : 72.5% ( 174/240 )
Branches : 31.65% ( 25/79 )
Functions : 72.34% ( 34/47 )
Please let me know that what could be the issue here??
gulp-istanbul does not work with the new version of istanbul (0.3.13).
Tests no longer pass with this version.
Here's my gulp task:
gulp.task(taskName, function(callback) {
require('babel/register')({
stage: 0
});
gulp.src(filesToCover)
.pipe(istanbul({
instrumenter: isparta.Instrumenter,
includeUntested: true,
babel: {
stage: 0
}
}))
.pipe(istanbul.hookRequire())
.on('finish', function() {
gulp.src(testFiles, {read: false})
.pipe(mocha({
reporter: reporter
}))
.pipe(istanbul.writeReports())
.pipe(istanbul.enforceThresholds({
thresholds: {
global: minimumCodeCoverage
}
}))
.on('error', function(error) {
throw new Error("Code coverage is below " + minimumCodeCoverage + "%");
})
.on('end', callback);
});
});
When tests fail, the mocha task throws an error and coverage reports aren't generated. Is there a way to fix this?
Thanks
Line 53
global[opts.coverageVariable][path.resolve(file.path)] = covStub;
Why is path resolved for the file.path incase includeUntested is supplied ? Why isn't file.path simply used ?
Thanks!
I need this hook to my project nsmockup.
I am using vm.runInThisContext to import my JS files in node.js
var fs = require('fs'),
vm = require('vm'),
vmInclude = function(code, path) {
vm.runInThisContext(code, path);
},
vmAddFile = function(path) {
vmInclude(fs.readFileSync(path), path);
};
I can't use require in this project :(
Since changing _.defaults
to _defaultsDeep
in commit e94f537 the default reporters are always turned on.
I just use reporters: ['lcov']
and now all other default reporters like the report in the console are executed as well.
According to the scope of #79 it would be sufficient to just do the _.defaultsDeep
on reportOpts
:
- opts = _.defaultsDeep(opts, {
+ opts = _.defaults(opts, {
coverageVariable: COVERAGE_VARIABLE,
dir: defaultDir,
reporters: [ 'lcov', 'json', 'text', 'text-summary' ]
+ });
+ opts = _.defaultsDeep(opts, {
reportOpts: {
dir: opts.dir || defaultDir
}
});
If I add this task to my gulpfile.js
- I get no output in my test-tmp
.
gulp.task('pre-test', function () {
return gulp.src(['lib/**/*.js'])
// Covering files
.pipe(istanbul())
// Force `require` to return covered files
.pipe(istanbul.hookRequire())
// Write the covered files to a temporary directory
.pipe(gulp.dest('test-tmp/'));
});
However removing this line .pipe(istanbul.hookRequire())
- I get the instrumented files output in the test-tmp
folder.
In gulpfile.js, I have a setup that looks like this:
return gulp.src(config.sourceCode)
.pipe(istanbul({ includeUntested: true }))
.pipe(istanbul.hookRequire());
An issue I'm running into is that some of my modules may need to create and maintain long-running connections (e.g. to a database); these modules provide shutdown methods, but istanbul seems to be requiring or using the modules in a way that is in parallel to the rest of my testing process; shutdown is being called within the test, but istanbul seems to have a separate copy open, is this possible? At the end of the test routine, gulp simply hangs, owing to those modules keeping open connections.
Now, I can avoid this by omitting modules that behave this way from the gulp.src
but then I have to give up test coverage metrics on those files, which I'd rather not.
Any suggestions on what istanbul is doing here that would be keeping these modules open?
Use through2 instead of event-stream's through.
I have a project that contains both client-side (browserify) code and server-side code, each with separate unit tests. If I try to run istanbul with both tests in parallel, one seem to end up superseding the other. In other words, both coverage reports end up being identical, with only the client-side tests included.
I'm not entirely sure if this is an issue. I may simply not understand how to accomplish parallel istanbul tasks or this was intentional in the design of istanbul.
This isn't a major problem as my workaround for this has been to use run-squence
to prevent the tasks from running in parallel:
gulp.task('test', function(callback){
runSequence(
'serverUnitTests',
'clientUnitTests',
callback
);
});
I am mostly just curious if there is a better way to do this.
I cannot figure out how to get gulp-istanbul to work with gulp-qunit for unit testing my front-end JavaScript code.
Here is the relevant snippet from my gulpfile.js:
gulp.task('cover', function (callback) {
gulp.src('static/js/**/*.js')
.pipe(istanbul())
.on('end', callback);
});
gulp.task('test', function () {
gulp.run('cover', function () {
gulp.src('tests/js/**/*.html')
.pipe(qunit())
.pipe(istanbul.writeReports());
});
});
The error I receive (after the tests run successfully):
/my_project/node_modules/gulp-istanbul/node_modules/istanbul/lib/collector.js:67
Object.keys(coverage).forEach(function (key) {
^
TypeError: Object.keys called on non-object
at Function.keys (native)
at Object.Collector.add (/my_project/node_modules/gulp-istanbul/node_modules/istanbul/lib/collector.js:67:16)
at Stream.<anonymous> (/my_project/node_modules/gulp-istanbul/index.js:40:15)
at _end (/my_project/node_modules/gulp-istanbul/node_modules/event-stream/node_modules/through/index.js:65:9)
at Stream.stream.end (/my_project/node_modules/gulp-istanbul/node_modules/event-stream/node_modules/through/index.js:74:5)
at Transform.onend (/my_project/node_modules/gulp-qunit/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:487:10)
at Transform.g (events.js:175:14)
at Transform.EventEmitter.emit (events.js:117:20)
at /my_project/node_modules/gulp-qunit/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:924:16
at process._tickCallback (node.js:415:13)
We are testing our modules with gulp-istanbul, but in our gulpfile we require() these modules, as some of our gulp tasks use them. This causes require to cache the files before they are instrumented by istanbul, so when the tests require them, the uninstrumented versions are returned from require.cache.
I'm not sure if this is exactly a gulp-istanbul issue.
As a workaround we do:
var through = require('through2')
gulp.task('test', function(cb) {
gulp.src(['src/**/*.js'])
.pipe(through.obj(function(file, enc, cb) { // <-- workaround
delete require.cache[file.path];
cb(undefined, file);
}))
.pipe(istanbul({ includeUntested: true }))
.on('finish', function() {
gulp.src(['test/**/*.js'])
.pipe(mocha())
.pipe(istanbul.writeReports())
.on('end', cb);
});
});
I know this is probably a question for the Istanbul project, but I thought I'd start by asking y'all first:
How might one go about enhancing the coverage variable's data structure with trace info, i.e., information about the calling statement? Such information would be useful to analyze the the test code itself.
I notice the coverage variable keeps call counts of statements, branches, and functions, e.g.,
{
// File path
path: 'foo.js',
// Execution counts for statements, branches, and functions of `foo.js`
s:{
'1': 2, // Statement "1" was called 2 times
'2': 1, // Statement "2" was called 1 time
...
},
b: { ... },
f: { ... },
// Content of statements, branches, and functions of `foo.js`
statementMap: { ... },
branchMap: { ... }
fnMap: { ... },
}
But it would be nice if, instead of simple call counts, the coverage variable contained trace info of each call, e.g.,
{
path: 'foo.js',
s:{
// Call "1" was called twice, the length of `s[ '1' ]`
'1': [
// Call "1" was called by `foo-spec.js`, line 35, column 7
{
path: 'foo-spec.js',
line: '35',
col: '7'
},
// Call "2" was called by `bar-spec.js`, line 7, column 10
{
path: 'bar-spec.js',
line: '7',
col: '10'
}
],
// Call "2" was called once
'2': [ { ... } ],
...
},
b: { ... },
f: { ... },
...
}
Seems like I may need to make a custom Instrumenter. What do you think? Can you think of a simpler way of achieving this?
Thanks!
I have my code coverage being measured in the browser, and I'm writing the contents of the coverage variable to disk. how can I pass that coverage file into writeReport so that the coverage report is generated?
Ideally, how would I combine the browser coverage with the node coverage reports?
I'm seeing some strange behavior with gulp-mocha and gulp-istanbul, and have created a simple project with just the following two files to try to narrow down the issue:
gulpfile.js
const gulp = require('gulp');
const istanbul = require('gulp-istanbul');
const mocha = require('gulp-mocha');
gulp.task('test', ['pre-test'], () =>
gulp.src('test.js')
.pipe(mocha())
//.on('error', err => console.log(err) )
.pipe(istanbul.writeReports())
);
gulp.task('pre-test', () =>
gulp.src('lib/**/*.js')
.pipe(istanbul())
);
test.js
describe('something', function() {
it('should work', function() {
throw new Error('fail');
});
});
after( function() {
console.log('after');
});
I would expect gulp test
to fail and return a non-zero exit code. Instead, I see the following output, with return code 0:
[11:20:02] Using gulpfile ~/temp/gulpfile.js
[11:20:02] Starting 'pre-test'...
[11:20:02] Finished 'pre-test' after 13 ms
[11:20:02] Starting 'test'...
something
1) should work
after
0 passing (6ms)
1 failing
1) something should work:
Error: fail
at Context.<anonymous> (test.js:3:15)
2) "after all" hook
Everything in the output looks fine up til that last line: 2) "after all" hook
Now, if I comment out either the after
hook in test.js
, or the .pipe(istanbul.writeReports())
line in gulpfile.js
, the output looks fine and I get return code 1:
without after
hook
[11:28:08] Using gulpfile ~/temp/gulpfile.js
[11:28:08] Starting 'pre-test'...
[11:28:08] Finished 'pre-test' after 14 ms
[11:28:08] Starting 'test'...
something
1) should work
0 passing (5ms)
1 failing
1) something should work:
Error: fail
at Context.<anonymous> (test.js:3:15)
events.js:154
throw er; // Unhandled 'error' event
^
Error: 1 test failed.
without pipe to istanbul.writeReports
[11:26:54] Using gulpfile ~/temp/gulpfile.js
[11:26:54] Starting 'pre-test'...
[11:26:54] Finished 'pre-test' after 12 ms
[11:26:54] Starting 'test'...
something
1) should work
after
0 passing (7ms)
1 failing
1) something should work:
Error: fail
at Context.<anonymous> (test.js:3:15)
[11:26:54] 'test' errored after 21 ms
[11:26:54] Error in plugin 'gulp-mocha'
Message:
1 test failed.
So it seems like something about the combination of a mocha after
hook, and istanbul.writeReports
is causing problems. At first I thought this was likely a gulp-mocha
issue, but then I tried adding an on('error')
handler (commented out in the gulpfile code above), and the error event emitted by gulp-mocha seems correct.
I'll try to debug this further when I have some time, but I thought I'd post an issue in case anyone else is seeing this.
Versions I'm using:
โโโ [email protected]
โโโ [email protected]
โโโ [email protected]
โโโ [email protected]
Hi,
I have a project where I try to use gulp-istanbul
with coveralls
. Locally everything works fine, but on Travis-CI it doesn't work. It seems that gulp-istanbul
is unable to create the coverage
directory and thus coveralls
can't read the report. Is there any easy fix to this? Would it be possible to pipe the output from gulp-istanbul
directly into gulp-coveralls
?
Does gulp-istanbul work the the default yml config file for istanbul? I could not figure out how to get it to read it.
Hello there,
i'm unsure what i'm doing wrong but with this code
gulp.src([dir+'/lib/**.js'])
.pipe(istanbul({
instrumenter: isparta.Instrumenter,
}))
.pipe(istanbul.hookRequire())
.on('finish', function() {
gulp.src([dir+'/test/**/*.es6'], {read: false})
.pipe(mocha({reporter: 'dot'}))
.pipe(istanbul.writeReports({
dir: coverageDir,
reportOpts: {dir: coverageDir},
reporters: ['text', 'text-summary', 'json', 'html']
}))
.on('end', cb);
});
I get the code coverage working but if i change the first gulp.src(
to use .es6 (obviously renaming also the files in the folder from *.js to *.es6) i don't get it working at all.
I tried to understand what's wrong but i honestly wasn't able to understand if the problem is with gulp-istanbul, istanbul or babel :(
My gulpfile:
gulp.task('pre-test', function preTestTask() {
return gulp.src(srcPaths)
.pipe(istanbul({
includeUntested: true,
}))
.pipe(istanbul.hookRequire());
});
gulp.task('test', [ 'pre-test' ], function testTask() {
return gulp.src(testPaths)
.pipe(plumber())
.pipe(mocha())
.pipe(istanbul.writeReports());
});
gulp.task('watch-test', [ 'test' ], function watchTestTask() {
return gulp.watch(srcPaths.concat(testPaths), [ 'test' ]);
});
Running gulp watch-test
behaves as expected until a syntax error is encountered. On further changes, only the pre-test
task is run. Commenting out .pipe(istanbul.writeReports())
fixes things (but obviously without the coverage reports).
I wrote several unit tests and get the coverage report (html) as expected. I have a watch task and therefore execute the unit tests again and again. When I add another test the reported coverage goes up as expected. However, when I comment out a test the reported coverage does not go down again. For an accurate coverage report I have to terminate gulp and start my watch task again.
My otherwise good working code is:
'use strict';
var gulp = require('gulp');
var runSequence = require('run-sequence');
var jshint = require('gulp-jshint');
var jshintStylish = require('jshint-stylish');
var istanbul = require('gulp-istanbul');
var mocha = require('gulp-mocha');
var chalk = require('chalk');
var chai = require("chai");
chai.use(require("chai-as-promised"));
global.expect = chai.expect;
var paths = {
common: {
jsFiles: './lib/common/**/*.js'
},
crawler: {
jsFiles: './lib/crawler/**/*.js',
specFiles: './test/crawler/spec/**/*.js',
fixtureFiles: './test/crawler/fixtures/**/*.js'
},
webserver: {
jsFiles: './lib/webserver/**/*.js'
}
};
gulp.task('watch-crawler', ['validate-crawler'], function () {
return gulp.watch([
paths.crawler.jsFiles,
paths.common.jsFiles,
paths.crawler.specFiles,
paths.crawler.fixtureFiles
], [
'validate-crawler'
]);
});
gulp.task('validate-crawler', function (done) {
runSequence('lint-crawler', 'test-crawler', done);
});
gulp.task('lint-crawler', function () {
return gulp.src([paths.common.jsFiles, paths.crawler.jsFiles, paths.crawler.fixtureFiles])
.pipe(jshint())
.pipe(jshint.reporter(jshintStylish))
.pipe(jshint.reporter('fail'));
});
gulp.task('clean-coverage', function (done) {
(require('rimraf'))('./coverage', done);
});
gulp.task('test-crawler', ['clean-coverage'], function (done) {
gulp.src([
paths.crawler.jsFiles,
paths.common.jsFiles
])
.pipe(istanbul())
.on('finish', function () {
gulp.src([
paths.crawler.specFiles
])
.pipe(mocha())
.on('error', function () {
console.log(chalk.bold.bgRed(' TESTS FAILED '));
done();
})
.pipe(istanbul.writeReports({
reporters: ['lcov']
}))
.on('end', done);
});
});
Did I configure something wrong? Or what else might be the cause?
When I run the coverage task in gulp with mocha and istanbul, gulp reports the task as done. However, it doesn't exit.
I would have expected gulp to exit once the task is over.
gulpfile.js:
'use strict';
const gulp = require('gulp');
const mocha = require('gulp-spawn-mocha');
// istanbul requires the non-threaded gulp-mocha version
const mocha_istanbul = require('gulp-mocha');
const istanbul = require('gulp-istanbul');
const eslint = require('gulp-eslint');
const runSequence = require('run-sequence');
const test_files = 'test/**/*_test.js';
const test_helper_file = 'test/test_helper.js';
const lib_files = 'lib/**/*.js';
const app_file = 'index.js';
const min_coverage = 90;
// ...
// other unrelated tasks
// ...
gulp.task('pre-cov', () => {
return gulp.src([lib_files])
.pipe(istanbul({ includeUntested: true }))
.pipe(istanbul.hookRequire());
});
gulp.task('cov', ['pre-cov'], () => {
process.env.NOCK_BACK_MODE = 'lockdown';
return gulp.src([test_files], { read: false })
.pipe(mocha_istanbul({ reporter: 'dot' }))
.pipe(istanbul.writeReports())
.pipe(istanbul.enforceThresholds({ thresholds: { global: min_coverage } }));
});
Output when running the task (the ^C
is me exiting gulp since it doesn't do it itself)
$ gulp cov
[13:26:20] Using gulpfile ~/project/gulpfile.js
[13:26:20] Starting 'pre-cov'...
[13:26:21] Finished 'pre-cov' after 125 ms
[13:26:21] Starting 'cov'...
โคโคโคโคโคโคโคโคโคโคโคโคโคโคโคโคโคโคโคโคโคโคโค
23 passing (249ms)
---------------------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
---------------------|----------|----------|----------|----------|----------------|
lib/ | 100 | 100 | 100 | 100 | |
my_lib.js | 100 | 100 | 100 | 100 | |
---------------------|----------|----------|----------|----------|----------------|
All files | 100 | 100 | 100 | 100 | |
---------------------|----------|----------|----------|----------|----------------|
=============================== Coverage summary ===============================
Statements : 100% ( 136/136 )
Branches : 100% ( 25/25 )
Functions : 100% ( 20/20 )
Lines : 100% ( 135/135 )
================================================================================
[13:26:21] Finished 'cov' after 921 ms
^C
All other gulp tasks running fine and exiting properly.
$ gulp -v
[13:30:28] CLI version 3.9.1
[13:30:28] Local version 3.9.1
$ node -v
v4.4.3
If I run gulp-istanbul for the the first time, it successfully outputs a report to the specified directory. If I re-run the task thereafter, it throws the below error:
stream.js:94
throw er; // Unhandled stream error in pipe.
^
ReferenceError: window is not defined
at Object.<anonymous> (c:\Projects\websprototype\test\server\unit\results\coverage\lcov-report\prettify.js:
1:63)
at Module._compile (module.js:456:26)
at Module._extensions..js (module.js:474:10)
at Object.Module._extensions..js (c:\Projects\websprototype\build\node_modules\gulp-istanbul\node_modules\i
stanbul\lib\hook.js:101:13)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at c:\Projects\websprototype\build\node_modules\gulp-mocha\node_modules\mocha\lib\mocha.js:172:27
at Array.forEach (native)
Here is an example of my gulp task:
gulp.task('mocha-coverage', function (cb) {
gulp.src(['xxx, xxx'])
.pipe(istanbul())
.on('finish', function () {
gulp.src(['xxx'])
.pipe(mocha())
.pipe(istanbul.writeReports({
dir: './coverage'
}))
.on('end', cb);
});
});
Any chance you can make a new release?
I have a problem with the integration of gulp-istanbul with gulp-mocha.
The report indicates that the feature is not covered.
This gist show you the test file and the script file. They are not in the same directory
If you need more information, please feel free to ask
I have the following task:
var gulp = require('gulp');
var mocha = require('gulp-mocha');
var istanbul = require('gulp-istanbul');
var spec_files = ['test/**/*_spec.js'];
var every_js_file = ['lib/**/*.js', 'helpers/**/*.js', 'test/**/*.js', 'index.js'];
var mocha_reporter = 'list';
gulp.task('mocha-istanbul', function(cb) {
gulp.src(every_js_file)
.pipe(istanbul({ includeUntested: true }))
.pipe(istanbul.hookRequire())
.on('finish', function () {
gulp.src(spec_files, { read: false })
.pipe(mocha({ reporter: mocha_reporter }))
.pipe(istanbul.writeReports( { reporters: ['html', 'text-summary'] }))
.pipe(istanbul.enforceThresholds({ thresholds: { global: 90 } }))
.on('end', cb);
});
});
When I run it, I get my tests results and the coverage report both in the terminal and as html on disk. But the task run finishes with an error:
events.js:85
throw er; // Unhandled 'error' event
^
Error: Coverage failed
This error seems to come from mocha. When I run mocha on its own with this task:
gulp.task('mocha', function() {
return gulp.src(spec_files, { read: false })
.pipe(mocha({ reporter: mocha_reporter }));
});
it runs just fine, no error.
Because mocha runs fine on its own, I'm leaning towards gulp-istanbul. Any ideas?
I have the following two tasks that work (complete) when the jasmine tests complete successfully, however the jasmine
task does not complete when the tests fail. Removing istanbul from the task, the task completes.
gulp.task('pre-test', ['lint', 'lint:test'], function() {
return gulp.src(paths.src)
.pipe(istanbul())
// Force require to return covered files
.pipe(istanbul.hookRequire())
// Write the covered files to a temporary directory
.pipe(gulp.dest('test-tmp/'));
gulp.task('jasmine', ['compile:tests', 'lint', 'lint:test', 'pre-test'], function() {
return gulp.src(paths.srcTests)
.pipe(jasmine())
.pipe(istanbul.writeReports());
});
When trying the basic example from the readme, I'm getting the following error:
[15:16:29] 'test' errored after 1.4 s task completion callback called too many times
I assume this is related to this new feature of orchestrator? robrich/orchestrator#10 plus that you're also calling end within the plugin?: https://github.com/SBoudrias/gulp-istanbul/blob/master/index.js#L79
[15:16:29] Local version 3.8.2
Hi,
Is there any way to suppress coverage report display in stdout? I would like to display the report generated by remap-istanbul instead.
thanks,
Jerry
With recent changes to gulp.src
, is it possible to do the following:
var istanbul = require('gulp-istanbul');
var mocha = require('gulp-mocha'); // Using mocha here, but any test framework will work
gulp.task('test', function () {
return gulp.src(['lib/**/*.js', 'main.js'])
.pipe(istanbul()) // Covering files
.pipe(gulp.src(['test/*.js']))
.pipe(mocha())
.pipe(istanbul.writeReports()) // Creating the reports after tests runned
});
If so, can this be documented?
The running fails on generators. The issue is with this script and not with Istanbul.
events.js:141
throw er; // Unhandled 'error' event
^
Error: Unable to parse /{censored}.js
Line 38: Unexpected token *
npm ERR! Test failed. See above for more details.
I recently added gulp-istanbul to my gulp build. I used the example in the README with mocha.
Here are my tasks:
gulp.task('pre-unit', function() {
return gulp.src([
'app/**/*.js'
])
.pipe(istanbul())
.pipe(istanbul.hookRequire());
});
gulp.task('unit', ['lint', 'pre-unit'], function() {
return gulp.src(['test/unit/**/*.js'])
.pipe(plumber())
.pipe(notify({ title: 'Unit Tests', message: 'Running unit tests.', onLast: true }))
.pipe(mocha())
.pipe(istanbul.writeReports({
reporters: ['text-summary', 'html'],
reportOpts: {
html: { dir: './coverage' }
}
}))
.pipe(istanbul.enforceThresholds({ thresholds: { global: 85 } }));
});
Everything works fine until I add istanbul to a task using gulp.watch. When I add a new line to a file, it gives me this error:
Cannot read property 'start' of undefined
Details:
domain: [object Object]
domainThrown: true
Stack:
TypeError: Cannot read property 'start' of undefined
at /Users/planetmalone/projekts/tims/Web/node_modules/gulp-istanbul/node_modules/istanbul/lib/object-utils.js:59:44
at Array.forEach (native)
at Object.addDerivedInfoForFile (/Users/planetmalone/projekts/tims/Web/node_modules/gulp-istanbul/node_modules/istanbul/lib/object-utils.js:58:37)
at Object.Collector.fileCoverageFor (/Users/planetmalone/projekts/tims/Web/node_modules/gulp-istanbul/node_modules/istanbul/lib/collector.js:94:15)
at /Users/planetmalone/projekts/tims/Web/node_modules/gulp-istanbul/node_modules/istanbul/lib/report/text-summary.js:70:66
at Array.forEach (native)
at TextSummaryReport.Report.mix.writeReport (/Users/planetmalone/projekts/tims/Web/node_modules/gulp-istanbul/node_modules/istanbul/lib/report/text-summary.js:69:27)
at /Users/planetmalone/projekts/tims/Web/node_modules/gulp-istanbul/index.js:131:14
at Array.forEach (native)
at DestroyableTransform.<anonymous> (/Users/planetmalone/projekts/tims/Web/node_modules/gulp-istanbul/index.js:130:15)
at emitNone (events.js:72:20)
at DestroyableTransform.emit (events.js:166:7)
at endReadableNT (/Users/planetmalone/projekts/tims/Web/node_modules/gulp-istanbul/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:960:12)
at doNTCallback2 (node.js:441:9)
at process._tickDomainCallback (node.js:396:17)
I tracked it down to the text-summary
reporter not adding the line to the statementMap. The place it's throwing the error is this block of code in object-utils.js:
Object.keys(statements).forEach(function (st) {
var line = statementMap[st].start.line,
count = statements[st],
prevVal = lineMap[line];
if (count === 0 && statementMap[st].skip) { count = 1; }
if (typeof prevVal === 'undefined' || prevVal < count) {
lineMap[line] = count;
}
});
st
is 49 while the last index in the statementMap is 48.
Is this a known issue or is there anything I need to modify in order to allow gulp-istanbul to play nicely with gulp.watch?
I know this is code inside of istanbul, but it seems to be directly related to gulp watch.
I'm having this issue when using wildcards to specify the paths to cover. If I wrote all as absolute paths it works as expected. Here's my current configuration (quite similar to example on README):
gulp.task('test', function (cb) {
gulp.src(['src/**/*.js', 'index.js'])
.pipe(istanbul()) // Covering files
.on('finish', function () {
gulp.src(['test/**/*.js'])
.pipe(mocha())
.pipe(istanbul.writeReports());
});
});
And here's the output:
[17:18:45] Using gulpfile ~/Projects/my-project/Gulpfile.js
[17:18:45] Starting 'test'...
โฏ
And the target files tree:
Any ideas what could be wrong?
Thanks!
This module breaks many of the gulp plugin contracts and leads people to create poorly structured tasks.
Nesting a stream inside an on('finish')
is an antipattern and giant red flag that things are being done incorrectly. Why is the hookRequire method even part of a stream?
Streams should be returned from the gulp task. By nesting the stream inside the event callback, you are unable to return that stream pipeline. You can use the callback as per the example but you lose a bunch of internal stuff that gulp does, like sink the stream, etc.
Am I right in thinking that the /* istanbul ignore ... */
directive is not supported? I cannot get it to work with your plugin. Do you think it'd be easy to add? Many thanks.
Hello there,
when mocha has an error the code does not generate the coverage report (OK). but i inserted the task in a gulp.watch and every time a testcase goes wrong the process exit with:
events.js:72
throw er; // Unhandled 'error' event
^
Error: 1 test failed.
returning me the prompt. I tried with .on('error', function(err){}) but i had no luck. :(
I'd like to request keeping a harmony branch tracking the same in istanbul. As of right now, anything using ES6 syntax can't be used with this module.
As an aside, this looks like a pain point for npm in general, as you need
gulp-istanbul#harmony -> istanbul#harmony -> esprima#harmony
I've made the one-line change to package.json in my fork - but then realized I can't request a new upstream branch be created via pull-request
gulp.task('test', function (cb) {
gulp.src(['./*.js'])
.pipe(istanbul()) // Covering files
.on('finish', function () {
gulp.src(['test/*.js'])
.pipe(lab('-v -C -l -m 0'))
.pipe(istanbul.writeReports()) // Creating the reports after tests runned
.on('end', cb);
});
});
results in this:
----------|-----------|-----------|-----------|-----------|
File | % Stmts |% Branches | % Funcs | % Lines |
----------|-----------|-----------|-----------|-----------|
----------|-----------|-----------|-----------|-----------|
All files | 100 | 100 | 100 | 100 |
----------|-----------|-----------|-----------|-----------|
=============================== Coverage summary ===============================
Statements : 100% ( 0/0 )
Branches : 100% ( 0/0 )
Functions : 100% ( 0/0 )
Lines : 100% ( 0/0 )
================================================================================
The output lcov.info is an empty file.
coverage-final.json contains and empty {}
Hello,
While trying to produce a coverage report, I get the following failure and error
=============================== Coverage summary ===============================
Statements : 34.12% ( 29/85 )
Branches : 0% ( 0/10 )
Functions : 11.11% ( 2/18 )
Lines : 34.94% ( 29/83 )
events.js:72
throw er; // Unhandled 'error' event
^
Error: Coverage failed
I added a console.trace() command and here are the details:
{ [Error: Coverage failed]
message: 'Coverage failed',
showStack: false,
showProperties: true,
plugin: 'gulp-istanbul',
__safety: { toString: [Function] } }
Trace
at DestroyableTransform. (/home/ubuntu/workspace/proxy-server/gulpfile.js:42:19)
at DestroyableTransform.emit (events.js:117:20)
at DestroyableTransform. (/home/ubuntu/workspace/proxy-server/node_modules/gulp-istanbul/index.js:156:12)
at DestroyableTransform.emit (events.js:117:20)
at /home/ubuntu/workspace/proxy-server/node_modules/gulp-istanbul/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:965:16
at process._tickDomainCallback (node.js:486:13)
Can anyone suggest what I am missing here?
Code is:
gulp.task('test', function (cb) {
gulp.src(['./test/endsever.1.js','./proxy.js','./lib/saveToDB.js','./test/client.1.js'])
.pipe(istanbul()) // Covering files
.pipe(istanbul.hookRequire()) // Force require
to return covered files
.on('error', function(err) {
console.log(err);
process.exit(1);
})
.on('finish', function () {
gulp.src(['./test/endsever.1.js','./proxy.js','./lib/saveToDB.js','./test/client.1.js'])
.pipe(mocha())
.pipe(istanbul.writeReports()) // Creating the reports after tests ran
.pipe(istanbul.enforceThresholds({ thresholds: { global: 90 } })) // Enforce a coverage of at least 90%
.on('error', function(err) {
//console.log(err({showStack:true}));
console.log(err);
console.trace();
process.exit(1);
})
.on('end', cb);
Thanks in advance
This code never writes reports with [email protected]
and [email protected]
gulp.task('spec', ['lint'], function(callback) {
gulp.src(lib)
.pipe(istanbul({
includeUntested: true
}))
.pipe(istanbul.hookRequire())
.on('finish', function() {
gulp.src(test)
.pipe(mocha({
reporter: process.env.TRAVIS ? 'spec' : 'nyan'
}))
.pipe(istanbul.writeReports({
reporters: ['text', 'text-summary']
}))
.on('end', function() {
var errOrNull = null;
var coverage = istanbul.summarizeCoverage();
var incomplete = Object.keys(coverage).filter(function(key) {
return coverage[key].pct !== 100;
});
if (incomplete.length > 0) {
errOrNull = new Error(
'Incomplete coverage for ' + incomplete.join(', '));
}
callback(errOrNull);
});
});
});
I had an issue with grunt-istanbul after updating from 0.3.1 to 0.4.0. Because I have more than 16 src files in my project, I had to add a call to .resume() after the call to .on('finish', function () {...}). This seems to have been caused by the update to a newer version of through2, see this issue: rvagg/through2#32
Is this the correct way to handle this issue? If so, we should update the documentation in README.md to reflect this.
Thanks.
Would you mind if I make a PR to add threshold enforcing support?
Istanbul has this feature but unfortunately the logic is embedded within a console command which only reads from a coverage file.
I imagined it would look like this:
.pipe(mocha())
.pipe(istanbul.writeReports())
.pipe(istanbul.enforceThresholds(thresholds))
.on('end', cb);
All this would do is check the coverage against thresholds, output a short message and then create a plugin error if the coverage failed.
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.