Ensure test failures get fully outputted.

Node's console.log() is non-blocking, so I was seeing test failure output get
cut off since it was happening on process exit. No more!
This commit is contained in:
Aseem Kishore 2011-08-12 14:56:33 -07:00
parent 42f2bd926b
commit 41b8b3256d
1 changed files with 22 additions and 20 deletions

View File

@ -195,9 +195,18 @@ runTests = (CoffeeScript) ->
global.arrayEq = (a, b, msg) -> ok arrayEqual(a,b), msg
# Run every test in the `test` folder, recording failures.
files = fs.readdirSync 'test'
for file in files when file.match /\.coffee$/i
currentFile = filename = path.join 'test', file
code = fs.readFileSync filename
try
CoffeeScript.run code.toString(), {filename}
catch error
failures.push {filename, error}
# When all the tests have run, collect and print errors.
# If a stacktrace is available, output the compiled function source.
process.on 'exit', ->
time = ((Date.now() - startTime) / 1000).toFixed(2)
message = "passed #{passedTests} tests in #{time} seconds#{reset}"
return log(message, green) unless failures.length
@ -213,17 +222,10 @@ runTests = (CoffeeScript) ->
log " #{error.stack}", red
log " #{jsFilename}: line #{line ? 'unknown'}, column #{col ? 'unknown'}", red
console.log " #{error.source}" if error.source
return
# Run every test in the `test` folder, recording failures.
files = fs.readdirSync 'test'
for file in files when file.match /\.coffee$/i
currentFile = filename = path.join 'test', file
code = fs.readFileSync filename
try
CoffeeScript.run code.toString(), {filename}
catch error
failures.push {filename, error}
# ensure process waits for console.log to drain before exiting
process.stdout.on 'drain', ->
return !failures.length