65 lines
1.8 KiB
CoffeeScript
Executable File
65 lines
1.8 KiB
CoffeeScript
Executable File
fs = require 'fs'
|
|
{print} = require 'util'
|
|
{spawn, exec} = require 'child_process'
|
|
glob = require 'glob'
|
|
|
|
REPORTER = "min"
|
|
|
|
config = {}
|
|
config.binPath = './node_modules/.bin/'
|
|
|
|
# cake test # run all tests
|
|
# cake -f test/lib/file.coffee test # run the files passed
|
|
# cake -b test # run all tests and stop at first failure
|
|
option '-f', '--file [FILE*]', 'input file(s)'
|
|
option '-b', '--bail', 'bail'
|
|
task 'test', 'Run the test suite', (options) ->
|
|
process.env.NODE_ENV = "test"
|
|
testFiles = [
|
|
|
|
]
|
|
testOpts = [
|
|
'--require', 'coffee-script/register',
|
|
'--compilers', 'coffee:coffee-script/register',
|
|
'--require', 'should',
|
|
'--colors',
|
|
'--ignore-leaks',
|
|
'--timeout', '15000',
|
|
'--reporter', 'spec'
|
|
]
|
|
if options.bail? and options.bail
|
|
testOpts = testOpts.concat('-b')
|
|
|
|
if options.file?
|
|
if _.isArray(options.file)
|
|
files = testFiles.concat(options.file)
|
|
else
|
|
files = testFiles.concat([options.file])
|
|
for opt in testOpts.reverse()
|
|
files.unshift opt
|
|
run 'mocha', files
|
|
|
|
else
|
|
glob 'test/**/*.coffee', (error, files) ->
|
|
for opt in testOpts.reverse()
|
|
files.unshift opt
|
|
run 'mocha', files
|
|
|
|
# Internal methods
|
|
|
|
# Spawns an application with `options` and calls `onExit`
|
|
# when it finishes.
|
|
run = (bin, options, onExit) ->
|
|
bin = config.binPath + bin
|
|
console.log timeNow() + ' - running: ' + bin + ' ' + (if options? then options.join(' ') else "")
|
|
cmd = spawn bin, options
|
|
cmd.stdout.on 'data', (data) -> print data.toString()
|
|
cmd.stderr.on 'data', (data) -> print data.toString()
|
|
cmd.on 'exit', (code) ->
|
|
console.log 'done.'
|
|
onExit?(code, options)
|
|
|
|
# Returns a string with the current time to print out.
|
|
timeNow = ->
|
|
today = new Date()
|
|
today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds() |