pull/16056/head
Rich Harris 4 months ago
parent 03273b7879
commit 7c10b237d1

@ -121,63 +121,53 @@ export function normalize_new_line(html) {
return html.replace(/\r\n/g, '\n'); return html.replace(/\r\n/g, '\n');
} }
export function setup_html_equal() { /**
/** * @param {string} actual
* @param {string} actual * @param {string} expected
* @param {string} expected * @param {string} [message]
* @param {string} [message] */
*/ export const assert_html_equal = (actual, expected, message) => {
const assert_html_equal = (actual, expected, message) => { try {
try { assert.deepEqual(normalize_html(window, actual), normalize_html(window, expected), message);
assert.deepEqual(normalize_html(window, actual), normalize_html(window, expected), message); } catch (e) {
} catch (e) { if (Error.captureStackTrace)
if (Error.captureStackTrace) Error.captureStackTrace(/** @type {Error} */ (e), assert_html_equal);
Error.captureStackTrace(/** @type {Error} */ (e), assert_html_equal); throw e;
throw e; }
} };
};
/**
*
* @param {string} actual
* @param {string} expected
* @param {{ preserveComments?: boolean, withoutNormalizeHtml?: boolean }} param2
* @param {string} [message]
*/
const assert_html_equal_with_options = (
actual,
expected,
{ preserveComments, withoutNormalizeHtml },
message
) => {
try {
assert.deepEqual(
withoutNormalizeHtml
? normalize_new_line(actual.trim()).replace(
/(<!(--)?.*?\2>)/g,
preserveComments !== false ? '$1' : ''
)
: normalize_html(window, actual.trim(), { preserveComments }),
withoutNormalizeHtml
? normalize_new_line(expected.trim()).replace(
/(<!(--)?.*?\2>)/g,
preserveComments !== false ? '$1' : ''
)
: normalize_html(window, expected.trim(), { preserveComments }),
message
);
} catch (e) {
if (Error.captureStackTrace)
Error.captureStackTrace(/** @type {Error} */ (e), assert_html_equal_with_options);
throw e;
}
};
return {
assert_html_equal,
assert_html_equal_with_options
};
}
// Common case without options /**
export const { assert_html_equal, assert_html_equal_with_options } = setup_html_equal(); *
* @param {string} actual
* @param {string} expected
* @param {{ preserveComments?: boolean, withoutNormalizeHtml?: boolean }} param2
* @param {string} [message]
*/
export const assert_html_equal_with_options = (
actual,
expected,
{ preserveComments, withoutNormalizeHtml },
message
) => {
try {
assert.deepEqual(
withoutNormalizeHtml
? normalize_new_line(actual.trim()).replace(
/(<!(--)?.*?\2>)/g,
preserveComments !== false ? '$1' : ''
)
: normalize_html(window, actual.trim(), { preserveComments }),
withoutNormalizeHtml
? normalize_new_line(expected.trim()).replace(
/(<!(--)?.*?\2>)/g,
preserveComments !== false ? '$1' : ''
)
: normalize_html(window, expected.trim(), { preserveComments }),
message
);
} catch (e) {
if (Error.captureStackTrace)
Error.captureStackTrace(/** @type {Error} */ (e), assert_html_equal_with_options);
throw e;
}
};

@ -7,7 +7,7 @@ import { flushSync, hydrate, mount, unmount } from 'svelte';
import { render } from 'svelte/server'; import { render } from 'svelte/server';
import { afterAll, assert, beforeAll } from 'vitest'; import { afterAll, assert, beforeAll } from 'vitest';
import { compile_directory, fragments } from '../helpers.js'; import { compile_directory, fragments } from '../helpers.js';
import { setup_html_equal } from '../html_equal.js'; import { assert_html_equal, assert_html_equal_with_options } from '../html_equal.js';
import { raf } from '../animation-helpers.js'; import { raf } from '../animation-helpers.js';
import type { CompileOptions } from '#compiler'; import type { CompileOptions } from '#compiler';
import { suite_with_variants, type BaseTest } from '../suite.js'; import { suite_with_variants, type BaseTest } from '../suite.js';
@ -86,8 +86,6 @@ function unhandled_rejection_handler(err: Error) {
const listeners = process.rawListeners('unhandledRejection'); const listeners = process.rawListeners('unhandledRejection');
const { assert_html_equal, assert_html_equal_with_options } = setup_html_equal();
beforeAll(() => { beforeAll(() => {
// @ts-expect-error TODO huh? // @ts-expect-error TODO huh?
process.prependListener('unhandledRejection', unhandled_rejection_handler); process.prependListener('unhandledRejection', unhandled_rejection_handler);

Loading…
Cancel
Save