gulp-mocha
Advanced tools
Comparing version 0.2.0 to 0.3.0
37
index.js
'use strict'; | ||
var path = require('path'); | ||
var through = require('through'); | ||
var Duplex = require('stream').Duplex; | ||
var gutil = require('gulp-util'); | ||
@@ -8,21 +8,36 @@ var Mocha = require('mocha'); | ||
module.exports = function (options) { | ||
var mocha = new Mocha(options); | ||
var duplex = new Duplex({objectMode: true}); | ||
var errorCount = 0; | ||
return through(function (file) { | ||
duplex._write = function (file, encoding, done) { | ||
var mocha = new Mocha(options); | ||
delete require.cache[require.resolve(path.resolve(file.path))]; | ||
mocha.addFile(file.path); | ||
this.emit('data', file); | ||
}, function () { | ||
try { | ||
mocha.run(function (errCount) { | ||
if (errCount > 0) { | ||
return this.emit('error', new Error('gulp-mocha: ' + errCount + ' ' + (errCount === 1 ? 'test' : 'tests') + ' failed.')); | ||
} | ||
this.emit('end'); | ||
duplex.push(file); | ||
errorCount += errCount; | ||
done(); | ||
}.bind(this)); | ||
} catch (err) { | ||
this.emit('error', new Error('gulp-mocha: ' + err)); | ||
this.emit('error', err); | ||
done(); | ||
} | ||
}; | ||
duplex.on('finish', function () { | ||
if (errorCount === 0) { | ||
return; | ||
} | ||
var ec = errorCount; | ||
errorCount = 0; | ||
duplex.emit('error', new gutil.PluginError('gulp-mocha', [ec, (ec === 1 ? 'test' : 'tests'), 'failed.'].join(' '))); | ||
}); | ||
duplex._read = function () {}; | ||
return duplex; | ||
}; |
{ | ||
"name": "gulp-mocha", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Run Mocha tests", | ||
@@ -37,5 +37,4 @@ "license": "MIT", | ||
"gulp-util": "~2.2.0", | ||
"through": "~2.3.0", | ||
"mocha": "~1" | ||
} | ||
} |
3200
2
34
- Removedthrough@~2.3.0
- Removedthrough@2.3.8(transitive)