mirror of
https://github.com/flynx/test.js.git
synced 2025-10-28 18:30:08 +00:00
added async support + a bit better assert logging...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
73a90a02da
commit
6c69c6a79e
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ig-test",
|
||||
"version": "1.4.8",
|
||||
"version": "1.5.0",
|
||||
"description": "experimental test runner....",
|
||||
"main": "test.js",
|
||||
"bin": {
|
||||
|
||||
40
test-test.js
40
test-test.js
@ -19,27 +19,48 @@ var tests = require('./test')
|
||||
|
||||
tests.Setup('setup',
|
||||
function(assert){
|
||||
assert(true, 'setup: assert')
|
||||
return {} })
|
||||
assert(true, 'setup')
|
||||
return {setup: 'setup'} })
|
||||
|
||||
tests.Setups({
|
||||
setup2: function(assert){
|
||||
assert(true, 'setup2: assert')
|
||||
return {} },
|
||||
setup3: function(assert){
|
||||
assert(true, 'setup3: assert')
|
||||
return {} },
|
||||
assert(true, 'setup')
|
||||
return {setup: 'setup2'} },
|
||||
async: async function(assert){
|
||||
assert(true, 'setup')
|
||||
return {setup: 'async'} },
|
||||
})
|
||||
|
||||
|
||||
tests.Modifiers({
|
||||
sync: function(assert, setup){
|
||||
assert(setup, 'modifier')
|
||||
setup.mod = 'sync'
|
||||
return setup },
|
||||
async: async function(assert, setup){
|
||||
assert(setup, 'modifier')
|
||||
setup.mod = 'async'
|
||||
return setup },
|
||||
})
|
||||
|
||||
|
||||
tests.Setup('setup',
|
||||
function(assert){
|
||||
assert(false, 'setup (shadowed): assert')
|
||||
return {} })
|
||||
|
||||
tests.Test('dummy',
|
||||
tests.Test('basic',
|
||||
function(assert, setup){
|
||||
assert(true, 'dummy: assert') })
|
||||
assert(setup, 'test')
|
||||
assert.log(setup)
|
||||
})
|
||||
|
||||
tests.Tests({
|
||||
async: async function(assert, setup){
|
||||
assert(setup, 'test')
|
||||
assert.log(setup)
|
||||
},
|
||||
})
|
||||
|
||||
// a nested test set...
|
||||
tests.Case('nested',
|
||||
@ -50,6 +71,7 @@ tests.Case('nested',
|
||||
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
typeof(__filename) != 'undefined'
|
||||
&& __filename == (require.main || {}).filename
|
||||
|
||||
53
test.js
53
test.js
@ -227,6 +227,16 @@ object.Constructor('Assert', {
|
||||
return this(arrayCmp(value, expected),
|
||||
msg +':', 'expected:', expected, 'got:', value) },
|
||||
|
||||
// output...
|
||||
log: function(...args){
|
||||
this.verbose
|
||||
&& console.log('\t', ...args) },
|
||||
warn: function(...args){
|
||||
this.verbose
|
||||
&& console.warn('\t', ...args) },
|
||||
error: function(...args){
|
||||
console.error('\t', ...args) },
|
||||
|
||||
__init__: function(path, stats, verbose){
|
||||
this.path = path instanceof Array ?
|
||||
path
|
||||
@ -575,7 +585,7 @@ module.merge =
|
||||
// ...if not then need to cleanup run(..) to use TestSet / BASE_TEST_SET...
|
||||
var runner =
|
||||
module.runner =
|
||||
function(spec, chain, stats){
|
||||
async function(spec, chain, stats){
|
||||
// parse chain...
|
||||
chain = (chain == '*' || chain == null) ?
|
||||
[]
|
||||
@ -613,7 +623,7 @@ function(spec, chain, stats){
|
||||
// tests...
|
||||
var assert = Assert('[TEST]', stats, module.VERBOSE)
|
||||
chain_length != 1
|
||||
&& object.deepKeys(tests)
|
||||
&& await Promise.all(object.deepKeys(tests)
|
||||
.filter(function(t, i, l){
|
||||
return typeof(tests[t]) == 'function'
|
||||
// skip blank tests if we have other tests unless
|
||||
@ -624,19 +634,19 @@ function(spec, chain, stats){
|
||||
false
|
||||
: (test == '*'
|
||||
|| test == t) ) })
|
||||
.forEach(function(t){
|
||||
.map(function(t){
|
||||
// modifiers...
|
||||
object.deepKeys(modifiers)
|
||||
return object.deepKeys(modifiers)
|
||||
.filter(function(m){
|
||||
return typeof(modifiers[m]) == 'function'
|
||||
&& (mod == '*' || mod == m) })
|
||||
.forEach(function(m){
|
||||
.map(function(m){
|
||||
// setups...
|
||||
object.deepKeys(setups)
|
||||
return object.deepKeys(setups)
|
||||
.filter(function(s){
|
||||
return typeof(setups[s]) == 'function'
|
||||
&& (setup == '*' || setup == s) })
|
||||
.forEach(function(s){
|
||||
.map(async function(s){
|
||||
// run the test...
|
||||
stats.tests += 1
|
||||
var _assert = assert.push(
|
||||
@ -644,19 +654,22 @@ function(spec, chain, stats){
|
||||
// do not print blank pass-through ('-')
|
||||
// components...
|
||||
.filter(function(e){ return e != '-' }) )
|
||||
tests[t](_assert,
|
||||
modifiers[m](_assert,
|
||||
setups[s](_assert))) }) }) })
|
||||
return tests[t](
|
||||
_assert,
|
||||
await modifiers[m](
|
||||
_assert,
|
||||
await setups[s](_assert))) }) }) })
|
||||
.flat(Infinity))
|
||||
// cases...
|
||||
var assert = Assert('[CASE]', stats, module.VERBOSE)
|
||||
chain_length <= 1
|
||||
&& Object.keys(cases)
|
||||
&& await Promise.all(Object.keys(cases)
|
||||
.filter(function(s){
|
||||
return typeof(cases[s]) == 'function'
|
||||
&& (setup == '*' || setup == s) })
|
||||
.forEach(function(c){
|
||||
.map(function(c){
|
||||
stats.tests += 1
|
||||
cases[c]( assert.push(c) ) })
|
||||
return cases[c]( assert.push(c) ) }))
|
||||
// runtime...
|
||||
stats.time += Date.now() - started
|
||||
return stats }
|
||||
@ -928,7 +941,7 @@ argv.Parser({
|
||||
//
|
||||
var run =
|
||||
module.run =
|
||||
function(default_files, tests){
|
||||
async function(default_files, tests){
|
||||
// parse args -- run(tests)...
|
||||
if(!(default_files instanceof Array
|
||||
|| typeof(default_files) == typeof('str'))){
|
||||
@ -962,13 +975,13 @@ function(default_files, tests){
|
||||
|
||||
return p
|
||||
// XXX should this be generic???
|
||||
.then(function(chains){
|
||||
.then(async function(chains){
|
||||
// run the tests...
|
||||
chains.length > 0 ?
|
||||
chains
|
||||
.forEach(function(chain){
|
||||
runner(tests, chain, stats) })
|
||||
: runner(tests, '*', stats)
|
||||
await (chains.length > 0 ?
|
||||
Promise.all(chains
|
||||
.map(function(chain){
|
||||
return runner(tests, chain, stats) }))
|
||||
: runner(tests, '*', stats))
|
||||
|
||||
// print stats...
|
||||
console.log(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user