pull/16060/head
Rich Harris 3 months ago
parent 798a495b35
commit 4047913fde

@ -198,22 +198,38 @@ export const fragments = /** @type {'html' | 'tree'} */ (process.env.FRAGMENTS)
*/ */
export function normalise_trace_logs(logs) { export function normalise_trace_logs(logs) {
let normalised = []; let normalised = [];
for (let i = 0; i < logs.length; i++) {
const log = logs[i]; logs = logs.slice();
while (logs.length > 0) {
const log = logs.shift();
if (log instanceof Error) {
continue;
}
if (typeof log === 'string' && log.includes('%c')) { if (typeof log === 'string' && log.includes('%c')) {
const split = log.split('%c'); const split = log.split('%c');
console.log({ split });
normalised.push({ const first = /** @type {string} */ (split.shift()).trim();
log: (split[0].length !== 0 ? split[0] : split[1]).trim(), if (first) normalised.push({ log: first });
highlighted: logs[i + 1] === 'color: CornflowerBlue; font-weight: bold'
}); while (split.length > 0) {
i++; const log = /** @type {string} */ (split.shift()).trim();
} else if (log instanceof Error) { const highlighted = logs.shift() === 'color: CornflowerBlue; font-weight: bold';
continue;
// omit timings, as they will differ between runs
if (/\(.+ms\)/.test(log)) continue;
normalised.push({
log,
highlighted
});
}
} else { } else {
normalised.push({ log }); normalised.push({ log });
} }
} }
return normalised; return normalised;
} }

@ -11,10 +11,11 @@ export default test({
// initial log, everything is highlighted // initial log, everything is highlighted
assert.deepEqual(normalise_trace_logs(logs), [ assert.deepEqual(normalise_trace_logs(logs), [
{ log: 'iife', highlighted: false }, { log: 'iife' },
{ log: 'count — $state', highlighted: true }, { log: '$state', highlighted: true },
{ log: 'count', highlighted: false },
{ log: 0 }, { log: 0 },
{ log: 'effect', highlighted: false } { log: 'effect' }
]); ]);
logs.length = 0; logs.length = 0;
@ -24,10 +25,11 @@ export default test({
flushSync(); flushSync();
assert.deepEqual(normalise_trace_logs(logs), [ assert.deepEqual(normalise_trace_logs(logs), [
{ log: 'iife', highlighted: false }, { log: 'iife' },
{ log: 'count — $state', highlighted: true }, { log: '$state', highlighted: true },
{ log: 'count', highlighted: false },
{ log: 1 }, { log: 1 },
{ log: 'effect', highlighted: false } { log: 'effect' }
]); ]);
} }
}); });

