Skip to content

Commit 2d5b51d

Browse files
committed
refactor(tests): extract common code into load function
The repetitive code for loading and preprocessing Svelte files in tests has been extracted into a separate async function named 'load'. This makes the test cases cleaner and easier to read.
1 parent 726fb56 commit 2d5b51d

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

mod_test.ts

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,34 @@ import { assertSnapshot } from "@std/testing/snapshot";
33
import { preprocess } from "svelte/compiler";
44
import { importCSSPreprocess } from "./mod.ts";
55

6+
async function load(_filename: string) {
7+
const filename = join(
8+
import.meta.dirname as string,
9+
_filename,
10+
);
11+
12+
const source = Deno.readTextFileSync(filename);
13+
const { code } = await preprocess(
14+
source,
15+
[importCSSPreprocess()],
16+
{ filename },
17+
);
18+
19+
return code;
20+
}
21+
622
Deno.test(
723
"example svelte main",
824
async function (t) {
9-
const filename = join(
10-
import.meta.dirname as string,
11-
"./test_project/Main.svelte",
12-
);
13-
const source = Deno.readTextFileSync(filename);
14-
const { code } = await preprocess(
15-
source,
16-
[importCSSPreprocess()],
17-
{ filename },
18-
);
19-
25+
const code = await load("./test_project/Main.svelte");
2026
await assertSnapshot(t, code);
2127
},
2228
);
29+
2330
Deno.test(
2431
"example svelte partial",
2532
async function (t) {
26-
const filename = join(
27-
import.meta.dirname as string,
28-
"./test_project/Partial.svelte",
29-
);
30-
const source = Deno.readTextFileSync(filename);
31-
const { code } = await preprocess(
32-
source,
33-
[importCSSPreprocess()],
34-
{ filename },
35-
);
36-
33+
const code = await load("./test_project/Partial.svelte");
3734
await assertSnapshot(t, code);
3835
},
3936
);

0 commit comments

Comments
 (0)