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.
This commit is contained in:
Denis Gladkikh
2014-01-12 08:50:42 -08:00
committed by Domenic Denicola
parent c8c3ebefd0
commit 0a03e90447
2 changed files with 13 additions and 4 deletions

View File

@@ -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" +

View File

@@ -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)