Closed adam-lynch closed 10 years ago
If you use the gather
task rather than the report
task, then it will pipe JSON and not output anything to any other destination. I am planning to create a new format
task that will convert the JSON into another output format (e.g. HTML). WDYT?
Thanks. Sounds good. Especially since they're different steps; I may want the JSON & HTML :)
Ugh. Still having problems here. I'm trying to add this to gulp-bless and I'm gettingNaN
for the stats.
My gulpfile.js
:
var gulp = require('gulp');
var mocha = require('gulp-mocha');
var coverage = require('gulp-coverage');
var through2 = require('through2');
gulp.task('default', function(){
gulp.src('./test/*.js')
.pipe(coverage.instrument({
pattern: ['./test/*.js'] // tried *, **, *.js, **/*.js here
}))
.pipe(mocha())
.pipe(coverage.gather())
.pipe(through2.obj(function(data, enc, cb){
console.log(data);
}));
});
Getting this:
{ coverage:
{ files: [],
sloc: 0,
ssoc: 0,
sboc: 0,
coverage: NaN,
statements: NaN,
blocks: NaN } }
Any ideas what's wrong?
Woops that was stupid. I was passing the tests as the source. Still no luck with this though:
gulp.src('./index.js')
.pipe(coverage.instrument({
pattern: ['./test/main.js'],
debugDirectory: 'debug'
}))
.pipe(mocha())
.pipe(coverage.gather())
.pipe(through2.obj(function(data, enc, cb){
console.log(data);
}));
Nothing is written to debug
either.
@adam-lynch take a look at the new "format" task and let me know if you think it meets your requirements.
BTW - I was not able to find a gulp-dest plugin so I made up my own format for the stream object. If you know of some work somewhere I could build-on, please let me know.
It sounds alright to me, but even without format
I would've thought it would work for me. I am getting the data (as JSON), the problem is just that it seems not to be gathered correctly since it's all empty / NaN
.
The tests are hard to follow for me. If you had a very simple example to try out, like with one source and one test file, then that would help a lot.
BTW - I was not able to find a gulp-dest plugin so I made up my own format for the stream object. If you know of some work somewhere I could build-on, please let me know.
I have no idea what you mean. If you mean in your tests then maybe the gulp-concat tests would help. I'm not sure.
I just took a smaller example.
If my gruntfile is this:
gulp.src('./test/main.js')
.pipe(mocha());
I get:
1 passing
gulp.src('./index.js')
.pipe(coverage.instrument({
pattern: ['./test/main.js'],
debugDirectory: 'debug'
}))
.pipe(mocha())
.pipe(coverage.gather());
I get:
0 Passing
I don't think I have special requirements, it just doesn't seem to work for me :/. Please tell me if I'm wrong or give me a minimal example.
If you have 0.0.17, then you should be able to do this:
gulp.src('./test/main.js')
.pipe(coverage.instrument({
pattern: ['index.js'],
debugDirectory: 'debug'
}))
.pipe(mocha())
.pipe(coverage.gather());
The principle here is that you are piping your test files through the stream, but instrumenting your target files. So the glob needs to match the files that are to be instrumented, whereas the .src needs to list the tests to be run.
I am going to publish the changes for format
as 0.0.18
It's now reporting the correct pass/fail count but I'm still getting this JSON:
{ coverage:
{ files: [],
sloc: 0,
ssoc: 0,
sboc: 0,
coverage: NaN,
statements: NaN,
blocks: NaN } }
From this Gulpfile:
gulp.src('./test/main.js')
.pipe(coverage.instrument({
pattern: ['./index.js'],
debugDirectory: 'debug'
}))
.pipe(mocha())
.pipe(coverage.gather())
.pipe(through2.obj(function(data, enc, cb){
console.log(data);
}));
I'm going to reopen this issue.
change the ./index to "index.js"
Ok, it's working. Thanks.
./index.js
to Gulp plugins.yeah, I am going to see whether the programmer responsible for the glob library I am using will make the match work for that...
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 tocoverage.html
before I usegulp.dest
to store it somewhere else. Or if I wanted to getgulp-coverage
to return JSON and pipe that into something that'll fail the build if the test coverage is too low.