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",
|
"name": "ig-test",
|
||||||
"version": "1.4.8",
|
"version": "1.5.0",
|
||||||
"description": "experimental test runner....",
|
"description": "experimental test runner....",
|
||||||
"main": "test.js",
|
"main": "test.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
|||||||
40
test-test.js
40
test-test.js
@ -19,27 +19,48 @@ var tests = require('./test')
|
|||||||
|
|
||||||
tests.Setup('setup',
|
tests.Setup('setup',
|
||||||
function(assert){
|
function(assert){
|
||||||
assert(true, 'setup: assert')
|
assert(true, 'setup')
|
||||||
return {} })
|
return {setup: 'setup'} })
|
||||||
|
|
||||||
tests.Setups({
|
tests.Setups({
|
||||||
setup2: function(assert){
|
setup2: function(assert){
|
||||||
assert(true, 'setup2: assert')
|
assert(true, 'setup')
|
||||||
return {} },
|
return {setup: 'setup2'} },
|
||||||
setup3: function(assert){
|
async: async function(assert){
|
||||||
assert(true, 'setup3: assert')
|
assert(true, 'setup')
|
||||||
return {} },
|
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',
|
tests.Setup('setup',
|
||||||
function(assert){
|
function(assert){
|
||||||
assert(false, 'setup (shadowed): assert')
|
assert(false, 'setup (shadowed): assert')
|
||||||
return {} })
|
return {} })
|
||||||
|
|
||||||
tests.Test('dummy',
|
tests.Test('basic',
|
||||||
function(assert, setup){
|
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...
|
// a nested test set...
|
||||||
tests.Case('nested',
|
tests.Case('nested',
|
||||||
@ -50,6 +71,7 @@ tests.Case('nested',
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
typeof(__filename) != 'undefined'
|
typeof(__filename) != 'undefined'
|
||||||
&& __filename == (require.main || {}).filename
|
&& __filename == (require.main || {}).filename
|
||||||
|
|||||||
53
test.js
53
test.js
@ -227,6 +227,16 @@ object.Constructor('Assert', {
|
|||||||
return this(arrayCmp(value, expected),
|
return this(arrayCmp(value, expected),
|
||||||
msg +':', 'expected:', expected, 'got:', value) },
|
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){
|
__init__: function(path, stats, verbose){
|
||||||
this.path = path instanceof Array ?
|
this.path = path instanceof Array ?
|
||||||
path
|
path
|
||||||
@ -575,7 +585,7 @@ module.merge =
|
|||||||
// ...if not then need to cleanup run(..) to use TestSet / BASE_TEST_SET...
|
// ...if not then need to cleanup run(..) to use TestSet / BASE_TEST_SET...
|
||||||
var runner =
|
var runner =
|
||||||
module.runner =
|
module.runner =
|
||||||
function(spec, chain, stats){
|
async function(spec, chain, stats){
|
||||||
// parse chain...
|
// parse chain...
|
||||||
chain = (chain == '*' || chain == null) ?
|
chain = (chain == '*' || chain == null) ?
|
||||||
[]
|
[]
|
||||||
@ -613,7 +623,7 @@ function(spec, chain, stats){
|
|||||||
// tests...
|
// tests...
|
||||||
var assert = Assert('[TEST]', stats, module.VERBOSE)
|
var assert = Assert('[TEST]', stats, module.VERBOSE)
|
||||||
chain_length != 1
|
chain_length != 1
|
||||||
&& object.deepKeys(tests)
|
&& await Promise.all(object.deepKeys(tests)
|
||||||
.filter(function(t, i, l){
|
.filter(function(t, i, l){
|
||||||
return typeof(tests[t]) == 'function'
|
return typeof(tests[t]) == 'function'
|
||||||
// skip blank tests if we have other tests unless
|
// skip blank tests if we have other tests unless
|
||||||
@ -624,19 +634,19 @@ function(spec, chain, stats){
|
|||||||
false
|
false
|
||||||
: (test == '*'
|
: (test == '*'
|
||||||
|| test == t) ) })
|
|| test == t) ) })
|
||||||
.forEach(function(t){
|
.map(function(t){
|
||||||
// modifiers...
|
// modifiers...
|
||||||
object.deepKeys(modifiers)
|
return object.deepKeys(modifiers)
|
||||||
.filter(function(m){
|
.filter(function(m){
|
||||||
return typeof(modifiers[m]) == 'function'
|
return typeof(modifiers[m]) == 'function'
|
||||||
&& (mod == '*' || mod == m) })
|
&& (mod == '*' || mod == m) })
|
||||||
.forEach(function(m){
|
.map(function(m){
|
||||||
// setups...
|
// setups...
|
||||||
object.deepKeys(setups)
|
return object.deepKeys(setups)
|
||||||
.filter(function(s){
|
.filter(function(s){
|
||||||
return typeof(setups[s]) == 'function'
|
return typeof(setups[s]) == 'function'
|
||||||
&& (setup == '*' || setup == s) })
|
&& (setup == '*' || setup == s) })
|
||||||
.forEach(function(s){
|
.map(async function(s){
|
||||||
// run the test...
|
// run the test...
|
||||||
stats.tests += 1
|
stats.tests += 1
|
||||||
var _assert = assert.push(
|
var _assert = assert.push(
|
||||||
@ -644,19 +654,22 @@ function(spec, chain, stats){
|
|||||||
// do not print blank pass-through ('-')
|
// do not print blank pass-through ('-')
|
||||||
// components...
|
// components...
|
||||||
.filter(function(e){ return e != '-' }) )
|
.filter(function(e){ return e != '-' }) )
|
||||||
tests[t](_assert,
|
return tests[t](
|
||||||
modifiers[m](_assert,
|
_assert,
|
||||||
setups[s](_assert))) }) }) })
|
await modifiers[m](
|
||||||
|
_assert,
|
||||||
|
await setups[s](_assert))) }) }) })
|
||||||
|
.flat(Infinity))
|
||||||
// cases...
|
// cases...
|
||||||
var assert = Assert('[CASE]', stats, module.VERBOSE)
|
var assert = Assert('[CASE]', stats, module.VERBOSE)
|
||||||
chain_length <= 1
|
chain_length <= 1
|
||||||
&& Object.keys(cases)
|
&& await Promise.all(Object.keys(cases)
|
||||||
.filter(function(s){
|
.filter(function(s){
|
||||||
return typeof(cases[s]) == 'function'
|
return typeof(cases[s]) == 'function'
|
||||||
&& (setup == '*' || setup == s) })
|
&& (setup == '*' || setup == s) })
|
||||||
.forEach(function(c){
|
.map(function(c){
|
||||||
stats.tests += 1
|
stats.tests += 1
|
||||||
cases[c]( assert.push(c) ) })
|
return cases[c]( assert.push(c) ) }))
|
||||||
// runtime...
|
// runtime...
|
||||||
stats.time += Date.now() - started
|
stats.time += Date.now() - started
|
||||||
return stats }
|
return stats }
|
||||||
@ -928,7 +941,7 @@ argv.Parser({
|
|||||||
//
|
//
|
||||||
var run =
|
var run =
|
||||||
module.run =
|
module.run =
|
||||||
function(default_files, tests){
|
async function(default_files, tests){
|
||||||
// parse args -- run(tests)...
|
// parse args -- run(tests)...
|
||||||
if(!(default_files instanceof Array
|
if(!(default_files instanceof Array
|
||||||
|| typeof(default_files) == typeof('str'))){
|
|| typeof(default_files) == typeof('str'))){
|
||||||
@ -962,13 +975,13 @@ function(default_files, tests){
|
|||||||
|
|
||||||
return p
|
return p
|
||||||
// XXX should this be generic???
|
// XXX should this be generic???
|
||||||
.then(function(chains){
|
.then(async function(chains){
|
||||||
// run the tests...
|
// run the tests...
|
||||||
chains.length > 0 ?
|
await (chains.length > 0 ?
|
||||||
chains
|
Promise.all(chains
|
||||||
.forEach(function(chain){
|
.map(function(chain){
|
||||||
runner(tests, chain, stats) })
|
return runner(tests, chain, stats) }))
|
||||||
: runner(tests, '*', stats)
|
: runner(tests, '*', stats))
|
||||||
|
|
||||||
// print stats...
|
// print stats...
|
||||||
console.log(
|
console.log(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user