From d6858a6838e22908169ef88043f1a8762a5f6153 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 20 Apr 2024 12:52:31 -0400 Subject: [PATCH] tidier output --- .../samples/ignore-mismatched-href/_config.js | 6 +++++- packages/svelte/tests/hydration/test.ts | 11 ++++++++++- packages/svelte/tests/runtime-browser/test.ts | 1 - 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/svelte/tests/hydration/samples/ignore-mismatched-href/_config.js b/packages/svelte/tests/hydration/samples/ignore-mismatched-href/_config.js index ce81251e5e..5ebdbb2680 100644 --- a/packages/svelte/tests/hydration/samples/ignore-mismatched-href/_config.js +++ b/packages/svelte/tests/hydration/samples/ignore-mismatched-href/_config.js @@ -11,5 +11,9 @@ export default test({ test(assert, target) { assert.equal(target.querySelector('a')?.getAttribute('href'), '/bar'); - } + }, + + errors: [ + 'Detected a href attribute value change during hydration. This will not be repaired during hydration, the href value that came from the server will be used. Related element:' + ] }); diff --git a/packages/svelte/tests/hydration/test.ts b/packages/svelte/tests/hydration/test.ts index 6884504718..9002f56d51 100644 --- a/packages/svelte/tests/hydration/test.ts +++ b/packages/svelte/tests/hydration/test.ts @@ -32,6 +32,7 @@ interface HydrationTest extends BaseTest { ) => void | Promise; before_test?: () => void; after_test?: () => void; + errors?: any[]; } function read(path: string): string | void { @@ -65,6 +66,7 @@ const { test, run } = suite(async (config, cwd) => { const snapshot = config.snapshot ? config.snapshot(target) : {}; const error = console.error; + const errors: any[] = []; let got_hydration_error = false; console.error = (message: any) => { if (typeof message === 'string' && message.startsWith('ERR_SVELTE_HYDRATION_MISMATCH')) { @@ -73,7 +75,7 @@ const { test, run } = suite(async (config, cwd) => { error(message); } } else { - error(message); + errors.push(message); } }; @@ -85,12 +87,19 @@ const { test, run } = suite(async (config, cwd) => { }); console.error = error; + if (config.expect_hydration_error) { assert.ok(got_hydration_error, 'Expected hydration error'); } else { assert.ok(!got_hydration_error, 'Unexpected hydration error'); } + if (config.errors) { + assert.deepEqual(errors, config.errors); + } else if (errors.length) { + throw new Error(`Unexpected errors: ${errors.join('\n')}`); + } + const expected = read(`${cwd}/_expected.html`) ?? rendered.html; assert_html_equal(target.innerHTML, expected); diff --git a/packages/svelte/tests/runtime-browser/test.ts b/packages/svelte/tests/runtime-browser/test.ts index b2df361aa5..d58f7e78cd 100644 --- a/packages/svelte/tests/runtime-browser/test.ts +++ b/packages/svelte/tests/runtime-browser/test.ts @@ -14,7 +14,6 @@ let browser: import('@playwright/test').Browser; beforeAll(async () => { browser = await chromium.launch(); - console.log('[runtime-browser] Launched browser'); }, 20000); afterAll(async () => {