From 175729a48b1e704f45d782605422bfa733179e5c Mon Sep 17 00:00:00 2001 From: Alexander Akait <4567934+alexander-akait@users.noreply.github.com> Date: Thu, 16 Mar 2023 00:41:07 +0300 Subject: [PATCH] test: more (#1504) --- test/__snapshots__/import-option.test.js.snap | 28 +++++++++++++++++++ test/fixtures/import/dark.css | 3 ++ .../fixtures/import/list-of-media-queries.css | 5 ++++ test/fixtures/import/list-of-media-queries.js | 5 ++++ test/import-option.test.js | 14 ++++++++++ 5 files changed, 55 insertions(+) create mode 100644 test/fixtures/import/dark.css create mode 100644 test/fixtures/import/list-of-media-queries.css create mode 100644 test/fixtures/import/list-of-media-queries.js diff --git a/test/__snapshots__/import-option.test.js.snap b/test/__snapshots__/import-option.test.js.snap index e6a85f8a..a202bc3a 100644 --- a/test/__snapshots__/import-option.test.js.snap +++ b/test/__snapshots__/import-option.test.js.snap @@ -354,6 +354,34 @@ Error: Can't resolve 'unresolved-file.css' in '/test/fixtures/import'", exports[`"import" option should throw an error on unresolved import: warnings 1`] = `Array []`; +exports[`"import" option should work and output media: errors 1`] = `Array []`; + +exports[`"import" option should work and output media: module 1`] = ` +"// Imports +import ___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___ from \\"../../../src/runtime/noSourceMaps.js\\"; +import ___CSS_LOADER_API_IMPORT___ from \\"../../../src/runtime/api.js\\"; +import ___CSS_LOADER_AT_RULE_IMPORT_0___ from \\"-!../../../src/index.js??ruleSet[1].rules[0].use[0]!./dark.css\\"; +var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___); +___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_0___, \\"(prefers-color-scheme: dark)\\"); +// Module +___CSS_LOADER_EXPORT___.push([module.id, \\"a {\\\\n color: black;\\\\n}\\\\n\\", \\"\\"]); +// Exports +export default ___CSS_LOADER_EXPORT___; +" +`; + +exports[`"import" option should work and output media: result 1`] = ` +"@media (prefers-color-scheme: dark) {a { + color: white; +} +}a { + color: black; +} +" +`; + +exports[`"import" option should work and output media: warnings 1`] = `Array []`; + exports[`"import" option should work resolve order: local -> node_modules -> alias: errors 1`] = `Array []`; exports[`"import" option should work resolve order: local -> node_modules -> alias: module 1`] = ` diff --git a/test/fixtures/import/dark.css b/test/fixtures/import/dark.css new file mode 100644 index 00000000..7e53924e --- /dev/null +++ b/test/fixtures/import/dark.css @@ -0,0 +1,3 @@ +a { + color: white; +} diff --git a/test/fixtures/import/list-of-media-queries.css b/test/fixtures/import/list-of-media-queries.css new file mode 100644 index 00000000..4410be1e --- /dev/null +++ b/test/fixtures/import/list-of-media-queries.css @@ -0,0 +1,5 @@ +@import "./dark.css" (prefers-color-scheme: dark); + +a { + color: black; +} diff --git a/test/fixtures/import/list-of-media-queries.js b/test/fixtures/import/list-of-media-queries.js new file mode 100644 index 00000000..559392dd --- /dev/null +++ b/test/fixtures/import/list-of-media-queries.js @@ -0,0 +1,5 @@ +import css from './list-of-media-queries.css'; + +__export__ = css.toString(); + +export default css; diff --git a/test/import-option.test.js b/test/import-option.test.js index 7f403660..4856353c 100644 --- a/test/import-option.test.js +++ b/test/import-option.test.js @@ -574,4 +574,18 @@ describe('"import" option', () => { expect(getWarnings(stats)).toMatchSnapshot("warnings"); expect(getErrors(stats)).toMatchSnapshot("errors"); }); + + it("should work and output media", async () => { + const compiler = getCompiler("./import/list-of-media-queries.js"); + const stats = await compile(compiler); + + expect( + getModuleSource("./import/list-of-media-queries.css", stats) + ).toMatchSnapshot("module"); + expect(getExecutedCode("main.bundle.js", compiler, stats)).toMatchSnapshot( + "result" + ); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); + }); });