2020-08-08 09:22:42 +03:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
/**********************************************************************
|
|
|
|
|
*
|
|
|
|
|
* test.js
|
|
|
|
|
*
|
|
|
|
|
* Repo and docs:
|
|
|
|
|
* https://github.com/flynx/test.js
|
|
|
|
|
*
|
|
|
|
|
***********************************************/ /* c8 ignore next 2 */
|
|
|
|
|
((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define)
|
|
|
|
|
(function(require){ var module={} // make module AMD/node compatible...
|
|
|
|
|
/*********************************************************************/
|
|
|
|
|
|
|
|
|
|
var tests = require('./test')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
|
2020-08-09 19:08:11 +03:00
|
|
|
tests.Setup('setup',
|
|
|
|
|
function(assert){
|
2022-06-05 19:31:27 +03:00
|
|
|
assert(true, 'setup')
|
|
|
|
|
return {setup: 'setup'} })
|
2020-08-08 09:22:42 +03:00
|
|
|
|
|
|
|
|
tests.Setups({
|
2020-08-09 19:08:11 +03:00
|
|
|
setup2: function(assert){
|
2022-06-05 19:31:27 +03:00
|
|
|
assert(true, 'setup')
|
|
|
|
|
return {setup: 'setup2'} },
|
|
|
|
|
async: async function(assert){
|
|
|
|
|
assert(true, 'setup')
|
2022-06-05 20:46:35 +03:00
|
|
|
return await {setup: 'async'} },
|
2022-06-05 19:31:27 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
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'
|
2022-06-05 20:46:35 +03:00
|
|
|
return await setup },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
tests.Tests({
|
|
|
|
|
async: async function(assert, setup){
|
|
|
|
|
assert(setup, 'test')
|
|
|
|
|
await setup
|
2022-06-05 23:23:24 +03:00
|
|
|
assert.log(setup)
|
|
|
|
|
assert(setup, 'done')
|
|
|
|
|
},
|
2020-08-08 09:22:42 +03:00
|
|
|
})
|
|
|
|
|
|
2022-06-05 19:31:27 +03:00
|
|
|
|
2020-08-17 13:14:46 +03:00
|
|
|
tests.Setup('setup',
|
|
|
|
|
function(assert){
|
|
|
|
|
assert(false, 'setup (shadowed): assert')
|
|
|
|
|
return {} })
|
|
|
|
|
|
2022-06-05 19:31:27 +03:00
|
|
|
tests.Test('basic',
|
2020-08-09 19:08:11 +03:00
|
|
|
function(assert, setup){
|
2022-06-05 19:31:27 +03:00
|
|
|
assert(setup, 'test')
|
|
|
|
|
assert.log(setup)
|
|
|
|
|
})
|
|
|
|
|
|
2022-06-05 23:23:24 +03:00
|
|
|
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')
|
|
|
|
|
})
|
2020-08-09 19:08:11 +03:00
|
|
|
|
2020-10-13 05:04:23 +03:00
|
|
|
// a nested test set...
|
|
|
|
|
tests.Case('nested',
|
|
|
|
|
tests.TestSet(function(){
|
2022-06-05 23:23:24 +03:00
|
|
|
// XXX these can behave in an odd manner...
|
|
|
|
|
// $ ./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') })
|
2020-10-13 05:04:23 +03:00
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
|
2020-08-09 19:08:11 +03:00
|
|
|
|
2022-06-05 19:31:27 +03:00
|
|
|
|
2020-08-09 19:08:11 +03:00
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
typeof(__filename) != 'undefined'
|
|
|
|
|
&& __filename == (require.main || {}).filename
|
|
|
|
|
&& tests.run()
|
2020-08-08 09:22:42 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
|
* vim:set ts=4 sw=4 : */ return module })
|