tidier output

pull/11265/head
Rich Harris 2 years ago
parent 0ce879837b
commit d6858a6838

@ -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:'
]
});

@ -32,6 +32,7 @@ interface HydrationTest extends BaseTest {
) => void | Promise<void>;
before_test?: () => void;
after_test?: () => void;
errors?: any[];
}
function read(path: string): string | void {
@ -65,6 +66,7 @@ const { test, run } = suite<HydrationTest>(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<HydrationTest>(async (config, cwd) => {
error(message);
}
} else {
error(message);
errors.push(message);
}
};
@ -85,12 +87,19 @@ const { test, run } = suite<HydrationTest>(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);

@ -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 () => {

Loading…
Cancel
Save