-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.test.ts
108 lines (92 loc) · 1.89 KB
/
index.test.ts
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
import postcss, { Root } from "postcss";
import variableCompress, { VariableCompressParameters } from "./index";
async function run(
input: string | { toString(): string } | Root,
output: string,
preserveVariables?: VariableCompressParameters[],
history?: string | boolean
) {
let result = await postcss([variableCompress(preserveVariables, history)])
.process(input, {
from: undefined,
});
expect(result.css).toEqual(output);
expect(result.warnings()).toHaveLength(0);
}
it("Shorten css variables", async () => {
await run(
`:root {
--first-color: #16f;
--second-color: #ff7;
--2: #000;
}
#firstParagraph {
background-color: var(--first-color);
color: var(--second-color);
}
#secondParagraph {
background-color: var(--second-color);
color: var(--first-color);
}
#container {
--first-color: #290;
}
#thirdParagraph {
background-color: var(--first-color);
color: var(--second-color);
}
.section-title {
color: var(--primary-color, var(--black, #222));
}
code {
--5: #555;
}`,
`:root {
--0: #16f;
--1: #ff7;
--2: #000;
}
#firstParagraph {
background-color: var(--0);
color: var(--1);
}
#secondParagraph {
background-color: var(--1);
color: var(--0);
}
#container {
--0: #290;
}
#thirdParagraph {
background-color: var(--0);
color: var(--1);
}
.section-title {
color: var(--primary-color, var(--3, #222));
}
code {
--5: #555;
}`,
[
"--primary-color",
"2",
(e: string | string[]) => e.includes("special"),
(e: string) => e === "--5",
]
);
});
it("Support reloading. Now the plugin will reset mapped variables",
async () => {
await run(
`:root{--first-color: #16f;--second-color: #ff7;}`,
`:root{--0: #16f;--1: #ff7;}`,
[],
"./build-history-folder"
);
await run(
`:root{--second-color: #ff7;--first-color: #16f;}`,
`:root{--1: #ff7;--0: #16f;}`,
[],
"./build-history-folder"
);
});