@ -11,12 +11,15 @@ function normalise_trace_logs(logs) {
if ( typeof log === 'string' && log . includes ( '%c' ) ) {
const split = log . split ( '%c' ) ;
normalised . push ( ( split [ 0 ] . length !== 0 ? split [ 0 ] : split [ 1 ] ) . trim ( ) ) ;
normalised . push ( {
log : ( split [ 0 ] . length !== 0 ? split [ 0 ] : split [ 1 ] ) . trim ( ) ,
highlighted : logs [ i + 1 ] === 'color: CornflowerBlue; font-weight: bold'
} ) ;
i ++ ;
} else if ( log instanceof Error ) {
continue ;
} else {
normalised . push ( log ) ;
normalised . push ( { log } ) ;
}
}
return normalised ;
@ -28,7 +31,17 @@ export default test({
} ,
test ( { assert , target , logs } ) {
assert . deepEqual ( normalise _trace _logs ( logs ) , [ 'effect' , '$derived' , 0 , '$state' , 0 ] ) ;
// initial log, everything is highlighted
assert . deepEqual ( normalise _trace _logs ( logs ) , [
{ log : 'effect' , highlighted : false } ,
{ log : '$derived' , highlighted : true } ,
{ log : 0 } ,
{ log : '$state' , highlighted : true } ,
{ log : 0 } ,
{ log : '$state' , highlighted : true } ,
{ log : false }
] ) ;
logs . length = 0 ;
@ -36,6 +49,49 @@ export default test({
button ? . click ( ) ;
flushSync ( ) ;
assert . deepEqual ( normalise _trace _logs ( logs ) , [ 'effect' , '$derived' , 2 , '$state' , 1 ] ) ;
// count changed, derived and state are highlighted, last state is not
assert . deepEqual ( normalise _trace _logs ( logs ) , [
{ log : 'effect' , highlighted : false } ,
{ log : '$derived' , highlighted : true } ,
{ log : 2 } ,
{ log : '$state' , highlighted : true } ,
{ log : 1 } ,
{ log : '$state' , highlighted : false } ,
{ log : false }
] ) ;
logs . length = 0 ;
const input = target . querySelector ( 'input' ) ;
input ? . click ( ) ;
flushSync ( ) ;
// checked changed, last state is highlighted, first two are not
assert . deepEqual ( normalise _trace _logs ( logs ) , [
{ log : 'effect' , highlighted : false } ,
{ log : '$derived' , highlighted : false } ,
{ log : 2 } ,
{ log : '$state' , highlighted : false } ,
{ log : 1 } ,
{ log : '$state' , highlighted : true } ,
{ log : true }
] ) ;
logs . length = 0 ;
button ? . click ( ) ;
flushSync ( ) ;
// count change and derived it's >=4, checked is not in the dependencies anymore
assert . deepEqual ( normalise _trace _logs ( logs ) , [
{ log : 'effect' , highlighted : false } ,
{ log : '$derived' , highlighted : true } ,
{ log : 4 } ,
{ log : '$state' , highlighted : true } ,
{ log : 2 }
] ) ;
}
} ) ;