Skip to content

Commit 3c1de87

Browse files
committed
Expand test cases
1 parent 4e89e5e commit 3c1de87

File tree

3 files changed

+92
-2
lines changed

3 files changed

+92
-2
lines changed

index.test.mjs

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,100 @@ async function run(input, output, opts, postcssOpts = {}) {
1818
}
1919

2020
describe("postcss-assign-layer", () => {
21-
it("adds component layer to module.css files by default", async () => {
21+
it("adds component layer to entire *.module.css file by default", async () => {
2222
const filePath = path.resolve("test/fixtures/component.module.css");
2323
const file = readFileSync(filePath, "utf-8");
24+
await run(
25+
file,
26+
`@layer components {
27+
a {
28+
color: BurlyWood;
29+
}
30+
31+
i {
32+
color: WhiteSmoke;
33+
}
34+
}`,
35+
undefined,
36+
{
37+
from: filePath,
38+
}
39+
);
40+
});
41+
42+
it("allows customizing the layer name layer to module.css files by default", async () => {
43+
const filePath = path.resolve("test/fixtures/component.module.css");
44+
const file = readFileSync(filePath, "utf-8");
45+
await run(
46+
file,
47+
`@layer custom {
48+
a {
49+
color: BurlyWood;
50+
}
2451
52+
i {
53+
color: WhiteSmoke;
54+
}
55+
}`,
56+
{ layerName: "custom" },
57+
{
58+
from: filePath,
59+
}
60+
);
61+
});
62+
63+
it("does not apply to non-module css files by default", async () => {
64+
const filePath = path.resolve("test/fixtures/base.css");
65+
const file = readFileSync(filePath, "utf-8");
2566
await run(
2667
file,
27-
"@layer components { a { color: BurlyWood; } }",
68+
`a {
69+
color: FireBrick;
70+
}`,
2871
undefined,
2972
{
3073
from: filePath,
3174
}
3275
);
3376
});
77+
78+
it("allows specifying files with include pattern", async () => {
79+
const filePath = path.resolve("test/fixtures/base.css");
80+
const file = readFileSync(filePath, "utf-8");
81+
await run(
82+
file,
83+
`@layer components {
84+
a {
85+
color: FireBrick;
86+
}
87+
}`,
88+
{
89+
include: "**/base.css",
90+
},
91+
{
92+
from: filePath,
93+
}
94+
);
95+
});
96+
97+
it("does not process module file if other include pattern is provided", async () => {
98+
const filePath = path.resolve("test/fixtures/component.module.css");
99+
const file = readFileSync(filePath, "utf-8");
100+
await run(
101+
file,
102+
`a {
103+
color: BurlyWood;
104+
}
105+
106+
i {
107+
color: WhiteSmoke;
108+
}`,
109+
{
110+
include: "**/base.css",
111+
},
112+
{
113+
from: filePath,
114+
}
115+
);
116+
});
34117
});

test/fixtures/base.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
a {
2+
color: FireBrick;
3+
}

test/fixtures/component.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
a {
22
color: BurlyWood;
33
}
4+
5+
i {
6+
color: WhiteSmoke;
7+
}

0 commit comments

Comments
 (0)