|
1 | | -import postcss from "postcss"; |
2 | 1 | import { readFileSync } from "node:fs"; |
3 | 2 | import path from "node:path"; |
| 3 | +import postcss from "postcss"; |
| 4 | +import prettier from "prettier"; |
4 | 5 | import { describe, it, expect } from "vitest"; |
5 | 6 |
|
6 | 7 | const plugin = (await import(".")).default; |
7 | 8 |
|
8 | | -async function run(input, output, opts = {}, postcssOpts = {}) { |
| 9 | +// We don't care about formatting differences, so normalize with prettier |
| 10 | +function format(css) { |
| 11 | + return prettier.format(css, { parser: "css" }); |
| 12 | +} |
| 13 | + |
| 14 | +async function run(input, output, opts, postcssOpts = {}) { |
9 | 15 | let result = await postcss([plugin(opts)]).process(input, postcssOpts); |
10 | | - expect(result.css).toEqual(output); |
| 16 | + expect(format(result.css)).toEqual(format(output)); |
11 | 17 | expect(result.warnings()).toHaveLength(0); |
12 | 18 | } |
13 | 19 |
|
14 | 20 | describe("postcss-assign-layer", () => { |
15 | | - it("does the thing", async () => { |
| 21 | + it("adds component layer to module.css files by default", async () => { |
16 | 22 | const filePath = path.resolve("test/fixtures/component.module.css"); |
17 | 23 | const file = readFileSync(filePath, "utf-8"); |
18 | 24 |
|
19 | 25 | await run( |
20 | 26 | file, |
21 | | - "@layer components {a {\n color: BurlyWood;\n}\n}\n", |
22 | | - {}, |
| 27 | + "@layer components { a { color: BurlyWood; } }", |
| 28 | + undefined, |
23 | 29 | { |
24 | 30 | from: filePath, |
25 | 31 | } |
|
0 commit comments