From 0a03e904474d6323356b4fc0178383bb3e17841d Mon Sep 17 00:00:00 2001 From: Denis Gladkikh Date: Sun, 12 Jan 2014 08:50:42 -0800 Subject: [PATCH] Change the way how tests fail on stderr output. Wait whole message from stderr output and only after that throw error. This helps to get whole picture why test fails. --- test/tap/prepublish.js | 11 ++++++++--- test/tap/startstop.js | 6 +++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/test/tap/prepublish.js b/test/tap/prepublish.js index 355ce1a2..f80085d9 100644 --- a/test/tap/prepublish.js +++ b/test/tap/prepublish.js @@ -58,16 +58,21 @@ test('test', function (t) { env: env }) child.stdout.setEncoding('utf8') - child.stderr.on('data', function(chunk) { - throw new Error('got stderr data: ' + JSON.stringify('' + chunk)) - }) + child.stderr.on('data', onerr) child.stdout.on('data', ondata) child.on('close', onend) var c = '' + , e = '' function ondata (chunk) { c += chunk } + function onerr (chunk) { + e += chunk + } function onend () { + if (e) { + throw new Error('got stderr data: ' + JSON.stringify('' + e)) + } c = c.trim() var regex = new RegExp("" + "> npm-test-prepublish@1.2.5 prepublish [^\\r\\n]+\\r?\\n" + diff --git a/test/tap/startstop.js b/test/tap/startstop.js index f94f3b02..d5a0026c 100644 --- a/test/tap/startstop.js +++ b/test/tap/startstop.js @@ -12,13 +12,14 @@ var common = require('../common-tap') function run (command, t, parse) { var c = '' + , e = '' , node = process.execPath , child = spawn(node, [npm, command], { cwd: pkg }) child.stderr.on('data', function (chunk) { - throw new Error('npm ' + command + ' stderr: ' + chunk.toString()) + e += chunk }) child.stdout.on('data', function (chunk) { @@ -26,6 +27,9 @@ function run (command, t, parse) { }) child.stdout.on('end', function () { + if (e) { + throw new Error('npm ' + command + ' stderr: ' + e.toString()) + } if (parse) { // custom parsing function c = parse(c)