tweaking and fixing...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-06-05 23:23:24 +03:00
parent 7f1ead5c7c
commit 2b599e0dbe
3 changed files with 41 additions and 18 deletions

View File

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

View File

@ -46,7 +46,9 @@ tests.Tests({
async: async function(assert, setup){ async: async function(assert, setup){
assert(setup, 'test') assert(setup, 'test')
await setup await setup
assert.log(setup) }, assert.log(setup)
assert(setup, 'done')
},
}) })
@ -61,12 +63,33 @@ tests.Test('basic',
assert.log(setup) assert.log(setup)
}) })
tests.Case('async-completion',
async function(assert){
assert(true, 'start')
await assert(true, '1')
await assert(true, '2')
await assert(true, '3')
assert(true, 'done')
})
// a nested test set... // a nested test set...
tests.Case('nested', tests.Case('nested',
tests.TestSet(function(){ tests.TestSet(function(){
this.Case('moo', function(assert){ // XXX these can behave in an odd manner...
assert(true, 'nested dummy: assert') }) // $ ./test.js nested --verbose
// will prin the output of the sunc test while the async
// is waiting...
// ...not yet sure how to sequence these in a more predictable
// manner...
// ...this only affects output sequencing and not the actual
// execution flow...
this.Case('async', async function(assert){
assert(true, 'nested async: assert')
await 123
assert(true, 'nested async: done') })
this.Case('sync', function(assert){
assert(true, 'nested sync: assert') })
})) }))

28
test.js
View File

@ -559,12 +559,12 @@ module.merge =
// //
// runner(spec) // runner(spec)
// runner(spec, '*') // runner(spec, '*')
// -> stats // -> promise(stats)
// //
// runner(spec, 'case') // runner(spec, 'case')
// runner(spec, 'setup:test') // runner(spec, 'setup:test')
// runner(spec, 'setup:mod:test') // runner(spec, 'setup:mod:test')
// -> stats // -> promise(stats)
// //
// //
// This will run // This will run
@ -650,7 +650,6 @@ async function(spec, chain, stats){
return [s, m, t] }) }) }) return [s, m, t] }) }) })
.flat(2) .flat(2)
: [] : []
// run the test queue...
// NOTE: we are not running these via .map(..) to keep things in // NOTE: we are not running these via .map(..) to keep things in
// sequence... // sequence...
var assert = Assert('[TEST]', stats, module.VERBOSE) var assert = Assert('[TEST]', stats, module.VERBOSE)
@ -661,7 +660,8 @@ async function(spec, chain, stats){
[s, m, t] [s, m, t]
// do not print blank pass-through ('-') // do not print blank pass-through ('-')
// components... // components...
.filter(function(e){ return e != '-' }) ) .filter(function(e){
return e != '-' }) )
await tests[t]( await tests[t](
_assert, _assert,
await modifiers[m]( await modifiers[m](
@ -674,12 +674,13 @@ async function(spec, chain, stats){
Object.keys(cases) 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) })
: [] : []
var assert = Assert('[CASE]', stats, module.VERBOSE) var assert = Assert('[CASE]', stats, module.VERBOSE)
for(var c of queue){ for(var c of queue){
stats.tests += 1 stats.tests += 1
await cases[c]( assert.push(c) ) } await cases[c](assert.push(c)) }
// runtime... // runtime...
stats.time += Date.now() - started stats.time += Date.now() - started
@ -952,7 +953,7 @@ argv.Parser({
// //
var run = var run =
module.run = module.run =
async function(default_files, tests){ 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'))){
@ -988,11 +989,11 @@ async function(default_files, tests){
// XXX should this be generic??? // XXX should this be generic???
.then(async function(chains){ .then(async function(chains){
// run the tests... // run the tests...
await (chains.length > 0 ? if(chains.length > 0){
Promise.all(chains for(var chain of chains){
.map(function(chain){ await runner(tests, chain, stats) }
return runner(tests, chain, stats) })) } else {
: runner(tests, '*', stats)) await runner(tests, '*', stats) }
// print stats... // print stats...
console.log( console.log(
@ -1002,8 +1003,7 @@ async function(default_files, tests){
` (${stats.time}ms)`.bold.black) ` (${stats.time}ms)`.bold.black)
// report error status to the OS... // report error status to the OS...
process.exit(stats.failures) process.exit(stats.failures) })
})
.call() } .call() }