Skip to content

Commit 4047913

Browse files
committed
fix tests
1 parent 798a495 commit 4047913

File tree

4 files changed

+77
-41
lines changed

4 files changed

+77
-41
lines changed

packages/svelte/tests/helpers.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,22 +198,38 @@ export const fragments = /** @type {'html' | 'tree'} */ (process.env.FRAGMENTS)
198198
*/
199199
export function normalise_trace_logs(logs) {
200200
let normalised = [];
201-
for (let i = 0; i < logs.length; i++) {
202-
const log = logs[i];
201+
202+
logs = logs.slice();
203+
204+
while (logs.length > 0) {
205+
const log = logs.shift();
206+
207+
if (log instanceof Error) {
208+
continue;
209+
}
203210

204211
if (typeof log === 'string' && log.includes('%c')) {
205212
const split = log.split('%c');
206-
console.log({ split });
207-
normalised.push({
208-
log: (split[0].length !== 0 ? split[0] : split[1]).trim(),
209-
highlighted: logs[i + 1] === 'color: CornflowerBlue; font-weight: bold'
210-
});
211-
i++;
212-
} else if (log instanceof Error) {
213-
continue;
213+
214+
const first = /** @type {string} */ (split.shift()).trim();
215+
if (first) normalised.push({ log: first });
216+
217+
while (split.length > 0) {
218+
const log = /** @type {string} */ (split.shift()).trim();
219+
const highlighted = logs.shift() === 'color: CornflowerBlue; font-weight: bold';
220+
221+
// omit timings, as they will differ between runs
222+
if (/\(.+ms\)/.test(log)) continue;
223+
224+
normalised.push({
225+
log,
226+
highlighted
227+
});
228+
}
214229
} else {
215230
normalised.push({ log });
216231
}
217232
}
233+
218234
return normalised;
219235
}

packages/svelte/tests/runtime-runes/samples/inspect-trace-nested/_config.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ export default test({
1111
// initial log, everything is highlighted
1212

1313
assert.deepEqual(normalise_trace_logs(logs), [
14-
{ log: 'iife', highlighted: false },
15-
{ log: 'count — $state', highlighted: true },
14+
{ log: 'iife' },
15+
{ log: '$state', highlighted: true },
16+
{ log: 'count', highlighted: false },
1617
{ log: 0 },
17-
{ log: 'effect', highlighted: false }
18+
{ log: 'effect' }
1819
]);
1920

2021
logs.length = 0;
@@ -24,10 +25,11 @@ export default test({
2425
flushSync();
2526

2627
assert.deepEqual(normalise_trace_logs(logs), [
27-
{ log: 'iife', highlighted: false },
28-
{ log: 'count — $state', highlighted: true },
28+
{ log: 'iife' },
29+
{ log: '$state', highlighted: true },
30+
{ log: 'count', highlighted: false },
2931
{ log: 1 },
30-
{ log: 'effect', highlighted: false }
32+
{ log: 'effect' }
3133
]);
3234
}
3335
});

packages/svelte/tests/runtime-runes/samples/inspect-trace-reassignment/_config.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ export default test({
1111
// initial log, everything is highlighted
1212

1313
assert.deepEqual(normalise_trace_logs(logs), [
14-
{ log: 'effect', highlighted: false },
15-
{ log: 'checked — $state', highlighted: true },
14+
{ log: 'effect' },
15+
{ log: '$state', highlighted: true },
16+
{ log: 'checked', highlighted: false },
1617
{ log: false }
1718
]);
1819

@@ -29,20 +30,26 @@ export default test({
2930
// checked changed, effect reassign state, values should be correct and be correctly highlighted
3031

3132
assert.deepEqual(normalise_trace_logs(logs), [
32-
{ log: 'effect', highlighted: false },
33-
{ log: 'checked — $state', highlighted: true },
33+
{ log: 'effect' },
34+
{ log: '$state', highlighted: true },
35+
{ log: 'checked', highlighted: false },
3436
{ log: true },
35-
{ log: 'count — $state', highlighted: true },
37+
{ log: '$state', highlighted: true },
38+
{ log: 'count', highlighted: false },
3639
{ log: 1 },
37-
{ log: 'effect', highlighted: false },
38-
{ log: 'checked — $state', highlighted: false },
40+
{ log: 'effect' },
41+
{ log: '$state', highlighted: false },
42+
{ log: 'checked', highlighted: false },
3943
{ log: true },
40-
{ log: 'count — $state', highlighted: true },
44+
{ log: '$state', highlighted: true },
45+
{ log: 'count', highlighted: false },
4146
{ log: 2 },
42-
{ log: 'effect', highlighted: false },
43-
{ log: 'checked — $state', highlighted: false },
47+
{ log: 'effect' },
48+
{ log: '$state', highlighted: false },
49+
{ log: 'checked', highlighted: false },
4450
{ log: true },
45-
{ log: 'count — $state', highlighted: true },
51+
{ log: '$state', highlighted: true },
52+
{ log: 'count', highlighted: false },
4653
{ log: 3 }
4754
]);
4855
}

packages/svelte/tests/runtime-runes/samples/inspect-trace/_config.js

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ export default test({
1111
// initial log, everything is highlighted
1212

1313
assert.deepEqual(normalise_trace_logs(logs), [
14-
{ log: 'effect', highlighted: false },
14+
{ log: 'effect' },
1515
{ log: '$derived', highlighted: true },
16+
{ log: 'double', highlighted: false },
1617
{ log: 0 },
17-
{ log: 'count — $state', highlighted: true },
18+
{ log: '$state', highlighted: true },
19+
{ log: 'count', highlighted: false },
1820
{ log: 0 },
19-
{ log: 'checked — $state', highlighted: true },
21+
{ log: '$state', highlighted: true },
22+
{ log: 'checked', highlighted: false },
2023
{ log: false }
2124
]);
2225

@@ -29,12 +32,15 @@ export default test({
2932
// count changed, derived and state are highlighted, last state is not
3033

3134
assert.deepEqual(normalise_trace_logs(logs), [
32-
{ log: 'effect', highlighted: false },
33-
{ log: 'double — $derived', highlighted: true },
35+
{ log: 'effect' },
36+
{ log: '$derived', highlighted: true },
37+
{ log: 'double', highlighted: false },
3438
{ log: 2 },
35-
{ log: 'count — $state', highlighted: true },
39+
{ log: '$state', highlighted: true },
40+
{ log: 'count', highlighted: false },
3641
{ log: 1 },
37-
{ log: 'checked — $state', highlighted: false },
42+
{ log: '$state', highlighted: false },
43+
{ log: 'checked', highlighted: false },
3844
{ log: false }
3945
]);
4046

@@ -47,12 +53,15 @@ export default test({
4753
// checked changed, last state is highlighted, first two are not
4854

4955
assert.deepEqual(normalise_trace_logs(logs), [
50-
{ log: 'effect', highlighted: false },
51-
{ log: 'double — $derived', highlighted: false },
56+
{ log: 'effect' },
57+
{ log: '$derived', highlighted: false },
58+
{ log: 'double', highlighted: false },
5259
{ log: 2 },
53-
{ log: 'count — $state', highlighted: false },
60+
{ log: '$state', highlighted: false },
61+
{ log: 'count', highlighted: false },
5462
{ log: 1 },
55-
{ log: 'checked — $state', highlighted: true },
63+
{ log: '$state', highlighted: true },
64+
{ log: 'checked', highlighted: false },
5665
{ log: true }
5766
]);
5867

@@ -64,10 +73,12 @@ export default test({
6473
// count change and derived it's >=4, checked is not in the dependencies anymore
6574

6675
assert.deepEqual(normalise_trace_logs(logs), [
67-
{ log: 'effect', highlighted: false },
68-
{ log: 'double — $derived', highlighted: true },
76+
{ log: 'effect' },
77+
{ log: '$derived', highlighted: true },
78+
{ log: 'double', highlighted: false },
6979
{ log: 4 },
70-
{ log: 'count — $state', highlighted: true },
80+
{ log: '$state', highlighted: true },
81+
{ log: 'count', highlighted: false },
7182
{ log: 2 }
7283
]);
7384
}

0 commit comments

Comments
 (0)