@ -11,8 +11,9 @@ export default test({
// initial log, everything is highlighted // initial log, everything is highlighted
assert.deepEqual(normalise_trace_logs(logs), [ assert.deepEqual(normalise_trace_logs(logs), [
{ log: 'effect', highlighted: false }, { log: 'effect' },
{ log: 'checked — $state', highlighted: true }, { log: '$state', highlighted: true },
{ log: 'checked', highlighted: false },
{ log: false } { log: false }
]); ]);
@ -29,20 +30,26 @@ export default test({
// checked changed, effect reassign state, values should be correct and be correctly highlighted // checked changed, effect reassign state, values should be correct and be correctly highlighted
assert.deepEqual(normalise_trace_logs(logs), [ assert.deepEqual(normalise_trace_logs(logs), [
{ log: 'effect', highlighted: false }, { log: 'effect' },
{ log: 'checked — $state', highlighted: true }, { log: '$state', highlighted: true },
{ log: 'checked', highlighted: false },
{ log: true }, { log: true },
{ log: 'count — $state', highlighted: true }, { log: '$state', highlighted: true },
{ log: 'count', highlighted: false },
{ log: 1 }, { log: 1 },
{ log: 'effect', highlighted: false }, { log: 'effect' },
{ log: 'checked — $state', highlighted: false }, { log: '$state', highlighted: false },
{ log: 'checked', highlighted: false },
{ log: true }, { log: true },
{ log: 'count — $state', highlighted: true }, { log: '$state', highlighted: true },
{ log: 'count', highlighted: false },
{ log: 2 }, { log: 2 },
{ log: 'effect', highlighted: false }, { log: 'effect' },
{ log: 'checked — $state', highlighted: false }, { log: '$state', highlighted: false },
{ log: 'checked', highlighted: false },
{ log: true }, { log: true },
{ log: 'count — $state', highlighted: true }, { log: '$state', highlighted: true },
{ log: 'count', highlighted: false },
{ log: 3 } { log: 3 }
]); ]);
} }

@ -11,12 +11,15 @@ export default test({
// initial log, everything is highlighted // initial log, everything is highlighted
assert.deepEqual(normalise_trace_logs(logs), [ assert.deepEqual(normalise_trace_logs(logs), [
{ log: 'effect', highlighted: false }, { log: 'effect' },
{ log: '$derived', highlighted: true }, { log: '$derived', highlighted: true },
{ log: 'double', highlighted: false },
{ log: 0 }, { log: 0 },
{ log: 'count — $state', highlighted: true }, { log: '$state', highlighted: true },
{ log: 'count', highlighted: false },
{ log: 0 }, { log: 0 },
{ log: 'checked — $state', highlighted: true }, { log: '$state', highlighted: true },
{ log: 'checked', highlighted: false },
{ log: false } { log: false }
]); ]);
@ -29,12 +32,15 @@ export default test({
// count changed, derived and state are highlighted, last state is not // count changed, derived and state are highlighted, last state is not
assert.deepEqual(normalise_trace_logs(logs), [ assert.deepEqual(normalise_trace_logs(logs), [
{ log: 'effect', highlighted: false }, { log: 'effect' },
{ log: 'double — $derived', highlighted: true }, { log: '$derived', highlighted: true },
{ log: 'double', highlighted: false },
{ log: 2 }, { log: 2 },
{ log: 'count — $state', highlighted: true }, { log: '$state', highlighted: true },
{ log: 'count', highlighted: false },
{ log: 1 }, { log: 1 },
{ log: 'checked — $state', highlighted: false }, { log: '$state', highlighted: false },
{ log: 'checked', highlighted: false },
{ log: false } { log: false }
]); ]);
@ -47,12 +53,15 @@ export default test({
// checked changed, last state is highlighted, first two are not // checked changed, last state is highlighted, first two are not
assert.deepEqual(normalise_trace_logs(logs), [ assert.deepEqual(normalise_trace_logs(logs), [
{ log: 'effect', highlighted: false }, { log: 'effect' },
{ log: 'double — $derived', highlighted: false }, { log: '$derived', highlighted: false },
{ log: 'double', highlighted: false },
{ log: 2 }, { log: 2 },
{ log: 'count — $state', highlighted: false }, { log: '$state', highlighted: false },
{ log: 'count', highlighted: false },
{ log: 1 }, { log: 1 },
{ log: 'checked — $state', highlighted: true }, { log: '$state', highlighted: true },
{ log: 'checked', highlighted: false },
{ log: true } { log: true }
]); ]);
@ -64,10 +73,12 @@ export default test({
// count change and derived it's >=4, checked is not in the dependencies anymore // count change and derived it's >=4, checked is not in the dependencies anymore
assert.deepEqual(normalise_trace_logs(logs), [ assert.deepEqual(normalise_trace_logs(logs), [
{ log: 'effect', highlighted: false }, { log: 'effect' },
{ log: 'double — $derived', highlighted: true }, { log: '$derived', highlighted: true },
{ log: 'double', highlighted: false },
{ log: 4 }, { log: 4 },
{ log: 'count — $state', highlighted: true }, { log: '$state', highlighted: true },
{ log: 'count', highlighted: false },
{ log: 2 } { log: 2 }
]); ]);
} }

Loading…
Cancel
Save