-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathtest.js
111 lines (102 loc) · 3.44 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const assert = require("assert");
const path = require("path");
const plugin = require("./");
const { receiveMessageOnPort } = require("worker_threads");
describe("styled-jsx-plugin-postcss", () => {
const compileEnvs = ["process", "worker"];
compileEnvs.forEach((compileEnv) => {
describe(`Compiling using a ${compileEnv}`, () => {
it("applies browser list and preset-env features", () => {
assert.strictEqual(
plugin(
"p { color: color-mod(red alpha(90%)); & img { display: block } }",
{ compileEnv }
),
"p.plugin { color: rgba(255, 0, 0, 0.9) }\np.plugin img.plugin { display: block }"
);
});
it("applies plugins", () => {
assert.strictEqual(
plugin("p { font-size: calc(2 * 20px); }", { compileEnv }),
"p.plugin { font-size: 40px; }"
);
});
it("works with placeholders", () => {
assert.strictEqual(
plugin(
"p { color: %%styled-jsx-placeholder-0%%; & img { display: block; } } %%styled-jsx-placeholder-1%%",
{ compileEnv }
),
"p.plugin { color: %%styled-jsx-placeholder-0%% } p.plugin img.plugin { display: block; } %%styled-jsx-placeholder-1%%"
);
});
it("works with @import", () => {
assert.strictEqual(
plugin('@import "./fixtures/fixture.css"; p { color: red }', {
compileEnv,
}),
"div.plugin { color: red; } p.plugin { color: red }"
);
});
it("works with quotes and other characters", () => {
assert.strictEqual(
plugin(
`@import "./fixtures/fixture.css"; * { color: red; font-family: 'Times New Roman'; }
li:after{ content: "!@#$%^&*()_+"}
ul li:before{ content: "{res:{res:'korea'}}"; }`,
{ compileEnv }
),
`div.plugin { color: red; } *.plugin { color: red; font-family: 'Times New Roman'; } li:after.plugin{ content: "!@#$%^&*()_+"} ul.plugin li:before.plugin{ content: "{res:{res:'korea'}}"; }`
);
});
it("throws with invalid css", () => {
assert.throws(
() => {
plugin('a {\n content: "\n}', { compileEnv });
},
{
name: "Error",
message: /postcss failed with CssSyntaxError: <css input>:2:12: Unclosed string/,
}
);
});
it("throws with invalid config", () => {
assert.throws(
() => {
plugin(
"p { color: color-mod(red alpha(90%)); & img { display: block } }",
{
path: path.resolve("./fixtures/fixture-invalid-config"),
compileEnv,
}
);
},
{
name: "Error",
message: /postcss failed with TypeError: Invalid PostCSS Plugin found at: plugins\[0]/,
}
);
});
if (
compileEnv === "worker" &&
typeof receiveMessageOnPort !== "undefined"
) {
it("worker mode timeouts after 3s", () => {
assert.throws(
() => {
plugin("p { color: red; }", {
path: path.resolve("fixtures/timeout"),
compileEnv,
lockTimeout: 3000,
});
},
{
name: "Error",
message: /postcss is taking more than/,
}
);
});
}
});
});
});