Skip to content

Commit

Permalink
test: issue 286 (#849)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Dec 4, 2018
1 parent 419d27b commit 1e551f3
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/options.json
Expand Up @@ -55,7 +55,14 @@
]
},
"importLoaders": {
"type": "number"
"anyOf": [
{
"type": "boolean"
},
{
"type": "number"
}
]
},
"exportOnlyLocals": {
"type": "boolean"
Expand Down
2 changes: 2 additions & 0 deletions test/__snapshots__/errors.test.js.snap
Expand Up @@ -97,7 +97,9 @@ options.camelCase should match some schema in anyOf
exports[`validation 13`] = `
"CSS Loader Invalid Options
options.importLoaders should be boolean
options.importLoaders should be number
options.importLoaders should match some schema in anyOf
"
`;

Expand Down
35 changes: 35 additions & 0 deletions test/__snapshots__/modules-option.test.js.snap
Expand Up @@ -5195,3 +5195,38 @@ exports.locals = {
`;
exports[`modules composes should supports resolving: warnings 1`] = `Array []`;
exports[`modules issue #286: errors 1`] = `Array []`;
exports[`modules issue #286: module (evaluated) 1`] = `
Array [
Array [
2,
".a--red { color: red }
",
"",
],
Array [
1,
".b--main { }
",
"",
],
]
`;
exports[`modules issue #286: module 1`] = `
"exports = module.exports = require(\\"../../../../src/runtime/api.js\\")(false);
// imports
exports.i(require(\\"./dep.css\\"), \\"\\");
// module
exports.push([module.id, \\".b--main { }\\\\n\\", \\"\\"]);
// exports
exports.locals = {
\\"main\\": \\"b--main \\" + require(\\"./dep.css\\").locals[\\"red\\"] + \\"\\"
};"
`;
exports[`modules issue #286: warnings 1`] = `Array []`;
1 change: 1 addition & 0 deletions test/errors.test.js
Expand Up @@ -73,6 +73,7 @@ it('validation', () => {
validate({ camelCase: 'unknown' })
).toThrowErrorMatchingSnapshot();

expect(() => validate({ importLoaders: false })).not.toThrow();
expect(() => validate({ importLoaders: 0 })).not.toThrow();
expect(() => validate({ importLoaders: 1 })).not.toThrow();
expect(() => validate({ importLoaders: 2 })).not.toThrow();
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/modules/issue-286/dep.css
@@ -0,0 +1 @@
.red { color: red }
1 change: 1 addition & 0 deletions test/fixtures/modules/issue-286/source.css
@@ -0,0 +1 @@
.main { composes: red from './dep.css'; }
5 changes: 2 additions & 3 deletions test/helpers.js
Expand Up @@ -40,6 +40,7 @@ function evaluated(output, modules, moduleId = 1) {
'url',
'url/node_modules',
'modules/',
'modules/issue-286',
'modules/node_modules',
'modules/tests-cases/urls',
'modules/tests-cases/comments',
Expand Down Expand Up @@ -74,9 +75,6 @@ function evaluated(output, modules, moduleId = 1) {
}

return 'nothing';
} else if (modules && module in modules) {
// Compatibility with old tests
return modules[module];
}
return `{${module}}`;
});
Expand Down Expand Up @@ -138,6 +136,7 @@ const moduleConfig = (config) => {
: []
),
},
config.additionalLoader ? config.additionalLoader : {},
{
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
use: {
Expand Down
33 changes: 33 additions & 0 deletions test/modules-option.test.js
Expand Up @@ -53,4 +53,37 @@ describe('modules', () => {
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
expect(stats.compilation.errors).toMatchSnapshot('errors');
});

it(`issue #286`, async () => {
const config = {
loader: {
test: /source\.css$/,
options: {
importLoaders: false,
modules: true,
localIdentName: 'b--[local]',
},
},
additionalLoader: {
test: /dep\.css$/,
loader: path.resolve(__dirname, '../src/index.js'),
options: {
importLoaders: false,
modules: true,
localIdentName: 'a--[local]',
},
},
};
const testId = './modules/issue-286/source.css';
const stats = await webpack(testId, config);
const { modules } = stats.toJson();
const module = modules.find((m) => m.id === testId);

expect(module.source).toMatchSnapshot('module');
expect(evaluated(module.source, modules)).toMatchSnapshot(
'module (evaluated)'
);
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
expect(stats.compilation.errors).toMatchSnapshot('errors');
});
});

0 comments on commit 1e551f3

Please sign in to comment.