node/deps/npm/node_modules/request/tests/run.js

41 lines
880 B
JavaScript
Raw Normal View History

2012-07-14 02:40:38 +08:00
var spawn = require('child_process').spawn
, exitCode = 0
2013-04-12 00:16:47 +08:00
, timeout = 10000
, fs = require('fs')
2012-07-14 02:40:38 +08:00
;
2013-04-12 00:16:47 +08:00
fs.readdir(__dirname, function (e, files) {
if (e) throw e
var tests = files.filter(function (f) {return f.slice(0, 'test-'.length) === 'test-'})
var next = function () {
if (tests.length === 0) process.exit(exitCode);
var file = tests.shift()
console.log(file)
var proc = spawn('node', [ 'tests/' + file ])
var killed = false
var t = setTimeout(function () {
proc.kill()
exitCode += 1
console.error(file + ' timeout')
killed = true
}, timeout)
proc.stdout.pipe(process.stdout)
proc.stderr.pipe(process.stderr)
proc.on('exit', function (code) {
if (code && !killed) console.error(file + ' failed')
exitCode += code || 0
clearTimeout(t)
next()
})
}
next()
})