forked from brunch/brunch
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request brunch#176 from kompiro/mocha_support
add Cakefile to launch test command
- Loading branch information
Showing
2 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
{spawn} = require 'child_process' | ||
fs = require 'fs' | ||
path = require 'path' | ||
{log,error} = require 'util' | ||
|
||
MODEL_TEST_PATH = 'test/unit/models' | ||
COLLECTION_TEST_PATH = 'test/unit/collections' | ||
VIEW_TEST_PATH = 'test/unit/views' | ||
ROUTE_TEST_PATH = 'test/unit/routes' | ||
|
||
TEST_PATHS = [ | ||
MODEL_TEST_PATH, | ||
COLLECTION_TEST_PATH, | ||
VIEW_TEST_PATH, | ||
ROUTE_TEST_PATH | ||
] | ||
|
||
TEST_COMMAND="#{__dirname}/node_modules/.bin/mocha" | ||
TEST_OPTIONS='-r should --growl --reporter spec' | ||
|
||
task 'test', (options)-> | ||
{EventEmitter} = require 'events' | ||
emitter = new EventEmitter | ||
emitter.once 'expanded',(paths)-> | ||
runMocha paths | ||
target = "" | ||
pathEmitter = new EventEmitter | ||
count = 0 | ||
pathEmitter.on 'finished',(paths)-> | ||
count += 1 | ||
emitter.emit 'expanded',paths if TEST_PATHS.length is count | ||
TEST_PATHS.forEach (testPath)-> | ||
expansionPath testPath,(result)-> | ||
target += result | ||
pathEmitter.emit 'finished',target | ||
|
||
task 'test_models', (options)-> | ||
expansionPath MODEL_TEST_PATH,(target)-> | ||
runMocha target | ||
|
||
task 'test_collections', (options)-> | ||
expansionPath COLLECTION_TEST_PATH,(target)-> | ||
runMocha target | ||
|
||
task 'test_views', (options)-> | ||
expansionPath VIEW_TEST_PATH,(target)-> | ||
runMocha target | ||
|
||
task 'test_routes', (options)-> | ||
expansionPath ROUTE_TEST_PATH,(target)-> | ||
runMocha target | ||
|
||
runMocha = (target)-> | ||
log 'start test' | ||
args = "#{TEST_OPTIONS} #{target}".trimRight().split(' ') | ||
spawn "#{TEST_COMMAND}",args,customFds : [0, 1, 2] | ||
|
||
expansionPath = (target,callback)-> | ||
expansion = "" | ||
fs.readdir target,(err,files)-> | ||
if !files | ||
error "Files aren't found. path:'#{target}'" | ||
return | ||
files = files.map (file)-> | ||
return path.join(target,file) | ||
files.forEach (file)-> | ||
expansion += file + ' ' | ||
callback expansion | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
"brunch-extensions": "0.1.0" | ||
}, | ||
"devDependencies": { | ||
|
||
"mocha": "0.9.0", | ||
"should": "0.5.0" | ||
} | ||
} |