Skip to content

Commit 1e551f3

Browse files
test: issue 286 (#849)
1 parent 419d27b commit 1e551f3

File tree

8 files changed

+83
-4
lines changed

8 files changed

+83
-4
lines changed

src/options.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,14 @@
5555
]
5656
},
5757
"importLoaders": {
58-
"type": "number"
58+
"anyOf": [
59+
{
60+
"type": "boolean"
61+
},
62+
{
63+
"type": "number"
64+
}
65+
]
5966
},
6067
"exportOnlyLocals": {
6168
"type": "boolean"

test/__snapshots__/errors.test.js.snap

+2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ options.camelCase should match some schema in anyOf
9797
exports[`validation 13`] = `
9898
"CSS Loader Invalid Options
9999
100+
options.importLoaders should be boolean
100101
options.importLoaders should be number
102+
options.importLoaders should match some schema in anyOf
101103
"
102104
`;
103105

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

+35
Original file line numberDiff line numberDiff line change
@@ -5195,3 +5195,38 @@ exports.locals = {
51955195
`;
51965196
51975197
exports[`modules composes should supports resolving: warnings 1`] = `Array []`;
5198+
5199+
exports[`modules issue #286: errors 1`] = `Array []`;
5200+
5201+
exports[`modules issue #286: module (evaluated) 1`] = `
5202+
Array [
5203+
Array [
5204+
2,
5205+
".a--red { color: red }
5206+
",
5207+
"",
5208+
],
5209+
Array [
5210+
1,
5211+
".b--main { }
5212+
",
5213+
"",
5214+
],
5215+
]
5216+
`;
5217+
5218+
exports[`modules issue #286: module 1`] = `
5219+
"exports = module.exports = require(\\"../../../../src/runtime/api.js\\")(false);
5220+
// imports
5221+
exports.i(require(\\"./dep.css\\"), \\"\\");
5222+
5223+
// module
5224+
exports.push([module.id, \\".b--main { }\\\\n\\", \\"\\"]);
5225+
5226+
// exports
5227+
exports.locals = {
5228+
\\"main\\": \\"b--main \\" + require(\\"./dep.css\\").locals[\\"red\\"] + \\"\\"
5229+
};"
5230+
`;
5231+
5232+
exports[`modules issue #286: warnings 1`] = `Array []`;

test/errors.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ it('validation', () => {
7373
validate({ camelCase: 'unknown' })
7474
).toThrowErrorMatchingSnapshot();
7575

76+
expect(() => validate({ importLoaders: false })).not.toThrow();
7677
expect(() => validate({ importLoaders: 0 })).not.toThrow();
7778
expect(() => validate({ importLoaders: 1 })).not.toThrow();
7879
expect(() => validate({ importLoaders: 2 })).not.toThrow();
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.red { color: red }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.main { composes: red from './dep.css'; }

test/helpers.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function evaluated(output, modules, moduleId = 1) {
4040
'url',
4141
'url/node_modules',
4242
'modules/',
43+
'modules/issue-286',
4344
'modules/node_modules',
4445
'modules/tests-cases/urls',
4546
'modules/tests-cases/comments',
@@ -74,9 +75,6 @@ function evaluated(output, modules, moduleId = 1) {
7475
}
7576

7677
return 'nothing';
77-
} else if (modules && module in modules) {
78-
// Compatibility with old tests
79-
return modules[module];
8078
}
8179
return `{${module}}`;
8280
});
@@ -138,6 +136,7 @@ const moduleConfig = (config) => {
138136
: []
139137
),
140138
},
139+
config.additionalLoader ? config.additionalLoader : {},
141140
{
142141
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
143142
use: {

test/modules-option.test.js

+33
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,37 @@ describe('modules', () => {
5353
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
5454
expect(stats.compilation.errors).toMatchSnapshot('errors');
5555
});
56+
57+
it(`issue #286`, async () => {
58+
const config = {
59+
loader: {
60+
test: /source\.css$/,
61+
options: {
62+
importLoaders: false,
63+
modules: true,
64+
localIdentName: 'b--[local]',
65+
},
66+
},
67+
additionalLoader: {
68+
test: /dep\.css$/,
69+
loader: path.resolve(__dirname, '../src/index.js'),
70+
options: {
71+
importLoaders: false,
72+
modules: true,
73+
localIdentName: 'a--[local]',
74+
},
75+
},
76+
};
77+
const testId = './modules/issue-286/source.css';
78+
const stats = await webpack(testId, config);
79+
const { modules } = stats.toJson();
80+
const module = modules.find((m) => m.id === testId);
81+
82+
expect(module.source).toMatchSnapshot('module');
83+
expect(evaluated(module.source, modules)).toMatchSnapshot(
84+
'module (evaluated)'
85+
);
86+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
87+
expect(stats.compilation.errors).toMatchSnapshot('errors');
88+
});
5689
});

0 commit comments

Comments
 (0)