diff --git a/test/__snapshots__/modules-option.test.js.snap b/test/__snapshots__/modules-option.test.js.snap index 1b5daa38..0f2da554 100644 --- a/test/__snapshots__/modules-option.test.js.snap +++ b/test/__snapshots__/modules-option.test.js.snap @@ -5342,3 +5342,39 @@ exports.locals = { `; exports[`modules issue #286: warnings 1`] = `Array []`; + +exports[`modules issue #636: errors 1`] = `Array []`; + +exports[`modules issue #636: module (evaluated) 1`] = ` +Array [ + Array [ + 2, + ".prefix-foo { + color: red; +}", + "", + ], + Array [ + 1, + ".prefix-bar { +}", + "", + ], +] +`; + +exports[`modules issue #636: module 1`] = ` +"exports = module.exports = require(\\"../../../../src/runtime/api.js\\")(false); +// imports +exports.i(require(\\"-!../../../../src/index.js??ref--4-0!../../../../node_modules/sass-loader/lib/loader.js??ref--4-1!./foo.scss\\"), \\"\\"); + +// module +exports.push([module.id, \\".prefix-bar {\\\\n}\\", \\"\\"]); + +// exports +exports.locals = { + \\"bar\\": \\"prefix-bar \\" + require(\\"-!../../../../src/index.js??ref--4-0!../../../../node_modules/sass-loader/lib/loader.js??ref--4-1!./foo.scss\\").locals[\\"foo\\"] + \\"\\" +};" +`; + +exports[`modules issue #636: warnings 1`] = `Array []`; diff --git a/test/fixtures/modules/issue-636/foo.scss b/test/fixtures/modules/issue-636/foo.scss new file mode 100644 index 00000000..a15c877a --- /dev/null +++ b/test/fixtures/modules/issue-636/foo.scss @@ -0,0 +1,3 @@ +.foo { + color: red; +} diff --git a/test/fixtures/modules/issue-636/source.scss b/test/fixtures/modules/issue-636/source.scss new file mode 100644 index 00000000..e200ce35 --- /dev/null +++ b/test/fixtures/modules/issue-636/source.scss @@ -0,0 +1,3 @@ +.bar { + composes: foo from "./foo.scss"; +} diff --git a/test/helpers.js b/test/helpers.js index 9b053f18..c76309d8 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -42,6 +42,7 @@ function evaluated(output, modules, moduleId = 1) { 'url/node_modules', 'modules/', 'modules/issue-286', + 'modules/issue-636', 'modules/node_modules', 'modules/tests-cases/urls', 'modules/tests-cases/issue-589', diff --git a/test/modules-option.test.js b/test/modules-option.test.js index 9d094ca0..048766de 100644 --- a/test/modules-option.test.js +++ b/test/modules-option.test.js @@ -37,7 +37,7 @@ describe('modules', () => { }); }); - it(`composes should supports resolving`, async () => { + it('composes should supports resolving', async () => { const config = { loader: { options: { import: true, modules: true } }, }; @@ -54,7 +54,7 @@ describe('modules', () => { expect(stats.compilation.errors).toMatchSnapshot('errors'); }); - it(`issue #286`, async () => { + it('issue #286', async () => { const config = { loader: { test: /source\.css$/, @@ -86,4 +86,35 @@ describe('modules', () => { expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); }); + + it('issue #636', async () => { + const config = { + loader: { + test: /\.s[ca]ss$/i, + options: { + modules: true, + importLoaders: 1, + localIdentName: '[local]', + getLocalIdent: (context, localIdentName, localName) => + `prefix-${localName}`, + }, + }, + sassLoader: true, + sassLoaderOptions: { + // eslint-disable-next-line global-require + implementation: require('sass'), + }, + }; + const testId = './modules/issue-636/source.scss'; + 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'); + }); });