Skip to content

Commit

Permalink
Smarter test runner.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeal committed Mar 1, 2013
1 parent 67d753f commit 337718b
Showing 1 changed file with 35 additions and 54 deletions.
89 changes: 35 additions & 54 deletions tests/run.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,40 @@
var spawn = require('child_process').spawn
, exitCode = 0
, timeout = 10000
, fs = require('fs')
;

var tests = [
'test-basic-auth.js'
, 'test-body.js'
, 'test-cookie.js'
, 'test-cookiejar.js'
, 'test-defaults.js'
, 'test-digest-auth.js'
, 'test-errors.js'
, 'test-form.js'
, 'test-follow-all-303.js'
, 'test-follow-all.js'
, 'test-headers.js'
, 'test-httpModule.js'
, 'test-https.js'
, 'test-https-strict.js'
, 'test-oauth.js'
, 'test-params.js'
, 'test-pipes.js'
, 'test-pool.js'
, 'test-protocol-changing-redirect.js'
, 'test-proxy.js'
, 'test-piped-redirect.js'
, 'test-qs.js'
, 'test-redirect.js'
, 'test-timeout.js'
, 'test-toJSON.js'
, 'test-tunnel.js'
]

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

})


0 comments on commit 337718b

Please sign in to comment.