Skip to content

Commit 7c10b23

Browse files
committed
simplify
1 parent 03273b7 commit 7c10b23

File tree

2 files changed

+50
-62
lines changed

2 files changed

+50
-62
lines changed

packages/svelte/tests/html_equal.js

Lines changed: 49 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -121,63 +121,53 @@ export function normalize_new_line(html) {
121121
return html.replace(/\r\n/g, '\n');
122122
}
123123

124-
export function setup_html_equal() {
125-
/**
126-
* @param {string} actual
127-
* @param {string} expected
128-
* @param {string} [message]
129-
*/
130-
const assert_html_equal = (actual, expected, message) => {
131-
try {
132-
assert.deepEqual(normalize_html(window, actual), normalize_html(window, expected), message);
133-
} catch (e) {
134-
if (Error.captureStackTrace)
135-
Error.captureStackTrace(/** @type {Error} */ (e), assert_html_equal);
136-
throw e;
137-
}
138-
};
139-
140-
/**
141-
*
142-
* @param {string} actual
143-
* @param {string} expected
144-
* @param {{ preserveComments?: boolean, withoutNormalizeHtml?: boolean }} param2
145-
* @param {string} [message]
146-
*/
147-
const assert_html_equal_with_options = (
148-
actual,
149-
expected,
150-
{ preserveComments, withoutNormalizeHtml },
151-
message
152-
) => {
153-
try {
154-
assert.deepEqual(
155-
withoutNormalizeHtml
156-
? normalize_new_line(actual.trim()).replace(
157-
/(<!(--)?.*?\2>)/g,
158-
preserveComments !== false ? '$1' : ''
159-
)
160-
: normalize_html(window, actual.trim(), { preserveComments }),
161-
withoutNormalizeHtml
162-
? normalize_new_line(expected.trim()).replace(
163-
/(<!(--)?.*?\2>)/g,
164-
preserveComments !== false ? '$1' : ''
165-
)
166-
: normalize_html(window, expected.trim(), { preserveComments }),
167-
message
168-
);
169-
} catch (e) {
170-
if (Error.captureStackTrace)
171-
Error.captureStackTrace(/** @type {Error} */ (e), assert_html_equal_with_options);
172-
throw e;
173-
}
174-
};
175-
176-
return {
177-
assert_html_equal,
178-
assert_html_equal_with_options
179-
};
180-
}
124+
/**
125+
* @param {string} actual
126+
* @param {string} expected
127+
* @param {string} [message]
128+
*/
129+
export const assert_html_equal = (actual, expected, message) => {
130+
try {
131+
assert.deepEqual(normalize_html(window, actual), normalize_html(window, expected), message);
132+
} catch (e) {
133+
if (Error.captureStackTrace)
134+
Error.captureStackTrace(/** @type {Error} */ (e), assert_html_equal);
135+
throw e;
136+
}
137+
};
181138

182-
// Common case without options
183-
export const { assert_html_equal, assert_html_equal_with_options } = setup_html_equal();
139+
/**
140+
*
141+
* @param {string} actual
142+
* @param {string} expected
143+
* @param {{ preserveComments?: boolean, withoutNormalizeHtml?: boolean }} param2
144+
* @param {string} [message]
145+
*/
146+
export const assert_html_equal_with_options = (
147+
actual,
148+
expected,
149+
{ preserveComments, withoutNormalizeHtml },
150+
message
151+
) => {
152+
try {
153+
assert.deepEqual(
154+
withoutNormalizeHtml
155+
? normalize_new_line(actual.trim()).replace(
156+
/(<!(--)?.*?\2>)/g,
157+
preserveComments !== false ? '$1' : ''
158+
)
159+
: normalize_html(window, actual.trim(), { preserveComments }),
160+
withoutNormalizeHtml
161+
? normalize_new_line(expected.trim()).replace(
162+
/(<!(--)?.*?\2>)/g,
163+
preserveComments !== false ? '$1' : ''
164+
)
165+
: normalize_html(window, expected.trim(), { preserveComments }),
166+
message
167+
);
168+
} catch (e) {
169+
if (Error.captureStackTrace)
170+
Error.captureStackTrace(/** @type {Error} */ (e), assert_html_equal_with_options);
171+
throw e;
172+
}
173+
};

packages/svelte/tests/runtime-legacy/shared.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { flushSync, hydrate, mount, unmount } from 'svelte';
77
import { render } from 'svelte/server';
88
import { afterAll, assert, beforeAll } from 'vitest';
99
import { compile_directory, fragments } from '../helpers.js';
10-
import { setup_html_equal } from '../html_equal.js';
10+
import { assert_html_equal, assert_html_equal_with_options } from '../html_equal.js';
1111
import { raf } from '../animation-helpers.js';
1212
import type { CompileOptions } from '#compiler';
1313
import { suite_with_variants, type BaseTest } from '../suite.js';
@@ -86,8 +86,6 @@ function unhandled_rejection_handler(err: Error) {
8686

8787
const listeners = process.rawListeners('unhandledRejection');
8888

89-
const { assert_html_equal, assert_html_equal_with_options } = setup_html_equal();
90-
9189
beforeAll(() => {
9290
// @ts-expect-error TODO huh?
9391
process.prependListener('unhandledRejection', unhandled_rejection_handler);

0 commit comments

Comments
 (0)