Skip to content

Commit d54216b

Browse files
test: ICSS support (#813)
1 parent 0a68bb4 commit d54216b

File tree

12 files changed

+243
-0
lines changed

12 files changed

+243
-0
lines changed

test/__snapshots__/icss.test.js.snap

+174
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`ICSS case duplicate-export: errors 1`] = `Array []`;
4+
5+
exports[`ICSS case duplicate-export: locals 1`] = `
6+
Object {
7+
"_test": "_right_value",
8+
}
9+
`;
10+
11+
exports[`ICSS case duplicate-export: module (evaluated) 1`] = `
12+
Array [
13+
Array [
14+
1,
15+
"
16+
",
17+
"",
18+
],
19+
]
20+
`;
21+
22+
exports[`ICSS case duplicate-export: warnings 1`] = `Array []`;
23+
24+
exports[`ICSS case duplicate-export-in-multiple-export: errors 1`] = `Array []`;
25+
26+
exports[`ICSS case duplicate-export-in-multiple-export: locals 1`] = `
27+
Object {
28+
"_test": "_right_value",
29+
}
30+
`;
31+
32+
exports[`ICSS case duplicate-export-in-multiple-export: module (evaluated) 1`] = `
33+
Array [
34+
Array [
35+
1,
36+
"
37+
",
38+
"",
39+
],
40+
]
41+
`;
42+
43+
exports[`ICSS case duplicate-export-in-multiple-export: warnings 1`] = `Array []`;
44+
45+
exports[`ICSS case empty-export: errors 1`] = `Array []`;
46+
47+
exports[`ICSS case empty-export: locals 1`] = `undefined`;
48+
49+
exports[`ICSS case empty-export: module (evaluated) 1`] = `
50+
Array [
51+
Array [
52+
1,
53+
"
54+
",
55+
"",
56+
],
57+
]
58+
`;
59+
60+
exports[`ICSS case empty-export: warnings 1`] = `Array []`;
61+
62+
exports[`ICSS case empty-import: errors 1`] = `Array []`;
63+
64+
exports[`ICSS case empty-import: locals 1`] = `undefined`;
65+
66+
exports[`ICSS case empty-import: module (evaluated) 1`] = `
67+
Array [
68+
Array [
69+
1,
70+
"
71+
",
72+
"",
73+
],
74+
]
75+
`;
76+
77+
exports[`ICSS case empty-import: warnings 1`] = `Array []`;
78+
79+
exports[`ICSS case export: errors 1`] = `Array []`;
80+
81+
exports[`ICSS case export: locals 1`] = `
82+
Object {
83+
"_test": "_test",
84+
}
85+
`;
86+
87+
exports[`ICSS case export: module (evaluated) 1`] = `
88+
Array [
89+
Array [
90+
1,
91+
"
92+
",
93+
"",
94+
],
95+
]
96+
`;
97+
98+
exports[`ICSS case export: warnings 1`] = `Array []`;
99+
100+
exports[`ICSS case import: errors 1`] = `Array []`;
101+
102+
exports[`ICSS case import: locals 1`] = `
103+
Object {
104+
"primary-color": "red",
105+
}
106+
`;
107+
108+
exports[`ICSS case import: module (evaluated) 1`] = `
109+
Array [
110+
Array [
111+
2,
112+
"
113+
",
114+
"",
115+
],
116+
Array [
117+
1,
118+
".className {
119+
color: red;
120+
}
121+
",
122+
"",
123+
],
124+
]
125+
`;
126+
127+
exports[`ICSS case import: warnings 1`] = `Array []`;
128+
129+
exports[`ICSS case multiple-export: errors 1`] = `Array []`;
130+
131+
exports[`ICSS case multiple-export: locals 1`] = `
132+
Object {
133+
"_foo": "_bar",
134+
"_test": "_test",
135+
}
136+
`;
137+
138+
exports[`ICSS case multiple-export: module (evaluated) 1`] = `
139+
Array [
140+
Array [
141+
1,
142+
"
143+
",
144+
"",
145+
],
146+
]
147+
`;
148+
149+
exports[`ICSS case multiple-export: warnings 1`] = `Array []`;
150+
151+
exports[`ICSS case multiple-keys-values-in-export: errors 1`] = `Array []`;
152+
153+
exports[`ICSS case multiple-keys-values-in-export: locals 1`] = `
154+
Object {
155+
"_test": "_test",
156+
"_test1": "1",
157+
"_test2": "'string'",
158+
"_test3": "1px 2px 3px",
159+
"_test4": "1px 2px 3px, 1px 2px 3px",
160+
}
161+
`;
162+
163+
exports[`ICSS case multiple-keys-values-in-export: module (evaluated) 1`] = `
164+
Array [
165+
Array [
166+
1,
167+
"
168+
",
169+
"",
170+
],
171+
]
172+
`;
173+
174+
exports[`ICSS case multiple-keys-values-in-export: warnings 1`] = `Array []`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:export {
2+
_test: _test;
3+
}
4+
5+
:export {
6+
_test: _right_value;
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
:export {
2+
_test: _test;
3+
_test: _right_value;
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:export {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:import("./vars.css") {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:export {
2+
_test: _test
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
:import("./vars.css") {
2+
IMPORTED_NAME: primary-color;
3+
}
4+
5+
.className {
6+
color: IMPORTED_NAME;
7+
}
8+
9+
:export {
10+
primary-color: IMPORTED_NAME
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:export {
2+
primary-color: red;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:export {
2+
_test: _test
3+
}
4+
5+
:export {
6+
_foo: _bar
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:export {
2+
_test: _test;
3+
_test1: 1;
4+
_test2: 'string';
5+
_test3: 1px 2px 3px;
6+
_test4: 1px 2px 3px, 1px 2px 3px;
7+
}

test/helpers.js

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ function evaluated(output, modules, moduleId = 1) {
3434
const importedModule = modules.find((el) => {
3535
const modulePath = el.identifier.split('!').pop();
3636
const importedPaths = [
37+
'icss/tests-cases/import',
3738
'import',
3839
'import/node_modules',
3940
'url',

test/icss.test.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const path = require('path');
2+
const fs = require('fs');
3+
4+
const { webpack, evaluated } = require('./helpers');
5+
6+
const testCasesPath = path.join(__dirname, 'fixtures/icss/tests-cases');
7+
const testCases = fs.readdirSync(testCasesPath);
8+
9+
describe('ICSS', () => {
10+
testCases.forEach((name) => {
11+
it(`case ${name}`, async () => {
12+
const testId = `./icss/tests-cases/${name}/source.css`;
13+
const stats = await webpack(testId);
14+
const { modules } = stats.toJson();
15+
const module = modules.find((m) => m.id === testId);
16+
const evaluatedModule = evaluated(module.source, modules);
17+
18+
expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
19+
expect(evaluatedModule.locals).toMatchSnapshot('locals');
20+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
21+
expect(stats.compilation.errors).toMatchSnapshot('errors');
22+
});
23+
});
24+
});

0 commit comments

Comments
 (0)