From f9b8ef908f3c8100415cb823f8a4c43a004f9af4 Mon Sep 17 00:00:00 2001 From: Alexey Lavinsky Date: Tue, 7 Jul 2020 17:39:42 +0300 Subject: [PATCH] test: resolve modules (#1102) --- .../__snapshots__/modules-option.test.js.snap | 110 ++++++++++++++++++ .../composes/composes-preprocessors.css | 32 +++++ .../composes/composes-preprocessors.js | 5 + test/fixtures/modules/composes/less-file.less | 8 ++ test/fixtures/modules/composes/sass-file.sass | 8 ++ test/fixtures/modules/composes/scss-file.scss | 8 ++ test/modules-option.test.js | 22 ++++ 7 files changed, 193 insertions(+) create mode 100644 test/fixtures/modules/composes/composes-preprocessors.css create mode 100644 test/fixtures/modules/composes/composes-preprocessors.js create mode 100644 test/fixtures/modules/composes/less-file.less create mode 100644 test/fixtures/modules/composes/sass-file.sass create mode 100644 test/fixtures/modules/composes/scss-file.scss diff --git a/test/__snapshots__/modules-option.test.js.snap b/test/__snapshots__/modules-option.test.js.snap index 03f8436c..c5d10730 100644 --- a/test/__snapshots__/modules-option.test.js.snap +++ b/test/__snapshots__/modules-option.test.js.snap @@ -1042,6 +1042,116 @@ Array [ exports[`"modules" option should should work with two leading underscore: warnings 1`] = `Array []`; +exports[`"modules" option should support resolving in composes preprocessor files with extensions: errors 1`] = `Array []`; + +exports[`"modules" option should support resolving in composes preprocessor files with extensions: module 1`] = ` +"// Imports +var ___CSS_LOADER_API_IMPORT___ = require(\\"../../../../src/runtime/api.js\\"); +var ___CSS_LOADER_ICSS_IMPORT_0___ = require(\\"-!../../../../src/index.js??[ident]!./values.css\\"); +var ___CSS_LOADER_ICSS_IMPORT_1___ = require(\\"-!../../../../src/index.js??[ident]!./less-file.less\\"); +var ___CSS_LOADER_ICSS_IMPORT_2___ = require(\\"-!../../../../src/index.js??[ident]!./scss-file.scss\\"); +var ___CSS_LOADER_ICSS_IMPORT_3___ = require(\\"-!../../../../src/index.js??[ident]!./sass-file.sass\\"); +exports = ___CSS_LOADER_API_IMPORT___(false); +exports.i(___CSS_LOADER_ICSS_IMPORT_0___, \\"\\", true); +exports.i(___CSS_LOADER_ICSS_IMPORT_1___, \\"\\", true); +exports.i(___CSS_LOADER_ICSS_IMPORT_2___, \\"\\", true); +exports.i(___CSS_LOADER_ICSS_IMPORT_3___, \\"\\", true); +// Module +exports.push([module.id, \\".globalClassName {\\\\n color: orange;\\\\n}\\\\n\\\\n._2vZioV5tEV-AlqaI8c_mtN {\\\\n color: \\" + ___CSS_LOADER_ICSS_IMPORT_0___.locals[\\"v-def\\"] + \\";\\\\n}\\\\n\\\\n.YX1POP6L7ESwR7pdtyRna {\\\\n color: \\" + ___CSS_LOADER_ICSS_IMPORT_1___.locals[\\"v-foo\\"] + \\";\\\\n}\\\\n\\\\n._1578mz8iEiOG2qNa19R11c {\\\\n color: \\" + ___CSS_LOADER_ICSS_IMPORT_2___.locals[\\"v-bar\\"] + \\";\\\\n}\\\\n\\\\n._1yWiOyfH6HuDl7TOzpnWkK {\\\\n color: \\" + ___CSS_LOADER_ICSS_IMPORT_3___.locals[\\"v-baz\\"] + \\";\\\\n}\\\\n\\\\n.OVj95yO5B9JEdIo3xDMtO {\\\\n background: #000;\\\\n}\\\\n\\", \\"\\"]); +// Exports +exports.locals = { + \\"v-def\\": \\"\\" + ___CSS_LOADER_ICSS_IMPORT_0___.locals[\\"v-def\\"] + \\"\\", + \\"v-foo\\": \\"\\" + ___CSS_LOADER_ICSS_IMPORT_1___.locals[\\"v-foo\\"] + \\"\\", + \\"v-bar\\": \\"\\" + ___CSS_LOADER_ICSS_IMPORT_2___.locals[\\"v-bar\\"] + \\"\\", + \\"v-baz\\": \\"\\" + ___CSS_LOADER_ICSS_IMPORT_3___.locals[\\"v-baz\\"] + \\"\\", + \\"globalClassName\\": \\"globalClassName\\", + \\"ghi\\": \\"_2vZioV5tEV-AlqaI8c_mtN\\", + \\"class\\": \\"YX1POP6L7ESwR7pdtyRna \\" + ___CSS_LOADER_ICSS_IMPORT_1___.locals[\\"lessClass\\"] + \\"\\", + \\"other\\": \\"_1578mz8iEiOG2qNa19R11c \\" + ___CSS_LOADER_ICSS_IMPORT_2___.locals[\\"scssClass\\"] + \\"\\", + \\"last\\": \\"_1yWiOyfH6HuDl7TOzpnWkK \\" + ___CSS_LOADER_ICSS_IMPORT_3___.locals[\\"sassClass\\"] + \\"\\", + \\"otherClassName\\": \\"OVj95yO5B9JEdIo3xDMtO globalClassName\\" +}; +module.exports = exports; +" +`; + +exports[`"modules" option should support resolving in composes preprocessor files with extensions: result 1`] = ` +Array [ + Array [ + "../../src/index.js?[ident]!./modules/composes/values.css", + " +", + "", + ], + Array [ + "../../src/index.js?[ident]!./modules/composes/less-file.less", + "._3lZeyjNxPePITWh1xVieTf { + padding: 5px; +} +", + "", + ], + Array [ + "../../src/index.js?[ident]!./modules/composes/scss-file.scss", + "._228B9eI0iy8oD-AJowJJdF { + padding: 15px; +} +", + "", + ], + Array [ + "../../src/index.js?[ident]!./modules/composes/sass-file.sass", + " + +", + "", + ], + Array [ + "./modules/composes/composes-preprocessors.css", + ".globalClassName { + color: orange; +} + +._2vZioV5tEV-AlqaI8c_mtN { + color: red; +} + +.YX1POP6L7ESwR7pdtyRna { + color: green; +} + +._1578mz8iEiOG2qNa19R11c { + color: white; +} + +._1yWiOyfH6HuDl7TOzpnWkK { + color: undefined; +} + +.OVj95yO5B9JEdIo3xDMtO { + background: #000; +} +", + "", + ], +] +`; + +exports[`"modules" option should support resolving in composes preprocessor files with extensions: warnings 1`] = ` +Array [ + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +Invalid value definition: v-def: red +@value v-foo: green +@value v-bar: white +@value v-baz: coral + +.sassClass + padding: 10px", +] +`; + exports[`"modules" option should support resolving in composes: errors 1`] = `Array []`; exports[`"modules" option should support resolving in composes: module 1`] = ` diff --git a/test/fixtures/modules/composes/composes-preprocessors.css b/test/fixtures/modules/composes/composes-preprocessors.css new file mode 100644 index 00000000..f7250729 --- /dev/null +++ b/test/fixtures/modules/composes/composes-preprocessors.css @@ -0,0 +1,32 @@ +@value v-def from './values.css'; +@value v-foo from './less-file.less'; +@value v-bar from './scss-file.scss'; +@value v-baz from './sass-file.sass'; + +:global(.globalClassName) { + color: orange; +} + +.ghi { + color: v-def; +} + +.class { + color: v-foo; + composes: lessClass from "less-file.less"; +} + +.other { + color: v-bar; + composes: scssClass from "scss-file.scss"; +} + +.last { + color: v-baz; + composes: sassClass from "sass-file.sass"; +} + +.otherClassName { + composes: globalClassName from global; + background: #000; +} diff --git a/test/fixtures/modules/composes/composes-preprocessors.js b/test/fixtures/modules/composes/composes-preprocessors.js new file mode 100644 index 00000000..8b66fb66 --- /dev/null +++ b/test/fixtures/modules/composes/composes-preprocessors.js @@ -0,0 +1,5 @@ +import css from './composes-preprocessors.css'; + +__export__ = css; + +export default css; diff --git a/test/fixtures/modules/composes/less-file.less b/test/fixtures/modules/composes/less-file.less new file mode 100644 index 00000000..8d437d87 --- /dev/null +++ b/test/fixtures/modules/composes/less-file.less @@ -0,0 +1,8 @@ +@value v-def: red; +@value v-foo: green; +@value v-bar: white; +@value v-baz: coral; + +.lessClass { + padding: 5px; +} diff --git a/test/fixtures/modules/composes/sass-file.sass b/test/fixtures/modules/composes/sass-file.sass new file mode 100644 index 00000000..50ea4705 --- /dev/null +++ b/test/fixtures/modules/composes/sass-file.sass @@ -0,0 +1,8 @@ +@value v-def: red +@value v-foo: green +@value v-bar: white +@value v-baz: coral + +.sassClass + padding: 10px + diff --git a/test/fixtures/modules/composes/scss-file.scss b/test/fixtures/modules/composes/scss-file.scss new file mode 100644 index 00000000..920dd89c --- /dev/null +++ b/test/fixtures/modules/composes/scss-file.scss @@ -0,0 +1,8 @@ +@value v-def: red; +@value v-foo: green; +@value v-bar: white; +@value v-baz: coral; + +.scssClass { + padding: 15px; +} diff --git a/test/modules-option.test.js b/test/modules-option.test.js index b26026bd..1bcc8160 100644 --- a/test/modules-option.test.js +++ b/test/modules-option.test.js @@ -328,6 +328,28 @@ describe('"modules" option', () => { expect(getErrors(stats)).toMatchSnapshot('errors'); }); + it('should support resolving in composes preprocessor files with extensions', async () => { + const compiler = getCompiler( + './modules/composes/composes-preprocessors.js', + { + modules: { + mode: 'local', + exportGlobals: true, + }, + } + ); + const stats = await compile(compiler); + + expect( + getModuleSource('./modules/composes/composes-preprocessors.css', stats) + ).toMatchSnapshot('module'); + expect(getExecutedCode('main.bundle.js', compiler, stats)).toMatchSnapshot( + 'result' + ); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + it('issue #286', async () => { const compiler = getCompiler( './modules/issue-286/source.js',