Skip to content

Commit 533abbe

Browse files
test: issue 636 (#853)
1 parent 08c551c commit 533abbe

File tree

5 files changed

+76
-2
lines changed

5 files changed

+76
-2
lines changed

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

+36
Original file line numberDiff line numberDiff line change
@@ -5342,3 +5342,39 @@ exports.locals = {
53425342
`;
53435343
53445344
exports[`modules issue #286: warnings 1`] = `Array []`;
5345+
5346+
exports[`modules issue #636: errors 1`] = `Array []`;
5347+
5348+
exports[`modules issue #636: module (evaluated) 1`] = `
5349+
Array [
5350+
Array [
5351+
2,
5352+
".prefix-foo {
5353+
color: red;
5354+
}",
5355+
"",
5356+
],
5357+
Array [
5358+
1,
5359+
".prefix-bar {
5360+
}",
5361+
"",
5362+
],
5363+
]
5364+
`;
5365+
5366+
exports[`modules issue #636: module 1`] = `
5367+
"exports = module.exports = require(\\"../../../../src/runtime/api.js\\")(false);
5368+
// imports
5369+
exports.i(require(\\"-!../../../../src/index.js??ref--4-0!../../../../node_modules/sass-loader/lib/loader.js??ref--4-1!./foo.scss\\"), \\"\\");
5370+
5371+
// module
5372+
exports.push([module.id, \\".prefix-bar {\\\\n}\\", \\"\\"]);
5373+
5374+
// exports
5375+
exports.locals = {
5376+
\\"bar\\": \\"prefix-bar \\" + require(\\"-!../../../../src/index.js??ref--4-0!../../../../node_modules/sass-loader/lib/loader.js??ref--4-1!./foo.scss\\").locals[\\"foo\\"] + \\"\\"
5377+
};"
5378+
`;
5379+
5380+
exports[`modules issue #636: warnings 1`] = `Array []`;
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.foo {
2+
color: red;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.bar {
2+
composes: foo from "./foo.scss";
3+
}

test/helpers.js

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ function evaluated(output, modules, moduleId = 1) {
4242
'url/node_modules',
4343
'modules/',
4444
'modules/issue-286',
45+
'modules/issue-636',
4546
'modules/node_modules',
4647
'modules/tests-cases/urls',
4748
'modules/tests-cases/issue-589',

test/modules-option.test.js

+33-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('modules', () => {
3737
});
3838
});
3939

40-
it(`composes should supports resolving`, async () => {
40+
it('composes should supports resolving', async () => {
4141
const config = {
4242
loader: { options: { import: true, modules: true } },
4343
};
@@ -54,7 +54,7 @@ describe('modules', () => {
5454
expect(stats.compilation.errors).toMatchSnapshot('errors');
5555
});
5656

57-
it(`issue #286`, async () => {
57+
it('issue #286', async () => {
5858
const config = {
5959
loader: {
6060
test: /source\.css$/,
@@ -86,4 +86,35 @@ describe('modules', () => {
8686
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
8787
expect(stats.compilation.errors).toMatchSnapshot('errors');
8888
});
89+
90+
it('issue #636', async () => {
91+
const config = {
92+
loader: {
93+
test: /\.s[ca]ss$/i,
94+
options: {
95+
modules: true,
96+
importLoaders: 1,
97+
localIdentName: '[local]',
98+
getLocalIdent: (context, localIdentName, localName) =>
99+
`prefix-${localName}`,
100+
},
101+
},
102+
sassLoader: true,
103+
sassLoaderOptions: {
104+
// eslint-disable-next-line global-require
105+
implementation: require('sass'),
106+
},
107+
};
108+
const testId = './modules/issue-636/source.scss';
109+
const stats = await webpack(testId, config);
110+
const { modules } = stats.toJson();
111+
const module = modules.find((m) => m.id === testId);
112+
113+
expect(module.source).toMatchSnapshot('module');
114+
expect(evaluated(module.source, modules)).toMatchSnapshot(
115+
'module (evaluated)'
116+
);
117+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
118+
expect(stats.compilation.errors).toMatchSnapshot('errors');
119+
});
89120
});

0 commit comments

Comments
 (0)