From f4c7e9b5e34eecd63eb7d9aa30be9852fdfa4e1c Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 6 Jun 2022 00:09:30 +0300 Subject: [PATCH] bugfix -- now seems to be working... Signed-off-by: Alex A. Naanou --- package.json | 2 +- test-test.js | 23 +++++++++++- test.js | 101 ++++++++++++++++++++++++++++----------------------- 3 files changed, 77 insertions(+), 49 deletions(-) diff --git a/package.json b/package.json index ed92f46..46347ae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-test", - "version": "1.5.3", + "version": "1.5.4", "description": "experimental test runner....", "main": "test.js", "bin": { diff --git a/test-test.js b/test-test.js index a9b8fe7..5d0d8b4 100644 --- a/test-test.js +++ b/test-test.js @@ -64,13 +64,32 @@ tests.Test('basic', }) tests.Case('async-completion', - async function(assert){ + async function(assert){ assert(true, 'start') await assert(true, '1') await assert(true, '2') await assert(true, '3') 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... tests.Case('nested', diff --git a/test.js b/test.js index a11da33..ff2f073 100644 --- a/test.js +++ b/test.js @@ -400,7 +400,8 @@ object.Constructor('TestSet', { // XXX nested assert(..) need to report nestedness correctly... // XXX should/can this return a meaningfull result for it to be used // as a setup/mod??? - __call__: function(context, chain, stats){ + // XXX this is very similar to runner(..)... + __call__: async function(context, chain, stats){ var assert // running nested... if(typeof(chain) == 'function'){ @@ -446,53 +447,58 @@ object.Constructor('TestSet', { // XXX revise nested assert... var assert = assert || this.__assert__('[TEST]', stats, module.VERBOSE) - chain_length != 1 - && object.deepKeys(tests) - .filter(function(t, i, l){ - return typeof(tests[t]) == 'function' - // skip blank tests if we have other tests unless - // explicitly specified... - && ((t == '-' - && test != t - && l.length > 1) ? - false - : (test == '*' - || test == t) ) }) - .forEach(function(t){ - // modifiers... - object.deepKeys(modifiers) - .filter(function(m){ - return typeof(modifiers[m]) == 'function' - && (mod == '*' || mod == m) }) - .forEach(function(m){ - // setups... - object.deepKeys(setups) - .filter(function(s){ - return typeof(setups[s]) == 'function' - && (setup == '*' || setup == s) }) - .forEach(function(s){ - // run the test... - stats.tests += 1 - var _assert = assert.push( - [s, m, t] - // do not print blank pass-through ('-') - // components... - .filter(function(e){ return e != '-' }) ) - tests[t](_assert, - modifiers[m](_assert, - setups[s](_assert))) }) }) }) + var queue = + chain_length != 1 ? + object.deepKeys(tests) + .filter(function(t, i, l){ + return typeof(tests[t]) == 'function' + // skip blank tests if we have other tests unless + // explicitly specified... + && ((t == '-' + && test != t + && l.length > 1) ? + false + : (test == '*' + || test == t) ) }) + .map(function(t){ + // modifiers... + return object.deepKeys(modifiers) + .filter(function(m){ + return typeof(modifiers[m]) == 'function' + && (mod == '*' || mod == m) }) + .map(function(m){ + // setups... + return object.deepKeys(setups) + .filter(function(s){ + return typeof(setups[s]) == 'function' + && (setup == '*' || setup == s) }) + .map(function(s){ + return [s, m, t] }) }) }) + .flat(2) + : [] + for(var [s, m, t] of queue){ + stats.tests += 1 + var _assert = assert.push( + [s, m, t] + // do not print blank pass-through ('-') + // components... + .filter(function(e){ return e != '-' }) ) + await tests[t](_assert, + await modifiers[m](_assert, + await setups[s](_assert))) } // cases... - // XXX revise nested assert... assert = assert || this.__assert__('[CASE]', stats, module.VERBOSE) - chain_length <= 1 - && Object.keys(cases) - .filter(function(s){ - return typeof(cases[s]) == 'function' - && (setup == '*' || setup == s) }) - .forEach(function(c){ - stats.tests += 1 - cases[c]( assert.push(c) ) }) + var queue = + chain_length <= 1 ? + Object.keys(cases) + .filter(function(s){ + return typeof(cases[s]) == 'function' + && (setup == '*' || setup == s) }) + : [] + for(var c of queue){ + stats.tests += 1 + cases[c](assert.push(c)) } // runtime... stats.time += Date.now() - started return stats }, @@ -610,7 +616,7 @@ async function(spec, chain, stats){ e.toObject() : (e || {}) }) - // stats... + // setup stats... stats = stats || {} Object.assign(stats, { tests: stats.tests || 0, @@ -995,6 +1001,9 @@ function(default_files, tests){ } else { 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... console.log( 'Tests run:', stats.tests,