From 97ad622a7cf8222a7141ee134bce02e1fdd07d4b Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Mon, 10 Dec 2018 18:27:51 +0300 Subject: [PATCH] test: resolving in node_modules --- .../__snapshots__/modules-option.test.js.snap | 59 +++++++++++++++++++ .../node_modules/@localpackage/color.css | 1 + .../node_modules/@localpackage/style.css | 6 ++ .../node_modules/@otherlocalpackage/style.css | 3 + .../modules/resolving-inside-node-modules.css | 8 +++ test/modules-option.test.js | 17 ++++++ 6 files changed, 94 insertions(+) create mode 100644 test/fixtures/modules/node_modules/@localpackage/color.css create mode 100644 test/fixtures/modules/node_modules/@localpackage/style.css create mode 100644 test/fixtures/modules/node_modules/@otherlocalpackage/style.css create mode 100644 test/fixtures/modules/resolving-inside-node-modules.css diff --git a/test/__snapshots__/modules-option.test.js.snap b/test/__snapshots__/modules-option.test.js.snap index a2f04d71..bc011a5b 100644 --- a/test/__snapshots__/modules-option.test.js.snap +++ b/test/__snapshots__/modules-option.test.js.snap @@ -5378,3 +5378,62 @@ exports.locals = { `; exports[`modules issue #636: warnings 1`] = `Array []`; + +exports[`modules issue #861: errors 1`] = `Array []`; + +exports[`modules issue #861: module (evaluated) 1`] = ` +Array [ + Array [ + 2, + " +", + "", + ], + Array [ + 4, + "._1ef5Heix1Kf4k0qYvyWRRO { + display: flex; +} +", + "", + ], + Array [ + 3, + ".L8pnpYm5VAu49S290uPMA { + color: red; + margin: 0; + padding: 0; +} +", + "", + ], + Array [ + 1, + "._2gV2e6TcHcPgyDTzxbvkKa { + color: gray; + margin: 0; + padding: 0; +} +", + "", + ], +] +`; + +exports[`modules issue #861: module 1`] = ` +"exports = module.exports = require(\\"../../../src/runtime/api.js\\")(false); +// Imports +exports.i(require(\\"-!../../../src/index.js??ref--4-0!@localpackage/color.css\\"), \\"\\"); +exports.i(require(\\"-!../../../src/index.js??ref--4-0!@localpackage/style.css\\"), \\"\\"); + +// Module +exports.push([module.id, \\"._2gV2e6TcHcPgyDTzxbvkKa {\\\\n color: \\" + require(\\"-!../../../src/index.js??ref--4-0!@localpackage/color.css\\").locals[\\"color-grey\\"] + \\";\\\\n margin: 0;\\\\n padding: 0;\\\\n}\\\\n\\", \\"\\"]); + +// Exports +exports.locals = { + \\"color-grey\\": \\"\\" + require(\\"-!../../../src/index.js??ref--4-0!@localpackage/color.css\\").locals[\\"color-grey\\"] + \\"\\", + \\"copyright\\": \\"_2gV2e6TcHcPgyDTzxbvkKa \\" + require(\\"-!../../../src/index.js??ref--4-0!@localpackage/style.css\\").locals[\\"type-heading\\"] + \\"\\" +};" +`; + +exports[`modules issue #861: warnings 1`] = `Array []`; diff --git a/test/fixtures/modules/node_modules/@localpackage/color.css b/test/fixtures/modules/node_modules/@localpackage/color.css new file mode 100644 index 00000000..7ae91afb --- /dev/null +++ b/test/fixtures/modules/node_modules/@localpackage/color.css @@ -0,0 +1 @@ +@value color-grey: gray; diff --git a/test/fixtures/modules/node_modules/@localpackage/style.css b/test/fixtures/modules/node_modules/@localpackage/style.css new file mode 100644 index 00000000..0e3b37bf --- /dev/null +++ b/test/fixtures/modules/node_modules/@localpackage/style.css @@ -0,0 +1,6 @@ +.type-heading { + color: red; + composes: type-heading2 from "~@otherlocalpackage/style.css"; + margin: 0; + padding: 0; +} diff --git a/test/fixtures/modules/node_modules/@otherlocalpackage/style.css b/test/fixtures/modules/node_modules/@otherlocalpackage/style.css new file mode 100644 index 00000000..1567804b --- /dev/null +++ b/test/fixtures/modules/node_modules/@otherlocalpackage/style.css @@ -0,0 +1,3 @@ +.type-heading2 { + display: flex; +} diff --git a/test/fixtures/modules/resolving-inside-node-modules.css b/test/fixtures/modules/resolving-inside-node-modules.css new file mode 100644 index 00000000..a9986d8f --- /dev/null +++ b/test/fixtures/modules/resolving-inside-node-modules.css @@ -0,0 +1,8 @@ +@value color-grey from "~@localpackage/color.css"; + +.copyright { + color: color-grey; + composes: type-heading from "~@localpackage/style.css"; + margin: 0; + padding: 0; +} diff --git a/test/modules-option.test.js b/test/modules-option.test.js index 048766de..3b83ff4e 100644 --- a/test/modules-option.test.js +++ b/test/modules-option.test.js @@ -117,4 +117,21 @@ describe('modules', () => { expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); }); + + it('issue #861', async () => { + const config = { + loader: { options: { modules: true } }, + }; + const testId = './modules/resolving-inside-node-modules.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'); + }); });