This repository has been archived by the owner on Dec 5, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c1c9175
Showing
6 changed files
with
129 additions
and
0 deletions.
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,3 @@ | ||
node_modules | ||
node_modules/* | ||
npm_debug.log |
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,102 @@ | ||
//asynct.js | ||
|
||
//simple async test adapter | ||
|
||
var assert = require('assert') | ||
, ctrl = require('ctrlflow') | ||
, isSetup = /^__?setup$/ | ||
, isTeardown = /^__?teardown$/ | ||
, isSetupTeardown = /^__?(setup|teardown)$/ | ||
|
||
exports.run = run | ||
|
||
function run (tests,reporter,callback){ | ||
var status = {} | ||
var setup = [], teardown = [] | ||
var names = Object.keys(tests).filter(function (name){ | ||
if(isSetup(name)) | ||
setup.push(name) | ||
else if (isTeardown(name)) | ||
teardown.push(name) | ||
else return true | ||
}) | ||
|
||
names = setup.concat(names).concat(teardown) | ||
|
||
var tests = names.map(function (name){ | ||
var test = tests[name] | ||
status[name] = 'not started' | ||
return function (){ | ||
var __next = this.next | ||
, finishAlready = false | ||
|
||
if(!isSetupTeardown(name)) //don't report setup and teardown unless there is an error. | ||
reporter.test(name) | ||
|
||
function next (){ | ||
status[name] = 'finished' | ||
if(finishAlready) | ||
return reporter.test(name,new Error('test \'' + name + '\' called finish twice')) | ||
finishAlready = true | ||
__next() | ||
} | ||
|
||
function error(err){ | ||
reporter.test(name,err) | ||
next() | ||
} | ||
|
||
var tester = new Tester(name,next,function (err){reporter.test(name,err)}) | ||
|
||
function handle(err){ | ||
var catcher = tester.catch || tester.uncaughtExceptionHandler | ||
if('function' == typeof catcher){ | ||
try{ | ||
catcher(err) | ||
} catch (err){ | ||
error(err) | ||
} | ||
} else { | ||
error(err) | ||
} | ||
} | ||
|
||
process.removeAllListeners('uncaughtException') | ||
process.on('uncaughtException',handle) | ||
|
||
try{ | ||
status[name] = 'started' | ||
test.call(null,tester) | ||
if(isTeardown(name)) | ||
next()//teardown is sync! .. | ||
//on second thoughts this is probably not a good idea. | ||
//maybe, by hooking process.nextTick and the events you could have an | ||
//event loop drain event, so that you know when the process is about to exit. | ||
} catch (err) {handle(err)} | ||
} | ||
}) | ||
|
||
ctrl.seq(tests,function (err){throw err}).done(callback).go() | ||
|
||
return function (){ | ||
process.removeAllListeners('uncaughtException') | ||
|
||
names.forEach(function (name){ | ||
if(status[name] != 'finished') | ||
reporter.test(name, "did not finish, state was: " + status[name]) | ||
}) | ||
} | ||
|
||
} | ||
|
||
Tester.prototype = assert | ||
|
||
function Tester (name,next,handler){ | ||
this.done = next | ||
this.finish = next | ||
this.name = name | ||
this.catch = null | ||
this.failure = handler | ||
this.error = handler | ||
this.uncaughtExceptionHandler = null | ||
} |
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,7 @@ | ||
#! /usr/bin/env node | ||
|
||
var cmd = require('test-cmd') | ||
, asynct = require('./asynct') | ||
|
||
if(!module.parent) | ||
cmd.go(asynct) |
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,16 @@ | ||
{ "name": "asynct" | ||
, "version": "1.0.0" | ||
, "description": "" | ||
, "homepage": "http://github.com/dominictarr/asynct" | ||
, "repository": | ||
{ "type": "git" | ||
, "url": "https://github.com/dominictarr/asynct.git" } | ||
, "dependencies": { | ||
"ctrlflow": ">=0.0.3" | ||
, "test-cmd": "1" | ||
} | ||
, "main": "./asynct.js" | ||
, "author": "Dominic Tarr <dominic.tarr@gmail.com> (http://bit.ly/dominictarr)" | ||
, "scripts": { "test": "meta-test test/*.js" } | ||
, "bin": { "asynct": "./cmd.js" } | ||
} |
Empty file.
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 @@ | ||
{"name":"/home/dominic/source/dev/asynct","failures":[],"status":"success","filename":"/home/dominic/source/dev/asynct","os":"linux","version":"v0.4.8","meta":{},"tests":[{"name":"../map-reduce/test/errors.asynct.js","failures":[],"status":"success","filename":"../map-reduce/test/errors.asynct.js","os":"linux","version":"v0.4.8","meta":{},"tests":[{"name":"emit.error","failures":[],"status":"success"},{"name":"throw Error","failures":[],"status":"success"},{"name":"throw Error async","failures":[],"status":"success"},{"name":"dont catch in callback","failures":[],"status":"success"}]},{"name":"../map-reduce/test/map-reduce.asynct.js","failures":[],"status":"success","filename":"../map-reduce/test/map-reduce.asynct.js","os":"linux","version":"v0.4.8","meta":{},"tests":[{"name":"map","failures":[],"status":"success"},{"name":"map default to identity","failures":[],"status":"success"},{"name":"map default to identity with initial set","failures":[],"status":"success"},{"name":"reduce defaults to collect","failures":[],"status":"success"},{"name":"reduce stop early","failures":[],"status":"success"},{"name":"max","failures":[],"status":"success"},{"name":"min","failures":[],"status":"success"}]}]} |