mirror of
https://github.com/flynx/test.js.git
synced 2025-12-19 18:11:42 +00:00
added shadow reporting/handling...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
a10e8ae340
commit
89abacdb7e
@ -31,6 +31,11 @@ tests.Setups({
|
|||||||
return {} },
|
return {} },
|
||||||
})
|
})
|
||||||
|
|
||||||
|
tests.Setup('setup',
|
||||||
|
function(assert){
|
||||||
|
assert(false, 'setup (shadowed): assert')
|
||||||
|
return {} })
|
||||||
|
|
||||||
tests.Test('dummy',
|
tests.Test('dummy',
|
||||||
function(assert, setup){
|
function(assert, setup){
|
||||||
assert(true, 'dummy: assert') })
|
assert(true, 'dummy: assert') })
|
||||||
|
|||||||
43
test.js
43
test.js
@ -6,8 +6,10 @@
|
|||||||
* Repo and docs:
|
* Repo and docs:
|
||||||
* https://github.com/flynx/test.js
|
* https://github.com/flynx/test.js
|
||||||
*
|
*
|
||||||
|
*
|
||||||
* TODO:
|
* TODO:
|
||||||
* - report shadowing of tests...
|
* - flexible test chains with 0 or more modifiers...
|
||||||
|
*
|
||||||
*
|
*
|
||||||
***********************************************/ /* c8 ignore next 2 */
|
***********************************************/ /* c8 ignore next 2 */
|
||||||
((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define)
|
((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define)
|
||||||
@ -59,6 +61,8 @@ module.VERBOSE = process ?
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
var getCallerFilename =
|
var getCallerFilename =
|
||||||
@ -246,6 +250,8 @@ var mergeIter = function(iter){
|
|||||||
// -> merged
|
// -> merged
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
// Merged is the sum of all its members.
|
||||||
|
//
|
||||||
var Merged =
|
var Merged =
|
||||||
module.Merged =
|
module.Merged =
|
||||||
object.Constructor('Merged', {
|
object.Constructor('Merged', {
|
||||||
@ -266,6 +272,7 @@ object.Constructor('Merged', {
|
|||||||
// in JS...
|
// in JS...
|
||||||
get size(){
|
get size(){
|
||||||
return this.keys().length },
|
return this.keys().length },
|
||||||
|
// Like .size but does not count the pass-through elements...
|
||||||
get usize(){
|
get usize(){
|
||||||
var k = this.keys()
|
var k = this.keys()
|
||||||
return k.length - (k.includes('-') ? 1 : 0) },
|
return k.length - (k.includes('-') ? 1 : 0) },
|
||||||
@ -289,21 +296,51 @@ object.Constructor('Merged', {
|
|||||||
|
|
||||||
toObject: function(){
|
toObject: function(){
|
||||||
return Object.fromEntries(this.entries()) },
|
return Object.fromEntries(this.entries()) },
|
||||||
|
|
||||||
|
//
|
||||||
|
// .checkShadowing()
|
||||||
|
// -> shadows
|
||||||
|
//
|
||||||
|
// .checkShadowing(other)
|
||||||
|
// -> shadows
|
||||||
|
//
|
||||||
|
checkShadowing: function(other){
|
||||||
|
var existing = new Set(this.keys())
|
||||||
|
|
||||||
|
other = other || this.values()
|
||||||
|
return (other instanceof Array ?
|
||||||
|
other
|
||||||
|
: [other])
|
||||||
|
.map(function(o){
|
||||||
|
return Object.keys(o)
|
||||||
|
.filter(function(k){
|
||||||
|
return existing.has(k) }) })
|
||||||
|
.flat() },
|
||||||
|
handleShadowing: function(shadowed){
|
||||||
|
shadowed.length > 0
|
||||||
|
&& console.warn(` WARNING:`.bold, `shadowing: ${shadowed.join()}`)
|
||||||
|
return this },
|
||||||
}, {
|
}, {
|
||||||
filename: undefined,
|
filename: undefined,
|
||||||
|
|
||||||
__init__: function(other){
|
__init__: function(other){
|
||||||
|
// parse args...
|
||||||
if(arguments.length == 2){
|
if(arguments.length == 2){
|
||||||
var [name, func] = arguments
|
var [name, func] = arguments
|
||||||
other = {[name]: func}
|
other = {[name]: func} }
|
||||||
}
|
|
||||||
|
|
||||||
|
// set .filename on tests...
|
||||||
var f = getCallerFilename()
|
var f = getCallerFilename()
|
||||||
Object.entries(Object.getOwnPropertyDescriptors(other))
|
Object.entries(Object.getOwnPropertyDescriptors(other))
|
||||||
.forEach(function([k, p]){
|
.forEach(function([k, p]){
|
||||||
typeof(p.value) == 'function'
|
typeof(p.value) == 'function'
|
||||||
&& (p.value.filename = p.value.filename || f) })
|
&& (p.value.filename = p.value.filename || f) })
|
||||||
|
|
||||||
|
// check for shadowing...
|
||||||
|
this.constructor.handleShadowing(
|
||||||
|
this.constructor.checkShadowing(other))
|
||||||
|
|
||||||
|
// mix and merge...
|
||||||
object.mixinFlat(this, other)
|
object.mixinFlat(this, other)
|
||||||
this.constructor.add(this) },
|
this.constructor.add(this) },
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user