Skip to content

Commit fa8b1a6

Browse files
committed
test: clean up and add test cases
1 parent c8280b8 commit fa8b1a6

File tree

5 files changed

+91
-9
lines changed

5 files changed

+91
-9
lines changed

src/plugins/postcss-icss-parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default postcss.plugin(
5858
const token = node.value;
5959
const replacement = importReplacements[token];
6060

61-
if (replacement != null) {
61+
if (replacement) {
6262
// eslint-disable-next-line no-param-reassign
6363
node.value = replacement;
6464
}

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

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5359,10 +5359,10 @@ Array [
53595359
}
53605360
53615361
._3XDgIzfUIQkaUInpEdo7fN {
5362-
color: blue;
5362+
color: foo;
53635363
}
53645364
5365-
.green {
5365+
._1t1lFvgmmUiqhBGTbP08cn {
53665366
display: block;
53675367
}
53685368
@@ -5374,7 +5374,7 @@ Array [
53745374
color: green;
53755375
}
53765376
5377-
._3SRb8VDtr6fpZVzVUOJOM2 {
5377+
._1tAbIwITRWAdZZE6wKNk9O {
53785378
prop: red;
53795379
duplicate: green;
53805380
}
@@ -5417,20 +5417,20 @@ exports.i(require(\\"-!../../../src/index.js??ref--4-0!package/style.css\\"), \\
54175417
exports.i(require(\\"-!../../../src/index.js??ref--4-0!aliasesComposes/alias.css\\"), \\"\\");
54185418
54195419
// Module
5420-
exports.push([module.id, \\"._14uFt0lIVKKAlKTTT29IIQ {\\\\n color: \\" + require(\\"-!../../../src/index.js??ref--4-0!./values.css\\").locals[\\"def\\"] + \\";\\\\n}\\\\n\\\\n._3XDgIzfUIQkaUInpEdo7fN {\\\\n color: blue;\\\\n}\\\\n\\\\n.\\" + require(\\"-!../../../src/index.js??ref--4-0!./values.css\\").locals[\\"other\\"] + \\" {\\\\n display: block;\\\\n}\\\\n\\\\n._1DFEYnAfn9LZyk4fErI86e {\\\\n width: \\" + require(\\"-!../../../src/index.js??ref--4-0!./something.css\\").locals[\\"something\\"] + \\";\\\\n}\\\\n\\\\n.Ywv5coVC2RU-pIFhN9O4w {\\\\n color: \\" + require(\\"-!../../../src/index.js??ref--4-0!./values.css\\").locals[\\"other\\"] + \\";\\\\n}\\\\n\\\\n._3SRb8VDtr6fpZVzVUOJOM2 {\\\\n prop: \\" + require(\\"-!../../../src/index.js??ref--4-0!./values.css\\").locals[\\"def\\"] + \\";\\\\n duplicate: \\" + require(\\"-!../../../src/index.js??ref--4-0!./values.css\\").locals[\\"other\\"] + \\";\\\\n}\\\\n\\\\n.Q3SQ3BwtBwUFLlg6adzOI {\\\\n color: red;\\\\n}\\\\n\\\\n._1n5XhXj4SFnYrwziC3un0d {\\\\n color: yellow;\\\\n}\\\\n\\\\n._3dnFnGkAVAiMA6etF-naHc {\\\\n color: gray;\\\\n}\\\\n\\\\n._1xUePnlnafMQ1cExy3PUWT {\\\\n color: gray;\\\\n}\\\\n\\\\n._26Jdfenl9Xn8HXwb2jipvt {\\\\n color: gainsboro;\\\\n}\\\\n\\", \\"\\"]);
5420+
exports.push([module.id, \\"._14uFt0lIVKKAlKTTT29IIQ {\\\\n color: \\" + require(\\"-!../../../src/index.js??ref--4-0!./values.css\\").locals[\\"def\\"] + \\";\\\\n}\\\\n\\\\n._3XDgIzfUIQkaUInpEdo7fN {\\\\n color: foo;\\\\n}\\\\n\\\\n._1t1lFvgmmUiqhBGTbP08cn {\\\\n display: block;\\\\n}\\\\n\\\\n._1DFEYnAfn9LZyk4fErI86e {\\\\n width: \\" + require(\\"-!../../../src/index.js??ref--4-0!./something.css\\").locals[\\"something\\"] + \\";\\\\n}\\\\n\\\\n.Ywv5coVC2RU-pIFhN9O4w {\\\\n color: \\" + require(\\"-!../../../src/index.js??ref--4-0!./values.css\\").locals[\\"other\\"] + \\";\\\\n}\\\\n\\\\n._1tAbIwITRWAdZZE6wKNk9O {\\\\n prop: \\" + require(\\"-!../../../src/index.js??ref--4-0!./values.css\\").locals[\\"def\\"] + \\";\\\\n duplicate: \\" + require(\\"-!../../../src/index.js??ref--4-0!./values.css\\").locals[\\"other\\"] + \\";\\\\n}\\\\n\\\\n.Q3SQ3BwtBwUFLlg6adzOI {\\\\n color: red;\\\\n}\\\\n\\\\n._1n5XhXj4SFnYrwziC3un0d {\\\\n color: yellow;\\\\n}\\\\n\\\\n._3dnFnGkAVAiMA6etF-naHc {\\\\n color: gray;\\\\n}\\\\n\\\\n._1xUePnlnafMQ1cExy3PUWT {\\\\n color: gray;\\\\n}\\\\n\\\\n._26Jdfenl9Xn8HXwb2jipvt {\\\\n color: gainsboro;\\\\n}\\\\n\\", \\"\\"]);
54215421
54225422
// Exports
54235423
exports.locals = {
54245424
\\"def\\": \\"\\" + require(\\"-!../../../src/index.js??ref--4-0!./values.css\\").locals[\\"def\\"] + \\"\\",
54255425
\\"other\\": \\"\\" + require(\\"-!../../../src/index.js??ref--4-0!./values.css\\").locals[\\"other\\"] + \\"\\",
54265426
\\"something\\": \\"\\" + require(\\"-!../../../src/index.js??ref--4-0!./something.css\\").locals[\\"something\\"] + \\"\\",
5427-
\\"foo\\": \\"blue\\",
54285427
\\"bar\\": \\"block\\",
54295428
\\"ghi\\": \\"_14uFt0lIVKKAlKTTT29IIQ\\",
54305429
\\"class\\": \\"_3XDgIzfUIQkaUInpEdo7fN\\",
5430+
\\"block\\": \\"_1t1lFvgmmUiqhBGTbP08cn\\",
54315431
\\"other-other\\": \\"_1DFEYnAfn9LZyk4fErI86e\\",
54325432
\\"green\\": \\"Ywv5coVC2RU-pIFhN9O4w\\",
5433-
\\"blue\\": \\"_3SRb8VDtr6fpZVzVUOJOM2\\",
5433+
\\"foo\\": \\"_1tAbIwITRWAdZZE6wKNk9O\\",
54345434
\\"simple\\": \\"Q3SQ3BwtBwUFLlg6adzOI \\" + require(\\"-!../../../src/index.js??ref--4-0!./imported-simple.css\\").locals[\\"imported-simple\\"] + \\"\\",
54355435
\\"relative\\": \\"_1n5XhXj4SFnYrwziC3un0d \\" + require(\\"-!../../../src/index.js??ref--4-0!./relative.css\\").locals[\\"imported-relative\\"] + \\"\\",
54365436
\\"top-relative\\": \\"_3dnFnGkAVAiMA6etF-naHc \\" + require(\\"-!../../../src/index.js??ref--4-0!../modules/top-relative.css\\").locals[\\"imported-relative\\"] + \\"\\",
@@ -5441,6 +5441,58 @@ exports.locals = {
54415441
54425442
exports[`modules composes should supports resolving: warnings 1`] = `Array []`;
54435443
5444+
exports[`modules composes should values in selectors: errors 1`] = `Array []`;
5445+
5446+
exports[`modules composes should values in selectors: module (evaluated) 1`] = `
5447+
Array [
5448+
Array [
5449+
2,
5450+
"
5451+
",
5452+
"",
5453+
],
5454+
Array [
5455+
3,
5456+
"._22ETk3ZhhvjVe-4dAULcsF {
5457+
display: block;
5458+
}
5459+
",
5460+
"",
5461+
],
5462+
Array [
5463+
1,
5464+
"/* At the moment local-by-default doesn't understand values .btn would get hashed */
5465+
.btn {
5466+
display: block;
5467+
}
5468+
5469+
.green > ._22ETk3ZhhvjVe-4dAULcsF {
5470+
color: blue;
5471+
}
5472+
",
5473+
"",
5474+
],
5475+
]
5476+
`;
5477+
5478+
exports[`modules composes should values in selectors: module 1`] = `
5479+
"exports = module.exports = require(\\"../../../src/runtime/api.js\\")(false);
5480+
// Imports
5481+
exports.i(require(\\"-!../../../src/index.js??ref--4-0!./values.css\\"), \\"\\");
5482+
exports.i(require(\\"-!../../../src/index.js??ref--4-0!./imported-simple.css\\"), \\"\\");
5483+
5484+
// Module
5485+
exports.push([module.id, \\"/* At the moment local-by-default doesn't understand values .btn would get hashed */\\\\n.btn {\\\\n display: block;\\\\n}\\\\n\\\\n.\\" + require(\\"-!../../../src/index.js??ref--4-0!./values.css\\").locals[\\"other\\"] + \\" > .\\" + require(\\"-!../../../src/index.js??ref--4-0!./imported-simple.css\\").locals[\\"imported-simple\\"] + \\" {\\\\n color: blue;\\\\n}\\\\n\\", \\"\\"]);
5486+
5487+
// Exports
5488+
exports.locals = {
5489+
\\"other\\": \\"\\" + require(\\"-!../../../src/index.js??ref--4-0!./values.css\\").locals[\\"other\\"] + \\"\\",
5490+
\\"button-class\\": \\"btn\\"
5491+
};"
5492+
`;
5493+
5494+
exports[`modules composes should values in selectors: warnings 1`] = `Array []`;
5495+
54445496
exports[`modules issue #286: errors 1`] = `Array []`;
54455497
54465498
exports[`modules issue #286: module (evaluated) 1`] = `

test/fixtures/modules/composes.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
@value other from './values.css';
55
@value other from './values.css';
66
@value something from './something.css';
7-
@value foo: blue;
87
@value bar: block;
98

109
.ghi {
@@ -15,7 +14,7 @@
1514
color: foo;
1615
}
1716

18-
.other {
17+
.block {
1918
display: bar;
2019
}
2120

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@value other from './values.css';
2+
@value button-class: btn;
3+
4+
:import('imported-simple.css') {
5+
other-child: imported-simple;
6+
}
7+
/* At the moment local-by-default doesn't understand values .btn would get hashed */
8+
:global(.button-class) {
9+
display: block;
10+
}
11+
12+
.other > .other-child {
13+
color: blue;
14+
}

test/modules-option.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@ describe('modules', () => {
5454
expect(stats.compilation.errors).toMatchSnapshot('errors');
5555
});
5656

57+
it('composes should values in selectors', async () => {
58+
const config = {
59+
loader: { options: { import: true, modules: true } },
60+
};
61+
const testId = './modules/values-in-selectors.css';
62+
const stats = await webpack(testId, config);
63+
const { modules } = stats.toJson();
64+
const module = modules.find((m) => m.id === testId);
65+
66+
expect(module.source).toMatchSnapshot('module');
67+
expect(evaluated(module.source, modules)).toMatchSnapshot(
68+
'module (evaluated)'
69+
);
70+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
71+
expect(stats.compilation.errors).toMatchSnapshot('errors');
72+
});
73+
5774
it('issue #286', async () => {
5875
const config = {
5976
loader: {

0 commit comments

Comments
 (0)