From 8362065f02c17d6eb0ac4f9401dca1f3641140e6 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Thu, 15 Jul 2021 00:29:25 +0300 Subject: [PATCH] test: add test for entry and auto --- .../__snapshots__/modules-option.test.js.snap | 42 +++++++++++++++++++ test/fixtures/modules/mode/entry.css | 3 ++ test/helpers/getCompiler.js | 4 +- test/modules-option.test.js | 20 +++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/modules/mode/entry.css diff --git a/test/__snapshots__/modules-option.test.js.snap b/test/__snapshots__/modules-option.test.js.snap index 6cc00318..3be3aa16 100644 --- a/test/__snapshots__/modules-option.test.js.snap +++ b/test/__snapshots__/modules-option.test.js.snap @@ -13412,6 +13412,48 @@ Array [ exports[`"modules" option should work with the "auto" by default for icss: warnings 1`] = `Array []`; +exports[`"modules" option should work with the "auto" by default when CSS file is entrypoint: entry 1`] = ` +"// Imports +import ___CSS_LOADER_API_IMPORT___ from \\"../../../../src/runtime/api.js\\"; +var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(function(i){return i[1]}); +// Module +___CSS_LOADER_EXPORT___.push([module.id, \\".class {\\\\n color: red;\\\\n}\\\\n\\", \\"\\"]); +// Exports +export default ___CSS_LOADER_EXPORT___; +" +`; + +exports[`"modules" option should work with the "auto" by default when CSS file is entrypoint: errors 1`] = `Array []`; + +exports[`"modules" option should work with the "auto" by default when CSS file is entrypoint: module 1`] = ` +"// Imports +import ___CSS_LOADER_API_IMPORT___ from \\"../../../../src/runtime/api.js\\"; +var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(function(i){return i[1]}); +// Module +___CSS_LOADER_EXPORT___.push([module.id, \\"._wr0eVpMbaGr94MKhByE {\\\\n color: red;\\\\n}\\\\n\\", \\"\\"]); +// Exports +___CSS_LOADER_EXPORT___.locals = { + \\"relative\\": \\"_wr0eVpMbaGr94MKhByE\\" +}; +export default ___CSS_LOADER_EXPORT___; +" +`; + +exports[`"modules" option should work with the "auto" by default when CSS file is entrypoint: result 1`] = ` +Array [ + Array [ + "./modules/mode/relative.module.css", + "._wr0eVpMbaGr94MKhByE { + color: red; +} +", + "", + ], +] +`; + +exports[`"modules" option should work with the "auto" by default when CSS file is entrypoint: warnings 1`] = `Array []`; + exports[`"modules" option should work with the "auto" by default with "modules" filename: errors 1`] = `Array []`; exports[`"modules" option should work with the "auto" by default with "modules" filename: module 1`] = ` diff --git a/test/fixtures/modules/mode/entry.css b/test/fixtures/modules/mode/entry.css new file mode 100644 index 00000000..a95613b1 --- /dev/null +++ b/test/fixtures/modules/mode/entry.css @@ -0,0 +1,3 @@ +.class { + color: red; +} diff --git a/test/helpers/getCompiler.js b/test/helpers/getCompiler.js index fa600af8..c8e31c40 100644 --- a/test/helpers/getCompiler.js +++ b/test/helpers/getCompiler.js @@ -9,7 +9,9 @@ export default (fixture, loaderOptions = {}, config = {}) => { target: "node", devtool: config.devtool || false, context: path.resolve(__dirname, "../fixtures"), - entry: path.resolve(__dirname, "../fixtures", fixture), + entry: Array.isArray(fixture) + ? fixture + : path.resolve(__dirname, "../fixtures", fixture), output: { path: path.resolve(__dirname, "../outputs"), filename: "[name].bundle.js", diff --git a/test/modules-option.test.js b/test/modules-option.test.js index 720ca2ac..25220653 100644 --- a/test/modules-option.test.js +++ b/test/modules-option.test.js @@ -886,6 +886,26 @@ describe('"modules" option', () => { expect(getErrors(stats)).toMatchSnapshot("errors"); }); + it('should work with the "auto" by default when CSS file is entrypoint', async () => { + const compiler = getCompiler([ + "./modules/mode/entry.css", + "./modules/mode/modules.js", + ]); + const stats = await compile(compiler); + + expect(getModuleSource("./modules/mode/entry.css", stats)).toMatchSnapshot( + "entry" + ); + expect( + getModuleSource("./modules/mode/relative.module.css", stats) + ).toMatchSnapshot("module"); + expect(getExecutedCode("main.bundle.js", compiler, stats)).toMatchSnapshot( + "result" + ); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); + }); + it('should work with the "auto" by default with "modules" filename', async () => { const compiler = getCompiler("./modules/mode/modules-2.js"); const stats = await compile(compiler);