mirror of
https://github.com/zhigang1992/npm.git
synced 2026-06-13 17:35:58 +08:00
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:
committed by
Domenic Denicola
parent
c8c3ebefd0
commit
0a03e90447
@@ -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" +
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user