diff --git a/packages/svelte/tests/helpers.js b/packages/svelte/tests/helpers.js index e8c0f19c87..2d825dbb7c 100644 --- a/packages/svelte/tests/helpers.js +++ b/packages/svelte/tests/helpers.js @@ -198,22 +198,38 @@ export const fragments = /** @type {'html' | 'tree'} */ (process.env.FRAGMENTS) */ export function normalise_trace_logs(logs) { 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')) { const split = log.split('%c'); - console.log({ split }); - 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; + + const first = /** @type {string} */ (split.shift()).trim(); + if (first) normalised.push({ log: first }); + + while (split.length > 0) { + const log = /** @type {string} */ (split.shift()).trim(); + const highlighted = logs.shift() === 'color: CornflowerBlue; font-weight: bold'; + + // omit timings, as they will differ between runs + if (/\(.+ms\)/.test(log)) continue; + + normalised.push({ + log, + highlighted + }); + } } else { normalised.push({ log }); } } + return normalised; } diff --git a/packages/svelte/tests/runtime-runes/samples/inspect-trace-nested/_config.js b/packages/svelte/tests/runtime-runes/samples/inspect-trace-nested/_config.js index 489eccd1cb..5957d2cc6a 100644 --- a/packages/svelte/tests/runtime-runes/samples/inspect-trace-nested/_config.js +++ b/packages/svelte/tests/runtime-runes/samples/inspect-trace-nested/_config.js @@ -11,10 +11,11 @@ export default test({ // initial log, everything is highlighted assert.deepEqual(normalise_trace_logs(logs), [ - { log: 'iife', highlighted: false }, - { log: 'count — $state', highlighted: true }, + { log: 'iife' }, + { log: '$state', highlighted: true }, + { log: 'count', highlighted: false }, { log: 0 }, - { log: 'effect', highlighted: false } + { log: 'effect' } ]); logs.length = 0; @@ -24,10 +25,11 @@ export default test({ flushSync(); assert.deepEqual(normalise_trace_logs(logs), [ - { log: 'iife', highlighted: false }, - { log: 'count — $state', highlighted: true }, + { log: 'iife' }, + { log: '$state', highlighted: true }, + { log: 'count', highlighted: false }, { log: 1 }, - { log: 'effect', highlighted: false } + { log: 'effect' } ]); } }); diff --git a/packages/svelte/tests/runtime-runes/samples/inspect-trace-reassignment/_config.js b/packages/svelte/tests/runtime-runes/samples/inspect-trace-reassignment/_config.js index bfc5bb7c12..683f55f321 100644 --- a/packages/svelte/tests/runtime-runes/samples/inspect-trace-reassignment/_config.js +++ b/packages/svelte/tests/runtime-runes/samples/inspect-trace-reassignment/_config.js @@ -11,8 +11,9 @@ export default test({ // initial log, everything is highlighted assert.deepEqual(normalise_trace_logs(logs), [ - { log: 'effect', highlighted: false }, - { log: 'checked — $state', highlighted: true }, + { log: 'effect' }, + { log: '$state', highlighted: true }, + { log: 'checked', highlighted: false }, { log: false } ]); @@ -29,20 +30,26 @@ export default test({ // checked changed, effect reassign state, values should be correct and be correctly highlighted assert.deepEqual(normalise_trace_logs(logs), [ - { log: 'effect', highlighted: false }, - { log: 'checked — $state', highlighted: true }, + { log: 'effect' }, + { log: '$state', highlighted: true }, + { log: 'checked', highlighted: false }, { log: true }, - { log: 'count — $state', highlighted: true }, + { log: '$state', highlighted: true }, + { log: 'count', highlighted: false }, { log: 1 }, - { log: 'effect', highlighted: false }, - { log: 'checked — $state', highlighted: false }, + { log: 'effect' }, + { log: '$state', highlighted: false }, + { log: 'checked', highlighted: false }, { log: true }, - { log: 'count — $state', highlighted: true }, + { log: '$state', highlighted: true }, + { log: 'count', highlighted: false }, { log: 2 }, - { log: 'effect', highlighted: false }, - { log: 'checked — $state', highlighted: false }, + { log: 'effect' }, + { log: '$state', highlighted: false }, + { log: 'checked', highlighted: false }, { log: true }, - { log: 'count — $state', highlighted: true }, + { log: '$state', highlighted: true }, + { log: 'count', highlighted: false }, { log: 3 } ]); } diff --git a/packages/svelte/tests/runtime-runes/samples/inspect-trace/_config.js b/packages/svelte/tests/runtime-runes/samples/inspect-trace/_config.js index 9c545c43c7..8e9204c90f 100644 --- a/packages/svelte/tests/runtime-runes/samples/inspect-trace/_config.js +++ b/packages/svelte/tests/runtime-runes/samples/inspect-trace/_config.js @@ -11,12 +11,15 @@ export default test({ // initial log, everything is highlighted assert.deepEqual(normalise_trace_logs(logs), [ - { log: 'effect', highlighted: false }, + { log: 'effect' }, { log: '$derived', highlighted: true }, + { log: 'double', highlighted: false }, { log: 0 }, - { log: 'count — $state', highlighted: true }, + { log: '$state', highlighted: true }, + { log: 'count', highlighted: false }, { log: 0 }, - { log: 'checked — $state', highlighted: true }, + { log: '$state', highlighted: true }, + { log: 'checked', highlighted: false }, { log: false } ]); @@ -29,12 +32,15 @@ export default test({ // count changed, derived and state are highlighted, last state is not assert.deepEqual(normalise_trace_logs(logs), [ - { log: 'effect', highlighted: false }, - { log: 'double — $derived', highlighted: true }, + { log: 'effect' }, + { log: '$derived', highlighted: true }, + { log: 'double', highlighted: false }, { log: 2 }, - { log: 'count — $state', highlighted: true }, + { log: '$state', highlighted: true }, + { log: 'count', highlighted: false }, { log: 1 }, - { log: 'checked — $state', highlighted: false }, + { log: '$state', highlighted: false }, + { log: 'checked', highlighted: false }, { log: false } ]); @@ -47,12 +53,15 @@ export default test({ // checked changed, last state is highlighted, first two are not assert.deepEqual(normalise_trace_logs(logs), [ - { log: 'effect', highlighted: false }, - { log: 'double — $derived', highlighted: false }, + { log: 'effect' }, + { log: '$derived', highlighted: false }, + { log: 'double', highlighted: false }, { log: 2 }, - { log: 'count — $state', highlighted: false }, + { log: '$state', highlighted: false }, + { log: 'count', highlighted: false }, { log: 1 }, - { log: 'checked — $state', highlighted: true }, + { log: '$state', highlighted: true }, + { log: 'checked', highlighted: false }, { log: true } ]); @@ -64,10 +73,12 @@ export default test({ // 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: 'double — $derived', highlighted: true }, + { log: 'effect' }, + { log: '$derived', highlighted: true }, + { log: 'double', highlighted: false }, { log: 4 }, - { log: 'count — $state', highlighted: true }, + { log: '$state', highlighted: true }, + { log: 'count', highlighted: false }, { log: 2 } ]); }