From 6033e9c2e094e82fdf94b8a601f0599109cf2d73 Mon Sep 17 00:00:00 2001 From: James Talmage Date: Tue, 29 Dec 2015 03:29:02 -0500 Subject: [PATCH] Hide annoying error print outs. Fixes #339 --- lib/fork.js | 3 ++- package.json | 1 + test/cli.js | 34 ++++++++++++++++++++++++++++++---- test/fork.js | 2 +- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/lib/fork.js b/lib/fork.js index 79728f10a..666010865 100644 --- a/lib/fork.js +++ b/lib/fork.js @@ -12,7 +12,8 @@ module.exports = function (file, opts) { var ps = childProcess.fork(path.join(__dirname, 'test-worker.js'), [JSON.stringify(opts)], { cwd: path.dirname(file), - stdio: ['ignore', process.stderr, process.stderr] + stdio: ['ignore', process.stderr, process.stderr], + silent: opts.silent }); var relFile = path.relative('.', file); diff --git a/package.json b/package.json index 92a83ff1a..be949a8ce 100644 --- a/package.json +++ b/package.json @@ -123,6 +123,7 @@ "devDependencies": { "coveralls": "^2.11.4", "delay": "^1.3.0", + "get-stream": "^1.1.0", "signal-exit": "^2.1.2", "sinon": "^1.17.2", "source-map-fixtures": "^0.4.0", diff --git a/test/cli.js b/test/cli.js index a54e0737f..fbaa3b073 100644 --- a/test/cli.js +++ b/test/cli.js @@ -1,6 +1,8 @@ 'use strict'; var childProcess = require('child_process'); var test = require('tap').test; +global.Promise = require('bluebird'); +var getStream = require('get-stream'); function execCli(args, cb) { if (!Array.isArray(args)) { @@ -13,10 +15,34 @@ function execCli(args, cb) { env.AVA_APPVEYOR = 1; } - childProcess.execFile(process.execPath, ['../cli.js'].concat(args), { - cwd: __dirname, - env: env - }, cb); + var stdout; + var stderr; + + var processPromise = new Promise(function (resolve) { + var child = childProcess.spawn(process.execPath, ['../cli.js'].concat(args), { + cwd: __dirname, + env: env, + stdio: [null, 'pipe', 'pipe'] + }); + + child.on('close', function (code, signal) { + if (code) { + var err = new Error('test-worker exited with a non-zero exit code: ' + code); + err.code = code; + err.signal = signal; + resolve(err); + return; + } + resolve(code); + }); + + stdout = getStream(child.stdout); + stderr = getStream(child.stderr); + }); + + Promise.all([processPromise, stdout, stderr]).then(function (args) { + cb.apply(null, args); + }); } test('throwing a named function will report the to the console', function (t) { diff --git a/test/fork.js b/test/fork.js index 788f5db05..7fb142852 100644 --- a/test/fork.js +++ b/test/fork.js @@ -36,7 +36,7 @@ test('resolves promise with tests info', function (t) { test('rejects on error and streams output', function (t) { t.plan(2); - fork(fixture('broken.js')) + fork(fixture('broken.js'), {silent: true}) .run() .catch(function (err) { t.ok(err);