alltheversions
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -5,13 +5,52 @@ "use strict"; | ||
var exec = require("child_process").exec; | ||
var spawn = require("child_process").spawn; | ||
var Timeout = _interopRequire(require("./timeout")); | ||
var Promise = _interopRequire(require("bluebird")); | ||
module.exports = function (command) { | ||
return new Promise(function (resolve, reject) { | ||
exec(command, function (err, res) { | ||
var data = res && res.toString("utf8") || ""; | ||
err ? reject(data) : resolve(data); | ||
var Concat = _interopRequire(require("./concat")); | ||
// | ||
// Spawn a process | ||
// | ||
module.exports = function (command, ttl) { | ||
// This is kind of a bad hack...but needed to watch streams | ||
var proc = spawn("/bin/sh", ["-c", command]); | ||
// Create promise to track process completion | ||
var p = new Promise(function (resolve, reject) { | ||
// If a ttl was supplied, create a timeout rejector | ||
var t = ttl && new Timeout(ttl, function () { | ||
proc.kill(); | ||
reject("Timeout"); | ||
}); | ||
// Concatenate the stdout stream into a promise | ||
// NOTE: This includes a chunk handler to tap the timeout | ||
var stdout = Concat(proc.stdout, t && t.tap.bind(t)); | ||
// Reject on errors | ||
proc.on("error", reject); | ||
// Stop timeout and resolve/reject by exit code | ||
proc.on("close", function (code) { | ||
stdout.then(function (res) { | ||
if (t) t.stop(); | ||
if (code) { | ||
reject(res); | ||
} else { | ||
resolve(res); | ||
} | ||
}); | ||
}); | ||
}); | ||
// Attach stdout and stderr streams to promise | ||
p.stdout = proc.stdout; | ||
p.stderr = proc.stderr; | ||
return p; | ||
}; |
@@ -22,21 +22,48 @@ "use strict"; | ||
var Module = (function () { | ||
function Module(mod, version, emitter) { | ||
// | ||
// Construct a module instance | ||
// | ||
function Module(mod, version, reporter) { | ||
_classCallCheck(this, Module); | ||
this.emitter = emitter; | ||
this.reporter = reporter; | ||
this.version = version; | ||
this.name = mod.name; | ||
this.task = mod.task || "npm test"; | ||
this.timeout = mod.timeout || 1000 * 10; | ||
} | ||
_createClass(Module, { | ||
emit: { | ||
// | ||
// Only emits when there's a reporter | ||
// | ||
value: function emit() { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
if (this.reporter) { | ||
var _reporter; | ||
(_reporter = this.reporter).emit.apply(_reporter, args); | ||
} | ||
} | ||
}, | ||
uninstall: { | ||
// | ||
// Uninstall the module, if it exists already | ||
// | ||
value: function uninstall() { | ||
var _this = this; | ||
this.emit("before-uninstall", this); | ||
return rimraf("node_modules/" + this.name).then(function (res) { | ||
if (_this.emitter) { | ||
_this.emitter.emit("uninstall", _this, res); | ||
} | ||
_this.emit("after-uninstall", _this, res); | ||
return _this; | ||
@@ -49,10 +76,14 @@ }, function () { | ||
install: { | ||
// | ||
// Install the appropriate version of this module | ||
// | ||
value: function install() { | ||
var _this = this; | ||
return exec("npm install " + this.name + "@" + this.version).then(function (res) { | ||
if (_this.emitter) { | ||
_this.emitter.emit("install", _this, res); | ||
} | ||
var p = exec("npm install " + this.name + "@" + this.version); | ||
this.emit("before-install", this, p); | ||
return p.then(function (res) { | ||
_this.emit("after-install", _this, res); | ||
return _this; | ||
@@ -65,13 +96,16 @@ }, function () { | ||
test: { | ||
// | ||
// Run the test task | ||
// | ||
value: function test() { | ||
var _this = this; | ||
return exec(this.task).then(function (res) { | ||
var p = exec(this.task, this.timeout); | ||
this.emit("test", this, p); | ||
return p.then(function (res) { | ||
_this.passed = true; | ||
_this.result = res; | ||
if (_this.emitter) { | ||
_this.emitter.emit("pass", _this, res); | ||
} | ||
_this.emit("pass", _this, res); | ||
return _this; | ||
@@ -81,7 +115,3 @@ }, function (res) { | ||
_this.result = res; | ||
if (_this.emitter) { | ||
_this.emitter.emit("fail", _this, res); | ||
} | ||
_this.emit("fail", _this, res); | ||
return _this; | ||
@@ -92,2 +122,7 @@ }); | ||
testWithInstall: { | ||
// | ||
// Serially run the uninstall -> install -> test flow | ||
// | ||
value: function testWithInstall() { | ||
@@ -105,2 +140,7 @@ var _this = this; | ||
matchingSpec: { | ||
// | ||
// Find all versions matching a module spec | ||
// | ||
value: function matchingSpec(mod, emitter) { | ||
@@ -123,2 +163,7 @@ return exec("npm view " + mod.name + " versions").then(function (res) { | ||
testWithVersions: { | ||
// | ||
// Test against all versions matching a module spec | ||
// | ||
value: function testWithVersions(mod, emitter) { | ||
@@ -133,2 +178,7 @@ return Module.matchingSpec(mod, emitter).then(function (versions) { | ||
testAllWithVersions: { | ||
// | ||
// Test against a list a list of many module specs | ||
// | ||
value: function testAllWithVersions(mods, emitter) { | ||
@@ -135,0 +185,0 @@ return series(mods, function (mod) { |
@@ -9,7 +9,10 @@ "use strict"; | ||
var through2 = _interopRequire(require("through2")); | ||
module.exports = function (options) { | ||
var ev = new EventEmitter(); | ||
var currentModule = ""; | ||
var currentModule = undefined; | ||
var spin = undefined; | ||
function checkModule(mod) { | ||
ev.on("before-install", function (mod, p) { | ||
if (mod.name !== currentModule) { | ||
@@ -19,23 +22,68 @@ currentModule = mod.name; | ||
} | ||
} | ||
function extra(out) { | ||
if (options.verbose) { | ||
console.log("\n" + indent(out, " ", 4) + "\n"); | ||
console.log(" " + mod.version); | ||
return; | ||
} | ||
} | ||
ev.on("pass", function (mod, out) { | ||
checkModule(mod); | ||
console.log(" \u001b[32m✓\u001b[0m " + mod.version); | ||
extra(out); | ||
spin = spinner(15, function (c) { | ||
process.stdout.clearLine(); | ||
process.stdout.cursorTo(0); | ||
process.stdout.write(" " + c + " " + mod.version); | ||
}); | ||
}); | ||
ev.on("fail", function (mod, out) { | ||
checkModule(mod); | ||
console.log(" \u001b[31m✖\u001b[0m " + mod.version); | ||
extra(out); | ||
ev.on("test", function (mod, p) { | ||
if (options.verbose) { | ||
p.stdout.pipe(indentStream(4)).pipe(process.stdout); | ||
p.stderr.pipe(indentStream(4)).pipe(process.stderr); | ||
} | ||
}); | ||
function resultHandler(mark, msg) { | ||
return function (mod) { | ||
if (options.verbose) { | ||
console.log("\n " + mark + " " + msg + "\n"); | ||
} else { | ||
spin.stop(); | ||
process.stdout.clearLine(); | ||
process.stdout.cursorTo(0); | ||
console.log(" " + mark + " " + mod.version); | ||
} | ||
}; | ||
} | ||
ev.on("pass", resultHandler("\u001b[32m✓\u001b[0m", "passed")); | ||
ev.on("fail", resultHandler("\u001b[31m✖\u001b[0m", "failed")); | ||
return ev; | ||
}; | ||
}; | ||
// | ||
// Helpers | ||
// | ||
function indentStream(n) { | ||
return through2(function (chunk, enc, callback) { | ||
var s = indent(chunk.toString("utf8"), " ", n); | ||
var b = new Buffer(s); | ||
this.push(b); | ||
callback(); | ||
}); | ||
} | ||
var chars = "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏"; | ||
var len = chars.length; | ||
function spinner(fps, fn) { | ||
var frame = 0; | ||
var t = setInterval(function () { | ||
fn(chars[frame++ % len]); | ||
}, 1000 / fps); | ||
return { | ||
stop: function stop() { | ||
clearInterval(t); | ||
} | ||
}; | ||
} |
var gulp = require('gulp') | ||
var babel = require('gulp-babel') | ||
var mocha = require('gulp-mocha') | ||
require('should') | ||
var ATV = require('./dist') | ||
var spec = require('./dist/reporters/spec') | ||
gulp.task('test', function () { | ||
gulp.task('test', ['build'], function () { | ||
require('should') | ||
return gulp.src('test/**/*.js', { read: false }) | ||
@@ -18,2 +15,4 @@ .pipe(mocha({ | ||
gulp.task('versions', function (cb) { | ||
var ATV = require('./dist') | ||
var spec = require('./dist/reporters/spec') | ||
ATV.testWithVersions({ | ||
@@ -20,0 +19,0 @@ name: 'bluebird', |
{ | ||
"name": "alltheversions", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Run your tests against ALL THE VERSIONS!", | ||
@@ -20,5 +20,5 @@ "author": "Stephen Belanger <admin@stephenbelanger.com>", | ||
"minimist": "~1.1.1", | ||
"promised-exec": "~1.0.1", | ||
"rimraf-promise": "~1.0.0", | ||
"semver": "~4.3.1" | ||
"semver": "~4.3.1", | ||
"through2": "~0.6.3" | ||
}, | ||
@@ -29,5 +29,4 @@ "devDependencies": { | ||
"gulp-mocha": "~2.0.0", | ||
"mocha": "~2.2.1", | ||
"should": "~5.2.0" | ||
} | ||
} |
15757
4
12
468
+ Addedthrough2@~0.6.3
+ Addedcore-util-is@1.0.3(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedreadable-stream@1.0.34(transitive)
+ Addedstring_decoder@0.10.31(transitive)
+ Addedthrough2@0.6.5(transitive)
+ Addedxtend@4.0.2(transitive)
- Removedpromised-exec@~1.0.1
- Removedpromised-exec@1.0.1(transitive)
- Removedq@1.5.1(transitive)