mirror of
https://github.com/flynx/test.js.git
synced 2025-12-29 06:41:58 +00:00
cleanup... (needs testing!)
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
1409b80a24
commit
2aa354d30d
193
test.js
193
test.js
@ -8,12 +8,11 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* TODO:
|
* TODO:
|
||||||
* - a mor descriptive assertion fail...
|
* - a more descriptive assertion fail...
|
||||||
* would be nice to:
|
* would be nice to:
|
||||||
* - know what exactly failed and what was expected automatically
|
* - know what exactly failed and what was expected automatically
|
||||||
* - ...
|
* - ...
|
||||||
* - list found files...
|
* - list found files...
|
||||||
* - flexible test chains with 0 or more modifiers...
|
|
||||||
* - might be a good idea to detect test module type and run only our
|
* - might be a good idea to detect test module type and run only our
|
||||||
* ones...
|
* ones...
|
||||||
*
|
*
|
||||||
@ -60,7 +59,7 @@ module.IGNORE_TEST_FILES = ['node_modules/**']
|
|||||||
// or
|
// or
|
||||||
// $ VERBOSE=1 node test.js
|
// $ VERBOSE=1 node test.js
|
||||||
// or set this manually after require('./test') but before calling
|
// or set this manually after require('./test') but before calling
|
||||||
// the runner(..) or run(..)
|
// the runTests(..) or run(..)
|
||||||
// NOTE: this may change in the future...
|
// NOTE: this may change in the future...
|
||||||
module.VERBOSE = process ?
|
module.VERBOSE = process ?
|
||||||
process.env.VERBOSE
|
process.env.VERBOSE
|
||||||
@ -275,7 +274,6 @@ var mergeIter = function(iter){
|
|||||||
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
//
|
//
|
||||||
// Merged(name, func)
|
// Merged(name, func)
|
||||||
// -> merged
|
// -> merged
|
||||||
@ -387,6 +385,8 @@ object.Constructor('Merged', {
|
|||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Get tests from a test object...
|
||||||
|
//
|
||||||
var getTests = function(spec){
|
var getTests = function(spec){
|
||||||
var {setups, modifiers, tests, cases} = spec
|
var {setups, modifiers, tests, cases} = spec
|
||||||
;[setups, modifiers, tests, cases] =
|
;[setups, modifiers, tests, cases] =
|
||||||
@ -402,7 +402,9 @@ var getTests = function(spec){
|
|||||||
cases,
|
cases,
|
||||||
} }
|
} }
|
||||||
|
|
||||||
// XXX
|
|
||||||
|
// Parse test chain...
|
||||||
|
//
|
||||||
var parseChain =
|
var parseChain =
|
||||||
module.parseChain =
|
module.parseChain =
|
||||||
function(spec, chain){
|
function(spec, chain){
|
||||||
@ -433,6 +435,16 @@ function(spec, chain){
|
|||||||
length,
|
length,
|
||||||
} }
|
} }
|
||||||
|
|
||||||
|
|
||||||
|
// Build test chain queue...
|
||||||
|
//
|
||||||
|
// NOTE: this might look too nested-looped but this needs to do several
|
||||||
|
// dimensions of cartesian products, so no way around this.
|
||||||
|
//
|
||||||
|
// XXX add support for partial patterns
|
||||||
|
// e.g.
|
||||||
|
// test-*:*-keyword:*x
|
||||||
|
// XXX log test errors -- unavailable tests, invalid chains, ... etc.
|
||||||
var buildQueue =
|
var buildQueue =
|
||||||
module.buildQueue =
|
module.buildQueue =
|
||||||
function(spec, chain, mod_chain_length=1){
|
function(spec, chain, mod_chain_length=1){
|
||||||
@ -503,11 +515,78 @@ function(spec, chain, mod_chain_length=1){
|
|||||||
: [],
|
: [],
|
||||||
} }
|
} }
|
||||||
|
|
||||||
var runQueue =
|
|
||||||
module.runQueue =
|
|
||||||
function(queue){
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Test runner/combinator...
|
||||||
|
//
|
||||||
|
// runTests(spec)
|
||||||
|
// runTests(spec, '*')
|
||||||
|
// -> promise(stats)
|
||||||
|
//
|
||||||
|
// runTests(spec, 'case')
|
||||||
|
// runTests(spec, 'setup:test')
|
||||||
|
// runTests(spec, 'setup:mod:test')
|
||||||
|
// -> promise(stats)
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// This will run
|
||||||
|
// test(modifier(setup))
|
||||||
|
// for each test in spec.tests
|
||||||
|
// for each modifier in spec.modifiers
|
||||||
|
// for each setup in spec.setups
|
||||||
|
// case()
|
||||||
|
// for each case in spec.cases
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// XXX make Assert optional...
|
||||||
|
// XXX is this a good name???
|
||||||
|
var runTests =
|
||||||
|
module.runTests =
|
||||||
|
async function(spec, chain, stats, mod_chain_length=1, assert=Assert){
|
||||||
|
var {setups, modifiers, tests, cases} = getTests(spec)
|
||||||
|
|
||||||
|
// setup stats...
|
||||||
|
stats = stats || {}
|
||||||
|
Object.assign(stats, {
|
||||||
|
tests: stats.tests || 0,
|
||||||
|
assertions: stats.assertions || 0,
|
||||||
|
failures: stats.failures || 0,
|
||||||
|
time: stats.time || 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
var started = Date.now()
|
||||||
|
|
||||||
|
var queue = buildQueue(spec, chain, mod_chain_length)
|
||||||
|
|
||||||
|
// NOTE: we are not running these via .map(..) to keep things in
|
||||||
|
// sequence...
|
||||||
|
var assert = assert('[TEST]', stats, module.VERBOSE)
|
||||||
|
for(var [s, m, t] of queue.tests){
|
||||||
|
// 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 != '-' }) )
|
||||||
|
var d = await setups[s](_assert)
|
||||||
|
for(var mod of m){
|
||||||
|
d = await modifiers[mod](_assert, d) }
|
||||||
|
await tests[t](_assert, d) }
|
||||||
|
|
||||||
|
// cases...
|
||||||
|
var assert = assert('[CASE]', stats, module.VERBOSE)
|
||||||
|
for(var c of queue.cases){
|
||||||
|
stats.tests += 1
|
||||||
|
await cases[c](assert.push(c)) }
|
||||||
|
|
||||||
|
// runtime...
|
||||||
|
stats.time += Date.now() - started
|
||||||
|
return stats }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
var TestSet =
|
var TestSet =
|
||||||
module.TestSet =
|
module.TestSet =
|
||||||
@ -528,23 +607,17 @@ object.Constructor('TestSet', {
|
|||||||
|
|
||||||
__assert__: Assert,
|
__assert__: Assert,
|
||||||
|
|
||||||
// XXX DIVERGED FROM runner(..) -- unify!!!
|
|
||||||
// ...essentially this looks like runner(..) with a different way to get assert...
|
|
||||||
// XXX need to be able to use external assert...
|
|
||||||
// - from context...
|
|
||||||
// - from arg...
|
|
||||||
// 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
|
__call__: async function(chain, stats, mod_chain_length=1){
|
||||||
// as a setup/mod???
|
var assert = this.__assert__
|
||||||
// XXX this is very similar to runner(..)...
|
|
||||||
__call__: async function(context, chain, stats){
|
|
||||||
var assert
|
|
||||||
// running nested...
|
// running nested...
|
||||||
if(typeof(chain) == 'function'){
|
if(typeof(chain) == 'function'){
|
||||||
assert = chain
|
assert = chain
|
||||||
chain = null
|
chain = null
|
||||||
stats = stats
|
stats = stats
|
||||||
|| assert.stats }
|
|| assert.stats }
|
||||||
|
return runTests(this, chain, stats, mod_chain_length, assert) },
|
||||||
|
/*/
|
||||||
// parse chain...
|
// parse chain...
|
||||||
//chain = this.parseChain(chain)
|
//chain = this.parseChain(chain)
|
||||||
chain = (chain == '*' || chain == null) ?
|
chain = (chain == '*' || chain == null) ?
|
||||||
@ -639,6 +712,7 @@ object.Constructor('TestSet', {
|
|||||||
// runtime...
|
// runtime...
|
||||||
stats.time += Date.now() - started
|
stats.time += Date.now() - started
|
||||||
return stats },
|
return stats },
|
||||||
|
//*/
|
||||||
|
|
||||||
__init__: function(func){
|
__init__: function(func){
|
||||||
// test collections...
|
// test collections...
|
||||||
@ -671,7 +745,6 @@ object.Constructor('TestSet', {
|
|||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
// XXX rename to runner...
|
|
||||||
module.BASE_TEST_SET = new TestSet()
|
module.BASE_TEST_SET = new TestSet()
|
||||||
|
|
||||||
module.Setup =
|
module.Setup =
|
||||||
@ -697,82 +770,6 @@ module.merge =
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
|
||||||
// Test runner/combinator...
|
|
||||||
//
|
|
||||||
// runner(spec)
|
|
||||||
// runner(spec, '*')
|
|
||||||
// -> promise(stats)
|
|
||||||
//
|
|
||||||
// runner(spec, 'case')
|
|
||||||
// runner(spec, 'setup:test')
|
|
||||||
// runner(spec, 'setup:mod:test')
|
|
||||||
// -> promise(stats)
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// This will run
|
|
||||||
// test(modifier(setup))
|
|
||||||
// for each test in spec.tests
|
|
||||||
// for each modifier in spec.modifiers
|
|
||||||
// for each setup in spec.setups
|
|
||||||
// case()
|
|
||||||
// for each case in spec.cases
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// NOTE: chaining more than one modifier is not yet supported (XXX)
|
|
||||||
//
|
|
||||||
// XXX chain N modifiers...
|
|
||||||
// XXX make Assert optional...
|
|
||||||
// XXX is this a good name???
|
|
||||||
//* XXX do we need a root runner???
|
|
||||||
// ...if not then need to cleanup run(..) to use TestSet / BASE_TEST_SET...
|
|
||||||
var runner =
|
|
||||||
module.runner =
|
|
||||||
async function(spec, chain, stats, mod_chain_length=1){
|
|
||||||
var {setups, modifiers, tests, cases} = getTests(spec)
|
|
||||||
|
|
||||||
// setup stats...
|
|
||||||
stats = stats || {}
|
|
||||||
Object.assign(stats, {
|
|
||||||
tests: stats.tests || 0,
|
|
||||||
assertions: stats.assertions || 0,
|
|
||||||
failures: stats.failures || 0,
|
|
||||||
time: stats.time || 0,
|
|
||||||
})
|
|
||||||
|
|
||||||
var started = Date.now()
|
|
||||||
|
|
||||||
var queue = buildQueue(spec, chain, mod_chain_length)
|
|
||||||
|
|
||||||
// NOTE: we are not running these via .map(..) to keep things in
|
|
||||||
// sequence...
|
|
||||||
var assert = Assert('[TEST]', stats, module.VERBOSE)
|
|
||||||
for(var [s, m, t] of queue.tests){
|
|
||||||
// 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 != '-' }) )
|
|
||||||
var d = await setups[s](_assert)
|
|
||||||
for(var mod of m){
|
|
||||||
d = await modifiers[mod](_assert, d) }
|
|
||||||
await tests[t](_assert, d) }
|
|
||||||
|
|
||||||
// cases...
|
|
||||||
var assert = Assert('[CASE]', stats, module.VERBOSE)
|
|
||||||
for(var c of queue.cases){
|
|
||||||
stats.tests += 1
|
|
||||||
await cases[c](assert.push(c)) }
|
|
||||||
|
|
||||||
// runtime...
|
|
||||||
stats.time += Date.now() - started
|
|
||||||
return stats }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
// CLI...
|
// CLI...
|
||||||
//
|
//
|
||||||
@ -1085,10 +1082,10 @@ function(default_files, tests){
|
|||||||
// run the tests...
|
// run the tests...
|
||||||
if(chains.length > 0){
|
if(chains.length > 0){
|
||||||
for(var chain of chains){
|
for(var chain of chains){
|
||||||
await runner(tests, chain, stats, this.mod_chain_length) }
|
await runTests(tests, chain, stats, this.mod_chain_length) }
|
||||||
//await module.BASE_TEST_SET(tests, chain, stats) }
|
//await module.BASE_TEST_SET(tests, chain, stats) }
|
||||||
} else {
|
} else {
|
||||||
await runner(tests, '*', stats, this.mod_chain_length) }
|
await runTests(tests, '*', stats, this.mod_chain_length) }
|
||||||
//await module.BASE_TEST_SET(tests, '*', stats) }
|
//await module.BASE_TEST_SET(tests, '*', stats) }
|
||||||
|
|
||||||
// XXX BUG for some reason we can get here BEFORE all the
|
// XXX BUG for some reason we can get here BEFORE all the
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user