bugfix -- now seems to be working...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-06-06 00:09:30 +03:00
parent 2b599e0dbe
commit f4c7e9b5e3
3 changed files with 77 additions and 49 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "ig-test", "name": "ig-test",
"version": "1.5.3", "version": "1.5.4",
"description": "experimental test runner....", "description": "experimental test runner....",
"main": "test.js", "main": "test.js",
"bin": { "bin": {

View File

@ -64,13 +64,32 @@ tests.Test('basic',
}) })
tests.Case('async-completion', tests.Case('async-completion',
async function(assert){ async function(assert){
assert(true, 'start') assert(true, 'start')
await assert(true, '1') await assert(true, '1')
await assert(true, '2') await assert(true, '2')
await assert(true, '3') await assert(true, '3')
assert(true, 'done') assert(true, 'done')
}) })
tests.Case('async-completion-nested',
tests.TestSet(function(){
this.Setup({
empty: function(){
return true
},
})
// XXX if this is the last test we will not do all the assertions...
this.Test('test', async function(assert){
assert(true, 'start')
await assert(true, '1')
await assert(true, '2')
await assert(true, '3')
await assert(true, '4')
await assert(true, '5')
assert(true, 'done')
})
}))
// a nested test set... // a nested test set...
tests.Case('nested', tests.Case('nested',

101
test.js
View File

@ -400,7 +400,8 @@ object.Constructor('TestSet', {
// XXX nested assert(..) need to report nestedness correctly... // XXX nested assert(..) need to report nestedness correctly...
// XXX should/can this return a meaningfull result for it to be used // XXX should/can this return a meaningfull result for it to be used
// as a setup/mod??? // as a setup/mod???
__call__: function(context, chain, stats){ // XXX this is very similar to runner(..)...
__call__: async function(context, chain, stats){
var assert var assert
// running nested... // running nested...
if(typeof(chain) == 'function'){ if(typeof(chain) == 'function'){
@ -446,53 +447,58 @@ object.Constructor('TestSet', {
// XXX revise nested assert... // XXX revise nested assert...
var assert = assert var assert = assert
|| this.__assert__('[TEST]', stats, module.VERBOSE) || this.__assert__('[TEST]', stats, module.VERBOSE)
chain_length != 1 var queue =
&& object.deepKeys(tests) chain_length != 1 ?
.filter(function(t, i, l){ object.deepKeys(tests)
return typeof(tests[t]) == 'function' .filter(function(t, i, l){
// skip blank tests if we have other tests unless return typeof(tests[t]) == 'function'
// explicitly specified... // skip blank tests if we have other tests unless
&& ((t == '-' // explicitly specified...
&& test != t && ((t == '-'
&& l.length > 1) ? && test != t
false && l.length > 1) ?
: (test == '*' false
|| test == t) ) }) : (test == '*'
.forEach(function(t){ || test == t) ) })
// modifiers... .map(function(t){
object.deepKeys(modifiers) // modifiers...
.filter(function(m){ return object.deepKeys(modifiers)
return typeof(modifiers[m]) == 'function' .filter(function(m){
&& (mod == '*' || mod == m) }) return typeof(modifiers[m]) == 'function'
.forEach(function(m){ && (mod == '*' || mod == m) })
// setups... .map(function(m){
object.deepKeys(setups) // setups...
.filter(function(s){ return object.deepKeys(setups)
return typeof(setups[s]) == 'function' .filter(function(s){
&& (setup == '*' || setup == s) }) return typeof(setups[s]) == 'function'
.forEach(function(s){ && (setup == '*' || setup == s) })
// run the test... .map(function(s){
stats.tests += 1 return [s, m, t] }) }) })
var _assert = assert.push( .flat(2)
[s, m, t] : []
// do not print blank pass-through ('-') for(var [s, m, t] of queue){
// components... stats.tests += 1
.filter(function(e){ return e != '-' }) ) var _assert = assert.push(
tests[t](_assert, [s, m, t]
modifiers[m](_assert, // do not print blank pass-through ('-')
setups[s](_assert))) }) }) }) // components...
.filter(function(e){ return e != '-' }) )
await tests[t](_assert,
await modifiers[m](_assert,
await setups[s](_assert))) }
// cases... // cases...
// XXX revise nested assert...
assert = assert assert = assert
|| this.__assert__('[CASE]', stats, module.VERBOSE) || this.__assert__('[CASE]', stats, module.VERBOSE)
chain_length <= 1 var queue =
&& Object.keys(cases) chain_length <= 1 ?
.filter(function(s){ Object.keys(cases)
return typeof(cases[s]) == 'function' .filter(function(s){
&& (setup == '*' || setup == s) }) return typeof(cases[s]) == 'function'
.forEach(function(c){ && (setup == '*' || setup == s) })
stats.tests += 1 : []
cases[c]( assert.push(c) ) }) for(var c of queue){
stats.tests += 1
cases[c](assert.push(c)) }
// runtime... // runtime...
stats.time += Date.now() - started stats.time += Date.now() - started
return stats }, return stats },
@ -610,7 +616,7 @@ async function(spec, chain, stats){
e.toObject() e.toObject()
: (e || {}) }) : (e || {}) })
// stats... // setup stats...
stats = stats || {} stats = stats || {}
Object.assign(stats, { Object.assign(stats, {
tests: stats.tests || 0, tests: stats.tests || 0,
@ -995,6 +1001,9 @@ function(default_files, tests){
} else { } else {
await runner(tests, '*', stats) } await runner(tests, '*', stats) }
// XXX BUG for some reason we can get here BEFORE all the
// tests are finished -- forgot to await'ing something???
// print stats... // print stats...
console.log( console.log(
'Tests run:', stats.tests, 'Tests run:', stats.tests,