Comparing version 2.1.0 to 3.0.0
3.0.0 / 2016-01-05 | ||
================== | ||
* feat: ignore coverage or not by .coverage() | ||
* feat: spawn without .end, use nextTick (break change) | ||
* feat: pass a number to .debug | ||
2.1.0 / 2015-11-17 | ||
@@ -3,0 +10,0 @@ ================== |
39
index.js
'use strict'; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var debug = require('debug')('coffee'); | ||
var findIstanbul = require('./lib/find_istanbul'); | ||
var Coffee = require('./lib/coffee'); | ||
// inject script supporting istanbul with multiple process | ||
if (process.env.running_under_istanbul) { | ||
process.env.istanbul_bin_path = findIstanbul(); | ||
require('childprocess').inject(path.join(__dirname, 'lib/inject_istanbul.js')); | ||
} | ||
process.env.istanbul_bin_path = findIstanbul(); | ||
require('childprocess').inject(path.join(__dirname, 'lib/inject_istanbul.js')); | ||
@@ -21,3 +18,2 @@ exports.Coffee = Coffee; | ||
* @param {Object} opt - fork options | ||
* - {Boolean} autoCoverage - auto set cover code when `istanbul cover` running | ||
* @return {Coffee} | ||
@@ -42,30 +38,1 @@ */ | ||
}; | ||
// where is istanbul | ||
function findIstanbul(opt) { | ||
if (/\/istanbul$/.test(process.env._)) { | ||
debug('find istanbul %s', process.env._); | ||
return process.env._; | ||
} | ||
var filepath; | ||
var entryBin = require.resolve(process.env._); | ||
var dirs = []; | ||
// $PWD | ||
dirs.push(process.cwd()); | ||
// depended by some tools | ||
dirs.push(path.join(entryBin, '..')); | ||
dirs.push(path.join(entryBin, '../..')); | ||
// specified $PWD | ||
opt && opt.cwd && dirs.push(opt.cwd); | ||
for (var i = 0, l = dirs.length; i < l; i++) { | ||
filepath = path.join(dirs[i], 'node_modules/.bin/istanbul'); | ||
debug('find istanbul %s', filepath); | ||
if (fs.existsSync(filepath)) { | ||
return filepath; | ||
} | ||
} | ||
return ''; | ||
} |
'use strict'; | ||
var util = require('util'); | ||
var EventEmitter = require('events'); | ||
var cp = require('child_process'); | ||
@@ -12,2 +14,3 @@ var assert = require('assert'); | ||
function Coffee(opt) { | ||
EventEmitter.call(this); | ||
opt || (opt = {}); | ||
@@ -20,9 +23,76 @@ assert(opt.method && opt.cmd, 'should specify method and cmd'); | ||
this.restore(); | ||
var self = this; | ||
this.on('stdout_data', function(buf) { | ||
debug('output stdout `%s`', show(buf)); | ||
self._debug_stdout && process.stdout.write(buf); | ||
self.stdout += buf; | ||
}); | ||
this.on('stderr_data', function(buf) { | ||
debug('output stderr `%s`', show(buf)); | ||
self._debug_stderr && process.stderr.write(buf); | ||
self.stderr += buf; | ||
}); | ||
this.on('error', function(err) { | ||
self.error = err; | ||
}); | ||
this.once('close', function(code) { | ||
debug('output code `%s`', show(code)); | ||
self.code = code; | ||
try { | ||
assertion(self.waitAssert.stdout, self.stdout, 'should match stdout'); | ||
assertion(self.waitAssert.stderr, self.stderr, 'should match stderr'); | ||
assertion(self.waitAssert.code, self.code, 'should match code'); | ||
self.error && assertion(self.waitAssert.error, self.error.message, 'should match error message'); | ||
} catch (err) { | ||
return done(err); | ||
} | ||
done(); | ||
}); | ||
function done(err) { | ||
self.complete = true; | ||
if (self.cb) { | ||
self.cb.call(self, err, { | ||
stdout: self.stdout, | ||
stderr: self.stderr, | ||
code: self.code, | ||
error: self.error, | ||
}); | ||
} | ||
} | ||
process.nextTick(this._run.bind(this)); | ||
} | ||
Coffee.prototype.debug = function() { | ||
this._debug = true; | ||
util.inherits(Coffee, EventEmitter); | ||
Coffee.prototype.coverage = function(isCoverage) { | ||
if (isCoverage === false) { | ||
this._isCoverage = false; | ||
} | ||
return this; | ||
}; | ||
Coffee.prototype.debug = function(level) { | ||
this._debug_stdout = false; | ||
this._debug_stderr = false; | ||
// 0 (default) -> stdout + stderr | ||
// 1 -> stdout | ||
// 2 -> stderr | ||
switch (level) { | ||
case 1: | ||
this._debug_stdout = true; | ||
break; | ||
case 2: | ||
this._debug_stderr = true; | ||
break; | ||
default: | ||
this._debug_stdout = true; | ||
this._debug_stderr = true; | ||
} | ||
return this; | ||
}; | ||
// Only accept these type below for assertion | ||
@@ -49,20 +119,17 @@ var acceptType = ['stdout', 'stderr', 'code', 'error']; | ||
Coffee.prototype.end = function(cb) { | ||
this.cb = cb; | ||
return this; | ||
}; | ||
Coffee.prototype._run = function() { | ||
this._isEndCalled = true; | ||
var self = this; | ||
process.env.coffee_inject_istanbul = this._isCoverage; | ||
debug('coffee_inject_istanbul %s', this._isCoverage); | ||
var cmd = this.proc = run(this.method, this.cmd, this.args, this.opt); | ||
cmd.stdout && | ||
cmd.stdout.on('data', function(buf) { | ||
debug('output stdout `%s`', show(buf)); | ||
self._debug && process.stdout.write(buf); | ||
self.stdout += buf; | ||
}); | ||
cmd.stdout && cmd.stdout.on('data', this.emit.bind(this, 'stdout_data')); | ||
cmd.stderr && cmd.stderr.on('data', this.emit.bind(this, 'stderr_data')); | ||
cmd.once('error', this.emit.bind(this, 'error')); | ||
cmd.once('close', this.emit.bind(this, 'close')); | ||
cmd.stderr && | ||
cmd.stderr.on('data', function(buf) { | ||
debug('output stderr `%s`', show(buf)); | ||
self._debug && process.stderr.write(buf); | ||
self.stderr += buf; | ||
}); | ||
if (this.stdin.length) { | ||
@@ -76,34 +143,3 @@ this.stdin.forEach(function(buf) { | ||
cmd.once('error', function(err) { | ||
self._debug && console.info(err); | ||
self.error = err; | ||
}); | ||
cmd.once('close', function (code) { | ||
debug('output code `%s`', show(code)); | ||
self.code = code; | ||
try { | ||
assertion(self.waitAssert.stdout, self.stdout, 'should match stdout'); | ||
assertion(self.waitAssert.stderr, self.stderr, 'should match stderr'); | ||
assertion(self.waitAssert.code, self.code, 'should match code'); | ||
self.error && assertion(self.waitAssert.error, self.error.message, 'should match error message'); | ||
} catch(err) { | ||
return done(err); | ||
} | ||
done(); | ||
}); | ||
return this; | ||
function done(err) { | ||
self.complete = true; | ||
if (cb) { | ||
cb.call(self, err, { | ||
stdout: self.stdout, | ||
stderr: self.stderr, | ||
code: self.code, | ||
error: self.error, | ||
}); | ||
} | ||
} | ||
}; | ||
@@ -126,7 +162,9 @@ | ||
code: [], | ||
error: [] | ||
error: [], | ||
}; | ||
this.complete = false; | ||
this._isEndCalled = false; | ||
this._debug = false; | ||
this._debug_stdout = false; | ||
this._debug_stderr = false; | ||
this._isCoverage = true; | ||
return this; | ||
@@ -133,0 +171,0 @@ }; |
'use strict'; | ||
module.exports = function(modulePath, args, opt) { | ||
if (process.env.coffee_inject_istanbul === 'false') { | ||
return [modulePath, args, opt]; | ||
} | ||
if (!process.env.istanbul_bin_path) { | ||
@@ -5,0 +8,0 @@ console.warn('istanbul bin is not found'); |
{ | ||
"name": "coffee", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"description": "Test command line on nodejs", | ||
@@ -14,5 +14,6 @@ "main": "index.js", | ||
"istanbul": "0", | ||
"mm": "~1.3.5", | ||
"mm": "^1.3.5", | ||
"mocha": "2", | ||
"should": "6" | ||
"should": "6", | ||
"spy": "^0.1.3" | ||
}, | ||
@@ -19,0 +20,0 @@ "repository": { |
@@ -109,6 +109,16 @@ # Coffee | ||
#### coffee.debug() | ||
#### coffee.debug(level) | ||
Write data to process.stdout and process.stderr for debug | ||
`level` can be | ||
- 0 (default): pipe stdout + stderr | ||
- 1: pipe stdout | ||
- 2: pipe stderr | ||
#### coffee.coverage() | ||
If you set false, coffee will not generate coverage.json, default: true. | ||
## LISENCE | ||
@@ -115,0 +125,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
13314
9
272
129
7