Skip to content

Commit 53a7fe5

Browse files
refactor: modules option tests (#808)
1 parent b0db66f commit 53a7fe5

File tree

54 files changed

+1735
-515
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1735
-515
lines changed

test/__snapshots__/modules-option.test.js.snap

+1,581
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:local(.c1/*.c2*/.c3) { background: red; }

test/moduleTestCases/comments/source.css renamed to test/fixtures/modules/tests-cases/comments/source.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
*/
44

55
.bg {
6-
background-image: url(bg.jpg);
6+
background-image: url(./img.png);
77
}
88

99
/*
1010
* a ' below
11-
*/
11+
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
:local(.c2) {
2+
color: red;
3+
}
4+
5+
:local(.c4) {
6+
color: blue;
7+
}
8+
9+
.test{
10+
c: d
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:local(.c1) { composes: c2 from "./file.css"; b: 1; }
2+
:local(.c3) { composes: c1; b: 3; }
3+
:local(.c5) { composes: c2 c4 from "./file.css"; b: 5; }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
:local(.c-2) {
2+
color: red;
3+
}
4+
5+
:local(.c4) {
6+
color: blue;
7+
}
8+
9+
.test{
10+
c: d
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:local(.c1) { composes: c-2 from "./file.css"; b: 1; }
2+
:local(.c3) { composes: c1; b: 3; }
3+
:local(.c5) { composes: c-2 c4 from "./file.css"; b: 5; }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:local(.def1) {
2+
color: red;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:local(.def2) {
2+
color: blue;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
:local(.abc) {
2+
composes: def1 from "./file1.css";
3+
composes: def2 from "./file2.css";
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:local(.def) {
2+
color: red;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:local(.abc) {
2+
composes: def from "./file.css";
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:local(.c1) { a: 1; }
2+
:local(.c2) { composes: c1; b: 1; }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
:local(.className) { background: red; }
2+
:local(#someId) { background: green; }
3+
:local(.className .subClass) { color: green; }
4+
:local(#someId .subClass) { color: blue; }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:local(.abc) {
2+
color: red;
3+
}
4+
:local(.def) {
5+
composes: abc;
6+
background: green;
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:local(.c1[data-attr=".c2)]'"]:not(.c3):not(.c4)) {
2+
background: red;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.abc :local(.def) {
2+
color: red;
3+
}
4+
5+
:local .ghi .jkl {
6+
color: blue;
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.c1 :local .c2 .c3 :global .c4 :local .c5, .c6 :local .c7 { background: red; }
2+
.c8 { background: red; }
76.3 KB
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.a {
2+
background: url(./img.png);
3+
background: url("./img.png");
4+
background: url("./img img.png");
5+
background: url('./img img.png');
6+
background: url('./img.png');
7+
background: url("./img.png#?iefix");
8+
background: url("#hash");
9+
background: url("#");
10+
background: url(data:image/png;base64,AAA);
11+
background: url(http://example.com/image.jpg);
12+
background: url(//example.com/image.png);
13+
background: green url(data:image/png;base64,AAA) url(http://example.com/image.jpg) url(//example.com/image.png) url(./img.png) xyz;
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@value def: red;
2+
@value ghi: 1px solid black;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@value def: red;
2+
.ghi { color: def; }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@value def: red;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@value def from './file.css';
2+
.ghi { color: def; }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@value def: red;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@value def: green;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@value def as aaa from './file1.css';
2+
@value def as bbb from './file2.css';
3+
.ghi { background: aaa, bbb, def; }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@value color: red;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@value color from './file1.css';
2+
@value shadow: 0 0 color,0 0 color;
3+
.ghi { box-shadow: shadow; }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@value color: red;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@value color from './file1.css';
2+
@value shadow: 0 0 color ,0 0 color;
3+
.ghi { box-shadow: shadow; }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@value color: red;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@value color from './file1.css';
2+
@value shadow: 0 0 color, 0 0 color;
3+
.ghi { box-shadow: shadow; }

test/helpers.js

+11
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ function evaluated(output, modules, moduleId = 1) {
3838
'import/node_modules',
3939
'url',
4040
'url/node_modules',
41+
'modules/tests-cases/urls',
42+
'modules/tests-cases/comments',
43+
'modules/tests-cases/values-3',
44+
'modules/tests-cases/values-4',
45+
'modules/tests-cases/values-5',
46+
'modules/tests-cases/values-6',
47+
'modules/tests-cases/values-7',
48+
'modules/tests-cases/composes-1',
49+
'modules/tests-cases/composes-2',
50+
'modules/tests-cases/composes-multiple',
51+
'modules/tests-cases/composes-with-importing',
4152
].map((importedPath) =>
4253
path.resolve(__dirname, `./fixtures/${importedPath}`, module)
4354
);

test/local.test.js

-153
Original file line numberDiff line numberDiff line change
@@ -34,159 +34,6 @@ describe('local', () => {
3434
subClass: '_1s1VsToXFz17cPAltMg7jz',
3535
}
3636
);
37-
testLocal(
38-
'mode switching',
39-
'.c1 :local .c2 .c3 :global .c4 :local .c5, .c6 :local .c7 { background: red; }\n.c8 { background: red; }',
40-
[
41-
[
42-
1,
43-
'.c1 ._c2 ._c3 .c4 ._c5, .c6 ._c7 { background: red; }\n.c8 { background: red; }',
44-
'',
45-
],
46-
],
47-
{
48-
c2: '_c2',
49-
c3: '_c3',
50-
c5: '_c5',
51-
c7: '_c7',
52-
},
53-
'?localIdentName=_[local]'
54-
);
55-
testLocal(
56-
'comment in local',
57-
':local(.c1/*.c2*/.c3) { background: red; }',
58-
[[1, '._c1/*.c2*/._c3 { background: red; }', '']],
59-
{
60-
c1: '_c1',
61-
c3: '_c3',
62-
},
63-
'?localIdentName=_[local]'
64-
);
65-
testLocal(
66-
'comment in local',
67-
':local(.c1/*.c2*/.c3) { background: red; }',
68-
[[1, '._c1/*.c2*/._c3 { background: red; }', '']],
69-
{
70-
c1: '_c1',
71-
c3: '_c3',
72-
},
73-
'?localIdentName=_[local]'
74-
);
75-
testLocal(
76-
'strings in local',
77-
':local(.c1[data-attr=".c2)]\'"]:not(.c3):not(.c4)) { background: red; }',
78-
[
79-
[
80-
1,
81-
'._c1[data-attr=".c2)]\'"]:not(._c3):not(._c4) { background: red; }',
82-
'',
83-
],
84-
],
85-
{
86-
c1: '_c1',
87-
c3: '_c3',
88-
c4: '_c4',
89-
},
90-
'?localIdentName=_[local]'
91-
);
92-
93-
testLocal(
94-
'composes class simple',
95-
':local(.c1) { a: 1; }\n:local(.c2) { composes: c1; b: 1; }',
96-
[[1, '._c1 { a: 1; }\n._c2 { b: 1; }', '']],
97-
{
98-
c1: '_c1',
99-
c2: '_c2 _c1',
100-
},
101-
'?localIdentName=_[local]'
102-
);
103-
testLocal(
104-
'composes class from module',
105-
[
106-
':local(.c1) { composes: c2 from "./module"; b: 1; }',
107-
':local(.c3) { composes: c1; b: 3; }',
108-
':local(.c5) { composes: c2 c4 from "./module"; b: 5; }',
109-
].join('\n'),
110-
[
111-
[2, '.test{c: d}', ''],
112-
[
113-
1,
114-
['._c1 { b: 1; }', '._c3 { b: 3; }', '._c5 { b: 5; }'].join('\n'),
115-
'',
116-
],
117-
],
118-
{
119-
c1: '_c1 imported-c2',
120-
c3: '_c3 _c1 imported-c2',
121-
c5: '_c5 imported-c2 imported-c4',
122-
},
123-
'?localIdentName=_[local]',
124-
{
125-
'./module': (() => {
126-
const r = [[2, '.test{c: d}', '']];
127-
r.locals = {
128-
c2: 'imported-c2',
129-
c4: 'imported-c4',
130-
};
131-
return r;
132-
})(),
133-
}
134-
);
135-
testLocal(
136-
'composes class with hyphen from module',
137-
[
138-
':local(.c1) { composes: c-2 from "./module"; b: 1; }',
139-
':local(.c3) { composes: c1; b: 3; }',
140-
':local(.c5) { composes: c-2 c4 from "./module"; b: 5; }',
141-
].join('\n'),
142-
[
143-
[2, '.test{c: d}', ''],
144-
[
145-
1,
146-
['._c1 { b: 1; }', '._c3 { b: 3; }', '._c5 { b: 5; }'].join('\n'),
147-
'',
148-
],
149-
],
150-
{
151-
c1: '_c1 imported-c-2',
152-
c3: '_c3 _c1 imported-c-2',
153-
c5: '_c5 imported-c-2 imported-c4',
154-
},
155-
'?localIdentName=_[local]',
156-
{
157-
'./module': (() => {
158-
const r = [[2, '.test{c: d}', '']];
159-
r.locals = {
160-
'c-2': 'imported-c-2',
161-
c4: 'imported-c4',
162-
};
163-
return r;
164-
})(),
165-
}
166-
);
167-
testLocal(
168-
'composes class from module with import',
169-
[
170-
'@import url("module");',
171-
':local(.c1) { composes: c2 c3 from "./module"; composes: c4 from "./module"; b: 1; }',
172-
].join('\n'),
173-
[[2, '.test{c: d}', ''], [1, '._c1 { b: 1; }', '']],
174-
{
175-
c1: '_c1 imported-c2 imported-c3 imported-c4',
176-
},
177-
'?localIdentName=_[local]',
178-
{
179-
'./module': (() => {
180-
const r = [[2, '.test{c: d}', '']];
181-
r.locals = {
182-
c2: 'imported-c2',
183-
c3: 'imported-c3',
184-
c4: 'imported-c4',
185-
};
186-
return r;
187-
})(),
188-
}
189-
);
19037
testLocal(
19138
'module mode',
19239
".className { background: url(./file.png); }\n#someId { background: url('module/file.jpg'); }\n" +

test/locals.test.js

-62
This file was deleted.

0 commit comments

Comments
 (0)