Skip to content
This repository was archived by the owner on Sep 25, 2024. It is now read-only.

Commit aac6a32

Browse files
committed
feat: add test
1 parent 4481d37 commit aac6a32

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-0
lines changed

tests/assets/class.module.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.error {
2+
color: red;
3+
}
4+
.success {
5+
color: green;
6+
}

tests/assets/style.module.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
section {
2+
padding: 10px;
3+
}
4+
.error {
5+
color: red;
6+
}
7+
.success-message {
8+
color: green;
9+
}

tests/compiler.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import path from 'node:path';
2+
import { preprocess } from 'svelte/compiler';
3+
import { cssModules } from '../src';
4+
5+
type Params = {
6+
source: string;
7+
preprocessOptions: Parameters<typeof preprocess>[2];
8+
};
9+
10+
export async function compiler({
11+
source,
12+
preprocessOptions,
13+
}: Params) {
14+
const { code } = await preprocess(
15+
source,
16+
[cssModules()],
17+
preprocessOptions,
18+
);
19+
20+
return code;
21+
};

tests/test1/Input.svelte

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
import s from '../assets/class.module.css';
3+
</script>
4+
5+
<div class={s.error}>
6+
hello
7+
</div>
8+
9+
<div class={s.success}>
10+
world
11+
</div>

tests/test1/test1.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import fs from 'node:fs/promises';
2+
import path from 'node:path';
3+
import { expect, it } from 'vitest';
4+
import { compiler } from '../compiler';
5+
6+
function resolve(file: string) {
7+
return path.resolve(__dirname, file);
8+
}
9+
10+
it('test0', async () => {
11+
const filename = resolve('Input.svelte');
12+
13+
const source = await fs.readFile(filename, 'utf-8');
14+
15+
const code = await compiler({
16+
source,
17+
preprocessOptions: { filename },
18+
});
19+
20+
await expect(code).toMatchFileSnapshot('./Output.svelte');
21+
});

0 commit comments

Comments
 (0)