From 4e9fb501c510f65d853424812c2cb32d6d8f7212 Mon Sep 17 00:00:00 2001 From: cap-Bernardito Date: Sat, 1 May 2021 19:31:11 +0300 Subject: [PATCH 1/2] refactor: removed `importLoaders` in favor `import.loaders` --- README.md | 105 ++++++++++-------- src/index.js | 11 +- src/options.json | 28 ++--- src/utils.js | 9 +- test/__snapshots__/loader.test.js.snap | 6 +- .../validate-options.test.js.snap | 56 +++++----- test/importLoaders-option.test.js | 8 +- test/loader.test.js | 8 +- test/modules-option.test.js | 6 +- test/validate-options.test.js | 23 +++- 10 files changed, 147 insertions(+), 113 deletions(-) diff --git a/README.md b/README.md index dabdfd87..ceedfd4e 100644 --- a/README.md +++ b/README.md @@ -107,14 +107,13 @@ module.exports = { ## Options -| Name | Type | Default | Description | -| :-----------------------------------: | :-------------------------: | :----------------: | :--------------------------------------------------------------------- | -| **[`url`](#url)** | `{Boolean\|Object}` | `true` | Enables/Disables `url`/`image-set` functions handling | -| **[`import`](#import)** | `{Boolean\|Object}` | `true` | Enables/Disables `@import` at-rules handling | -| **[`modules`](#modules)** | `{Boolean\|String\|Object}` | `{auto: true}` | Enables/Disables CSS Modules and their configuration | -| **[`sourceMap`](#sourcemap)** | `{Boolean}` | `compiler.devtool` | Enables/Disables generation of source maps | -| **[`importLoaders`](#importloaders)** | `{Number}` | `0` | Enables/Disables or setups number of loaders applied before CSS loader | -| **[`esModule`](#esmodule)** | `{Boolean}` | `true` | Use ES modules syntax | +| Name | Type | Default | Description | +| :---------------------------: | :-------------------------: | :----------------: | :---------------------------------------------------- | +| **[`url`](#url)** | `{Boolean\|Object}` | `true` | Enables/Disables `url`/`image-set` functions handling | +| **[`import`](#import)** | `{Boolean\|Object}` | `true` | Enables/Disables `@import` at-rules handling | +| **[`modules`](#modules)** | `{Boolean\|String\|Object}` | `{auto: true}` | Enables/Disables CSS Modules and their configuration | +| **[`sourceMap`](#sourcemap)** | `{Boolean}` | `compiler.devtool` | Enables/Disables generation of source maps | +| **[`esModule`](#esmodule)** | `{Boolean}` | `true` | Use ES modules syntax | ### `url` @@ -250,6 +249,16 @@ module.exports = { #### `Object` +| Name | Type | Default | Description | +| :-----------------------: | :----------: | :---------: | :--------------------------------------------------------------------- | +| **[`filter`](#filter)** | `{Function}` | `undefined` | Allow to filter `@import` | +| **[`loaders`](#loaders)** | `{Number}` | `0` | Enables/Disables or setups number of loaders applied before CSS loader | + +##### `filter` + +Type: `Function` +Default: `undefined` + Allow to filter `@import`. All filtered `@import` will not be resolved (left in the code as they were written). **webpack.config.js** @@ -281,6 +290,47 @@ module.exports = { }; ``` +##### `loaders` + +Type: `Number` +Default: `0` + +Enables/Disables or setups number of loaders applied before CSS loader. + +The option `import.loaders` allows you to configure how many loaders before `css-loader` should be applied to `@import`ed resources. + +**webpack.config.js** + +```js +module.exports = { + module: { + rules: [ + { + test: /\.css$/i, + use: [ + "style-loader", + { + loader: "css-loader", + options: { + import: { + loaders: 2, + // 0 => no loaders (default); + // 1 => postcss-loader; + // 2 => postcss-loader, sass-loader + }, + }, + }, + "postcss-loader", + "sass-loader", + ], + }, + ], + }, +}; +``` + +This may change in the future when the module system (i. e. webpack) supports loader matching by origin. + ### `modules` Type: `Boolean|String|Object` @@ -1063,45 +1113,6 @@ module.exports = { }; ``` -### `importLoaders` - -Type: `Number` -Default: `0` - -Enables/Disables or setups number of loaders applied before CSS loader. - -The option `importLoaders` allows you to configure how many loaders before `css-loader` should be applied to `@import`ed resources. - -**webpack.config.js** - -```js -module.exports = { - module: { - rules: [ - { - test: /\.css$/i, - use: [ - "style-loader", - { - loader: "css-loader", - options: { - importLoaders: 2, - // 0 => no loaders (default); - // 1 => postcss-loader; - // 2 => postcss-loader, sass-loader - }, - }, - "postcss-loader", - "sass-loader", - ], - }, - ], - }, -}; -``` - -This may change in the future when the module system (i. e. webpack) supports loader matching by origin. - ### `esModule` Type: `Boolean` diff --git a/src/index.js b/src/index.js index 1df1d582..61c96596 100644 --- a/src/index.js +++ b/src/index.js @@ -20,6 +20,7 @@ import { getPreRequester, getExportCode, getFilter, + getImportLoaders, getImportCode, getModuleCode, getModulesPlugins, @@ -72,7 +73,10 @@ export default async function loader(content, map, meta) { urlHandler: (url) => stringifyRequest( this, - combineRequests(getPreRequester(this)(options.importLoaders), url) + combineRequests( + getPreRequester(this)(getImportLoaders(options.import.loaders)), + url + ) ), }) ); @@ -124,7 +128,10 @@ export default async function loader(content, map, meta) { urlHandler: (url) => stringifyRequest( this, - combineRequests(getPreRequester(this)(options.importLoaders), url) + combineRequests( + getPreRequester(this)(getImportLoaders(options.import.loaders)), + url + ) ), }) ); diff --git a/src/options.json b/src/options.json index 5c1797e4..f123d723 100644 --- a/src/options.json +++ b/src/options.json @@ -30,6 +30,20 @@ "properties": { "filter": { "instanceof": "Function" + }, + "loaders": { + "description": "Enables/Disables or setups number of loaders applied before CSS loader (https://github.com/webpack-contrib/css-loader#importloaders).", + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "string" + }, + { + "type": "integer" + } + ] } }, "additionalProperties": false @@ -139,20 +153,6 @@ "description": "Enables/Disables generation of source maps (https://github.com/webpack-contrib/css-loader#sourcemap).", "type": "boolean" }, - "importLoaders": { - "description": "Enables/Disables or setups number of loaders applied before CSS loader (https://github.com/webpack-contrib/css-loader#importloaders).", - "anyOf": [ - { - "type": "boolean" - }, - { - "type": "string" - }, - { - "type": "integer" - } - ] - }, "esModule": { "description": "Use the ES modules syntax (https://github.com/webpack-contrib/css-loader#esmodule).", "type": "boolean" diff --git a/src/utils.js b/src/utils.js index 9564e8e6..5079910b 100644 --- a/src/utils.js +++ b/src/utils.js @@ -256,6 +256,10 @@ function getFilter(filter, resourcePath) { }; } +function getImportLoaders(loaders) { + return typeof loaders === "string" ? parseInt(loaders, 10) : loaders; +} + function getValidLocalName(localName, exportLocalsConvention) { if (exportLocalsConvention === "dashesOnly") { return dashesCamelCase(localName); @@ -390,10 +394,6 @@ function normalizeOptions(rawOptions, loaderContext) { typeof rawOptions.sourceMap === "boolean" ? rawOptions.sourceMap : loaderContext.sourceMap, - importLoaders: - typeof rawOptions.importLoaders === "string" - ? parseInt(rawOptions.importLoaders, 10) - : rawOptions.importLoaders, esModule: typeof rawOptions.esModule === "undefined" ? true : rawOptions.esModule, }; @@ -871,6 +871,7 @@ export { normalizeUrl, requestify, getFilter, + getImportLoaders, getModulesOptions, getModulesPlugins, normalizeSourceMap, diff --git a/test/__snapshots__/loader.test.js.snap b/test/__snapshots__/loader.test.js.snap index 402c52b9..bb7dc0eb 100644 --- a/test/__snapshots__/loader.test.js.snap +++ b/test/__snapshots__/loader.test.js.snap @@ -773,9 +773,9 @@ Array [ exports[`loader should work with none AST metadata: warnings 1`] = `Array []`; -exports[`loader should work with the "modules.auto" option and the "importLoaders" option: errors 1`] = `Array []`; +exports[`loader should work with the "modules.auto" option and the "import.loaders" option: errors 1`] = `Array []`; -exports[`loader should work with the "modules.auto" option and the "importLoaders" option: result 1`] = ` +exports[`loader should work with the "modules.auto" option and the "import.loaders" option: result 1`] = ` "/* Pure CSS */ .imported-by-pure { overflow-x: hidden; @@ -841,7 +841,7 @@ exports[`loader should work with the "modules.auto" option and the "importLoader " `; -exports[`loader should work with the "modules.auto" option and the "importLoaders" option: warnings 1`] = `Array []`; +exports[`loader should work with the "modules.auto" option and the "import.loaders" option: warnings 1`] = `Array []`; exports[`loader should work with webpackIgnore comment: errors 1`] = `Array []`; diff --git a/test/__snapshots__/validate-options.test.js.snap b/test/__snapshots__/validate-options.test.js.snap index 879b9e86..1a5d9a19 100644 --- a/test/__snapshots__/validate-options.test.js.snap +++ b/test/__snapshots__/validate-options.test.js.snap @@ -9,23 +9,23 @@ exports[`validate options should throw an error on the "esModule" option with "t exports[`validate options should throw an error on the "import" option with "() => {}" value 1`] = ` "Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema. - options.import should be one of these: - boolean | object { filter? } + boolean | object { filter?, loaders? } -> Enables/Disables '@import' at-rules handling (https://github.com/webpack-contrib/css-loader#import). Details: * options.import should be a boolean. * options.import should be an object: - object { filter? }" + object { filter?, loaders? }" `; exports[`validate options should throw an error on the "import" option with "[]" value 1`] = ` "Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema. - options.import should be one of these: - boolean | object { filter? } + boolean | object { filter?, loaders? } -> Enables/Disables '@import' at-rules handling (https://github.com/webpack-contrib/css-loader#import). Details: * options.import should be a boolean. * options.import should be an object: - object { filter? }" + object { filter?, loaders? }" `; exports[`validate options should throw an error on the "import" option with "{"filter":true}" value 1`] = ` @@ -33,32 +33,36 @@ exports[`validate options should throw an error on the "import" option with "{"f - options.import.filter should be an instance of function." `; +exports[`validate options should throw an error on the "import" option with "{"loaders":2.5}" value 1`] = ` +"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema. + - options.import should be one of these: + boolean | object { filter?, loaders? } + -> Enables/Disables '@import' at-rules handling (https://github.com/webpack-contrib/css-loader#import). + Details: + * options.import.loaders should be one of these: + boolean | string | integer + -> Enables/Disables or setups number of loaders applied before CSS loader (https://github.com/webpack-contrib/css-loader#importloaders). + Details: + * options.import.loaders should be a boolean. + * options.import.loaders should be a string. + * options.import.loaders should be a integer." +`; + exports[`validate options should throw an error on the "import" option with "{}" value 1`] = ` "Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema. - options.import has an unknown property 'unknown'. These properties are valid: - object { filter? }" + object { filter?, loaders? }" `; exports[`validate options should throw an error on the "import" option with "true" value 1`] = ` "Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema. - options.import should be one of these: - boolean | object { filter? } + boolean | object { filter?, loaders? } -> Enables/Disables '@import' at-rules handling (https://github.com/webpack-contrib/css-loader#import). Details: * options.import should be a boolean. * options.import should be an object: - object { filter? }" -`; - -exports[`validate options should throw an error on the "importLoaders" option with "2.5" value 1`] = ` -"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema. - - options.importLoaders should be one of these: - boolean | string | integer - -> Enables/Disables or setups number of loaders applied before CSS loader (https://github.com/webpack-contrib/css-loader#importloaders). - Details: - * options.importLoaders should be a boolean. - * options.importLoaders should be a string. - * options.importLoaders should be a integer." + object { filter?, loaders? }" `; exports[`validate options should throw an error on the "modules" option with "{"auto":"invalid"}" value 1`] = ` @@ -267,49 +271,49 @@ exports[`validate options should throw an error on the "sourceMap" option with " exports[`validate options should throw an error on the "unknown" option with "/test/" value 1`] = ` "Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema. - options has an unknown property 'unknown'. These properties are valid: - object { url?, import?, modules?, sourceMap?, importLoaders?, esModule? }" + object { url?, import?, modules?, sourceMap?, esModule? }" `; exports[`validate options should throw an error on the "unknown" option with "[]" value 1`] = ` "Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema. - options has an unknown property 'unknown'. These properties are valid: - object { url?, import?, modules?, sourceMap?, importLoaders?, esModule? }" + object { url?, import?, modules?, sourceMap?, esModule? }" `; exports[`validate options should throw an error on the "unknown" option with "{"foo":"bar"}" value 1`] = ` "Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema. - options has an unknown property 'unknown'. These properties are valid: - object { url?, import?, modules?, sourceMap?, importLoaders?, esModule? }" + object { url?, import?, modules?, sourceMap?, esModule? }" `; exports[`validate options should throw an error on the "unknown" option with "{}" value 1`] = ` "Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema. - options has an unknown property 'unknown'. These properties are valid: - object { url?, import?, modules?, sourceMap?, importLoaders?, esModule? }" + object { url?, import?, modules?, sourceMap?, esModule? }" `; exports[`validate options should throw an error on the "unknown" option with "1" value 1`] = ` "Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema. - options has an unknown property 'unknown'. These properties are valid: - object { url?, import?, modules?, sourceMap?, importLoaders?, esModule? }" + object { url?, import?, modules?, sourceMap?, esModule? }" `; exports[`validate options should throw an error on the "unknown" option with "false" value 1`] = ` "Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema. - options has an unknown property 'unknown'. These properties are valid: - object { url?, import?, modules?, sourceMap?, importLoaders?, esModule? }" + object { url?, import?, modules?, sourceMap?, esModule? }" `; exports[`validate options should throw an error on the "unknown" option with "test" value 1`] = ` "Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema. - options has an unknown property 'unknown'. These properties are valid: - object { url?, import?, modules?, sourceMap?, importLoaders?, esModule? }" + object { url?, import?, modules?, sourceMap?, esModule? }" `; exports[`validate options should throw an error on the "unknown" option with "true" value 1`] = ` "Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema. - options has an unknown property 'unknown'. These properties are valid: - object { url?, import?, modules?, sourceMap?, importLoaders?, esModule? }" + object { url?, import?, modules?, sourceMap?, esModule? }" `; exports[`validate options should throw an error on the "url" option with "() => {}" value 1`] = ` diff --git a/test/importLoaders-option.test.js b/test/importLoaders-option.test.js index 11071f6f..60f52ae4 100644 --- a/test/importLoaders-option.test.js +++ b/test/importLoaders-option.test.js @@ -61,7 +61,7 @@ describe('"importLoaders" option', () => { use: [ { loader: path.resolve(__dirname, "../src"), - options: { importLoaders: 0 }, + options: { import: { loaders: 0 } }, }, { loader: "postcss-loader", @@ -115,7 +115,7 @@ describe('"importLoaders" option', () => { use: [ { loader: path.resolve(__dirname, "../src"), - options: { importLoaders: 1 }, + options: { import: { loaders: 1 } }, }, { loader: "postcss-loader", @@ -155,7 +155,7 @@ describe('"importLoaders" option', () => { use: [ { loader: path.resolve(__dirname, "../src"), - options: { importLoaders: 2 }, + options: { import: { loaders: 2 } }, }, { loader: "postcss-loader", @@ -195,7 +195,7 @@ describe('"importLoaders" option', () => { use: [ { loader: path.resolve(__dirname, "../src"), - options: { importLoaders: "1" }, + options: { import: { loaders: "1" } }, }, { loader: "postcss-loader", diff --git a/test/loader.test.js b/test/loader.test.js index aa2fa61b..edfd224e 100644 --- a/test/loader.test.js +++ b/test/loader.test.js @@ -137,7 +137,7 @@ describe("loader", () => { rules: [ { loader: path.resolve(__dirname, "../src"), - options: { importLoaders: 1 }, + options: { import: { loaders: 1 } }, }, { loader: require.resolve("./helpers/ast-loader"), @@ -335,7 +335,7 @@ describe("loader", () => { expect(getErrors(stats, false, "postcss")).toMatchSnapshot("errors"); }); - it('should work with the "modules.auto" option and the "importLoaders" option', async () => { + it('should work with the "modules.auto" option and the "import.loaders" option', async () => { const compiler = getCompiler( "./integration/index.js", {}, @@ -350,7 +350,7 @@ describe("loader", () => { options: { // Run only `postcss-loader` on each `@import` // If you need run `sass-loader` and `postcss-loader` please set it to `2` - importLoaders: 1, + import: { loaders: 1 }, // Automatically enable css modules for files satisfying `/\.module\.\w+$/i` RegExp. modules: { auto: true }, }, @@ -509,7 +509,7 @@ describe("loader", () => { rules: [ { loader: path.resolve(__dirname, "../src"), - options: { importLoaders: 1 }, + options: { import: { loaders: 1 } }, }, { loader: "sass-loader", diff --git a/test/modules-option.test.js b/test/modules-option.test.js index 8115c67d..4e04bf9e 100644 --- a/test/modules-option.test.js +++ b/test/modules-option.test.js @@ -377,7 +377,7 @@ describe('"modules" option', () => { test: /source\.css$/, loader: path.resolve(__dirname, "../src"), options: { - importLoaders: false, + import: { loaders: false }, modules: { localIdentName: "b--[local]", }, @@ -387,7 +387,7 @@ describe('"modules" option', () => { test: /dep\.css$/, loader: path.resolve(__dirname, "../src"), options: { - importLoaders: false, + import: { loaders: false }, modules: { localIdentName: "a--[local]", }, @@ -427,7 +427,7 @@ describe('"modules" option', () => { getLocalIdent: (context, localIdentName, localName) => `prefix-${localName}`, }, - importLoaders: 1, + import: { loaders: 1 }, }, }, { diff --git a/test/validate-options.test.js b/test/validate-options.test.js index 2a9e7cc8..92403a4e 100644 --- a/test/validate-options.test.js +++ b/test/validate-options.test.js @@ -7,8 +7,23 @@ describe("validate options", () => { failure: ["true", [], () => {}, { filter: true }, { unknown: () => {} }], }, import: { - success: [true, false, { filter: () => true }], - failure: ["true", [], () => {}, { filter: true }, { unknown: () => {} }], + success: [ + true, + false, + { filter: () => true }, + { loaders: false }, + { loaders: 0 }, + { loaders: 1 }, + { loaders: "1" }, + ], + failure: [ + "true", + [], + () => {}, + { filter: true }, + { unknown: () => {} }, + { loaders: 2.5 }, + ], }, modules: { success: [ @@ -73,10 +88,6 @@ describe("validate options", () => { success: [true, false], failure: ["true"], }, - importLoaders: { - success: [false, 0, 1, 2, "1"], - failure: [2.5], - }, esModule: { success: [true, false], failure: ["true"], From 1df1c046a29eb1798db202d47339a0395d34a8bd Mon Sep 17 00:00:00 2001 From: cap-Bernardito Date: Sat, 1 May 2021 19:35:15 +0300 Subject: [PATCH 2/2] test: update --- test/__snapshots__/import-option.test.js.snap | 306 +++++++++++++++++ .../importLoaders-option.test.js.snap | 307 ------------------ test/import-option.test.js | 213 ++++++++++++ test/importLoaders-option.test.js | 225 ------------- 4 files changed, 519 insertions(+), 532 deletions(-) delete mode 100644 test/__snapshots__/importLoaders-option.test.js.snap delete mode 100644 test/importLoaders-option.test.js diff --git a/test/__snapshots__/import-option.test.js.snap b/test/__snapshots__/import-option.test.js.snap index 2ac0b848..0c48d28f 100644 --- a/test/__snapshots__/import-option.test.js.snap +++ b/test/__snapshots__/import-option.test.js.snap @@ -410,6 +410,57 @@ Array [ exports[`"import" option should work resolve order: local -> node_modules -> alias: warnings 1`] = `Array []`; +exports[`"import" option should work when 'import.loaders' not specified: errors 1`] = `Array []`; + +exports[`"import" option should work when 'import.loaders' not specified: module 1`] = ` +"// Imports +import ___CSS_LOADER_API_IMPORT___ from \\"../../../src/runtime/api.js\\"; +import ___CSS_LOADER_AT_RULE_IMPORT_0___ from \\"-!../../../src/index.js!./imported.css\\"; +import ___CSS_LOADER_AT_RULE_IMPORT_1___ from \\"-!../../../src/index.js!./other-imported.css\\"; +var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(function(i){return i[1]}); +___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_0___); +___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_1___); +// Module +___CSS_LOADER_EXPORT___.push([module.id, \\".foo {\\\\n color: red;\\\\n color: rgba(0, 0, 255, 0.9);\\\\n}\\\\n\\", \\"\\"]); +// Exports +export default ___CSS_LOADER_EXPORT___; +" +`; + +exports[`"import" option should work when 'import.loaders' not specified: result 1`] = ` +Array [ + Array [ + "../../src/index.js!./nested-import/imported.css", + ".bar { + color: blue; + color: rgb(0 0 100% / 90%); +} +", + "", + ], + Array [ + "../../src/index.js!./nested-import/other-imported.css", + ".baz { + color: green; + color: rgb(0 0 100% / 90%); +} +", + "", + ], + Array [ + "./nested-import/source.css", + ".foo { + color: red; + color: rgba(0, 0, 255, 0.9); +} +", + "", + ], +] +`; + +exports[`"import" option should work when 'import.loaders' not specified: warnings 1`] = `Array []`; + exports[`"import" option should work when not specified: errors 1`] = `Array []`; exports[`"import" option should work when not specified: module 1`] = ` @@ -1347,6 +1398,261 @@ Array [ exports[`"import" option should work with 'false' aliases: warnings 1`] = `Array []`; +exports[`"import" option should work with a "import.loaders" value equal to ""1"" ("postcss-loader" before): errors 1`] = `Array []`; + +exports[`"import" option should work with a "import.loaders" value equal to ""1"" ("postcss-loader" before): module 1`] = ` +"// Imports +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]!../../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./imported.css\\"; +import ___CSS_LOADER_AT_RULE_IMPORT_1___ from \\"-!../../../src/index.js??ruleSet[1].rules[0].use[0]!../../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./other-imported.css\\"; +var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(function(i){return i[1]}); +___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_0___); +___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_1___); +// Module +___CSS_LOADER_EXPORT___.push([module.id, \\".foo {\\\\n color: red;\\\\n color: rgba(0, 0, 255, 0.9);\\\\n}\\\\n\\", \\"\\"]); +// Exports +export default ___CSS_LOADER_EXPORT___; +" +`; + +exports[`"import" option should work with a "import.loaders" value equal to ""1"" ("postcss-loader" before): result 1`] = ` +Array [ + Array [ + "../../src/index.js??ruleSet[1].rules[0].use[0]!../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./nested-import/imported.css", + ".bar { + color: blue; + color: rgba(0, 0, 255, 0.9); +} +", + "", + ], + Array [ + "../../src/index.js??ruleSet[1].rules[0].use[0]!../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./nested-import/other-imported.css", + ".baz { + color: green; + color: rgba(0, 0, 255, 0.9); +} +", + "", + ], + Array [ + "./nested-import/source.css", + ".foo { + color: red; + color: rgba(0, 0, 255, 0.9); +} +", + "", + ], +] +`; + +exports[`"import" option should work with a "import.loaders" value equal to ""1"" ("postcss-loader" before): warnings 1`] = `Array []`; + +exports[`"import" option should work with a "import.loaders" value equal to "0" (\`postcss-loader\` before): errors 1`] = `Array []`; + +exports[`"import" option should work with a "import.loaders" value equal to "0" (\`postcss-loader\` before): module 1`] = ` +"// Imports +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]!./imported.css\\"; +import ___CSS_LOADER_AT_RULE_IMPORT_1___ from \\"-!../../../src/index.js??ruleSet[1].rules[0].use[0]!./other-imported.css\\"; +var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(function(i){return i[1]}); +___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_0___); +___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_1___); +// Module +___CSS_LOADER_EXPORT___.push([module.id, \\".foo {\\\\n color: red;\\\\n color: rgba(0, 0, 255, 0.9);\\\\n}\\\\n\\", \\"\\"]); +// Exports +export default ___CSS_LOADER_EXPORT___; +" +`; + +exports[`"import" option should work with a "import.loaders" value equal to "0" (\`postcss-loader\` before): result 1`] = ` +Array [ + Array [ + "../../src/index.js??ruleSet[1].rules[0].use[0]!./nested-import/imported.css", + ".bar { + color: blue; + color: rgb(0 0 100% / 90%); +} +", + "", + ], + Array [ + "../../src/index.js??ruleSet[1].rules[0].use[0]!./nested-import/other-imported.css", + ".baz { + color: green; + color: rgb(0 0 100% / 90%); +} +", + "", + ], + Array [ + "./nested-import/source.css", + ".foo { + color: red; + color: rgba(0, 0, 255, 0.9); +} +", + "", + ], +] +`; + +exports[`"import" option should work with a "import.loaders" value equal to "0" (\`postcss-loader\` before): warnings 1`] = `Array []`; + +exports[`"import" option should work with a "import.loaders" value equal to "1" ("postcss-loader" before): errors 1`] = `Array []`; + +exports[`"import" option should work with a "import.loaders" value equal to "1" ("postcss-loader" before): module 1`] = ` +"// Imports +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]!../../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./imported.css\\"; +import ___CSS_LOADER_AT_RULE_IMPORT_1___ from \\"-!../../../src/index.js??ruleSet[1].rules[0].use[0]!../../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./other-imported.css\\"; +var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(function(i){return i[1]}); +___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_0___); +___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_1___); +// Module +___CSS_LOADER_EXPORT___.push([module.id, \\".foo {\\\\n color: red;\\\\n color: rgba(0, 0, 255, 0.9);\\\\n}\\\\n\\", \\"\\"]); +// Exports +export default ___CSS_LOADER_EXPORT___; +" +`; + +exports[`"import" option should work with a "import.loaders" value equal to "1" ("postcss-loader" before): result 1`] = ` +Array [ + Array [ + "../../src/index.js??ruleSet[1].rules[0].use[0]!../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./nested-import/imported.css", + ".bar { + color: blue; + color: rgba(0, 0, 255, 0.9); +} +", + "", + ], + Array [ + "../../src/index.js??ruleSet[1].rules[0].use[0]!../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./nested-import/other-imported.css", + ".baz { + color: green; + color: rgba(0, 0, 255, 0.9); +} +", + "", + ], + Array [ + "./nested-import/source.css", + ".foo { + color: red; + color: rgba(0, 0, 255, 0.9); +} +", + "", + ], +] +`; + +exports[`"import" option should work with a "import.loaders" value equal to "1" ("postcss-loader" before): warnings 1`] = `Array []`; + +exports[`"import" option should work with a "import.loaders" value equal to "1" (no loaders before): errors 1`] = `Array []`; + +exports[`"import" option should work with a "import.loaders" value equal to "1" (no loaders before): module 1`] = ` +"// Imports +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]!./imported.css\\"; +import ___CSS_LOADER_AT_RULE_IMPORT_1___ from \\"-!../../../src/index.js??ruleSet[1].rules[0].use[0]!./other-imported.css\\"; +var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(function(i){return i[1]}); +___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_0___); +___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_1___); +// Module +___CSS_LOADER_EXPORT___.push([module.id, \\".foo {\\\\n color: red;\\\\n color: rgb(0 0 100% / 90%);\\\\n}\\\\n\\", \\"\\"]); +// Exports +export default ___CSS_LOADER_EXPORT___; +" +`; + +exports[`"import" option should work with a "import.loaders" value equal to "1" (no loaders before): result 1`] = ` +Array [ + Array [ + "../../src/index.js??ruleSet[1].rules[0].use[0]!./nested-import/imported.css", + ".bar { + color: blue; + color: rgb(0 0 100% / 90%); +} +", + "", + ], + Array [ + "../../src/index.js??ruleSet[1].rules[0].use[0]!./nested-import/other-imported.css", + ".baz { + color: green; + color: rgb(0 0 100% / 90%); +} +", + "", + ], + Array [ + "./nested-import/source.css", + ".foo { + color: red; + color: rgb(0 0 100% / 90%); +} +", + "", + ], +] +`; + +exports[`"import" option should work with a "import.loaders" value equal to "1" (no loaders before): warnings 1`] = `Array []`; + +exports[`"import" option should work with a "import.loaders" value equal to "2" ("postcss-loader" before): errors 1`] = `Array []`; + +exports[`"import" option should work with a "import.loaders" value equal to "2" ("postcss-loader" before): module 1`] = ` +"// Imports +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]!../../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./imported.css\\"; +import ___CSS_LOADER_AT_RULE_IMPORT_1___ from \\"-!../../../src/index.js??ruleSet[1].rules[0].use[0]!../../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./other-imported.css\\"; +var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(function(i){return i[1]}); +___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_0___); +___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_1___); +// Module +___CSS_LOADER_EXPORT___.push([module.id, \\".foo {\\\\n color: red;\\\\n color: rgba(0, 0, 255, 0.9);\\\\n}\\\\n\\", \\"\\"]); +// Exports +export default ___CSS_LOADER_EXPORT___; +" +`; + +exports[`"import" option should work with a "import.loaders" value equal to "2" ("postcss-loader" before): result 1`] = ` +Array [ + Array [ + "../../src/index.js??ruleSet[1].rules[0].use[0]!../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./nested-import/imported.css", + ".bar { + color: blue; + color: rgba(0, 0, 255, 0.9); +} +", + "", + ], + Array [ + "../../src/index.js??ruleSet[1].rules[0].use[0]!../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./nested-import/other-imported.css", + ".baz { + color: green; + color: rgba(0, 0, 255, 0.9); +} +", + "", + ], + Array [ + "./nested-import/source.css", + ".foo { + color: red; + color: rgba(0, 0, 255, 0.9); +} +", + "", + ], +] +`; + +exports[`"import" option should work with a "import.loaders" value equal to "2" ("postcss-loader" before): warnings 1`] = `Array []`; + exports[`"import" option should work with a value equal to "false": errors 1`] = `Array []`; exports[`"import" option should work with a value equal to "false": module 1`] = ` diff --git a/test/__snapshots__/importLoaders-option.test.js.snap b/test/__snapshots__/importLoaders-option.test.js.snap deleted file mode 100644 index feda8a6d..00000000 --- a/test/__snapshots__/importLoaders-option.test.js.snap +++ /dev/null @@ -1,307 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`"importLoaders" option should work when not specified: errors 1`] = `Array []`; - -exports[`"importLoaders" option should work when not specified: module 1`] = ` -"// Imports -import ___CSS_LOADER_API_IMPORT___ from \\"../../../src/runtime/api.js\\"; -import ___CSS_LOADER_AT_RULE_IMPORT_0___ from \\"-!../../../src/index.js!./imported.css\\"; -import ___CSS_LOADER_AT_RULE_IMPORT_1___ from \\"-!../../../src/index.js!./other-imported.css\\"; -var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(function(i){return i[1]}); -___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_0___); -___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_1___); -// Module -___CSS_LOADER_EXPORT___.push([module.id, \\".foo {\\\\n color: red;\\\\n color: rgba(0, 0, 255, 0.9);\\\\n}\\\\n\\", \\"\\"]); -// Exports -export default ___CSS_LOADER_EXPORT___; -" -`; - -exports[`"importLoaders" option should work when not specified: result 1`] = ` -Array [ - Array [ - "../../src/index.js!./nested-import/imported.css", - ".bar { - color: blue; - color: rgb(0 0 100% / 90%); -} -", - "", - ], - Array [ - "../../src/index.js!./nested-import/other-imported.css", - ".baz { - color: green; - color: rgb(0 0 100% / 90%); -} -", - "", - ], - Array [ - "./nested-import/source.css", - ".foo { - color: red; - color: rgba(0, 0, 255, 0.9); -} -", - "", - ], -] -`; - -exports[`"importLoaders" option should work when not specified: warnings 1`] = `Array []`; - -exports[`"importLoaders" option should work with a value equal to ""1"" ("postcss-loader" before): errors 1`] = `Array []`; - -exports[`"importLoaders" option should work with a value equal to ""1"" ("postcss-loader" before): module 1`] = ` -"// Imports -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]!../../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./imported.css\\"; -import ___CSS_LOADER_AT_RULE_IMPORT_1___ from \\"-!../../../src/index.js??ruleSet[1].rules[0].use[0]!../../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./other-imported.css\\"; -var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(function(i){return i[1]}); -___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_0___); -___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_1___); -// Module -___CSS_LOADER_EXPORT___.push([module.id, \\".foo {\\\\n color: red;\\\\n color: rgba(0, 0, 255, 0.9);\\\\n}\\\\n\\", \\"\\"]); -// Exports -export default ___CSS_LOADER_EXPORT___; -" -`; - -exports[`"importLoaders" option should work with a value equal to ""1"" ("postcss-loader" before): result 1`] = ` -Array [ - Array [ - "../../src/index.js??ruleSet[1].rules[0].use[0]!../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./nested-import/imported.css", - ".bar { - color: blue; - color: rgba(0, 0, 255, 0.9); -} -", - "", - ], - Array [ - "../../src/index.js??ruleSet[1].rules[0].use[0]!../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./nested-import/other-imported.css", - ".baz { - color: green; - color: rgba(0, 0, 255, 0.9); -} -", - "", - ], - Array [ - "./nested-import/source.css", - ".foo { - color: red; - color: rgba(0, 0, 255, 0.9); -} -", - "", - ], -] -`; - -exports[`"importLoaders" option should work with a value equal to ""1"" ("postcss-loader" before): warnings 1`] = `Array []`; - -exports[`"importLoaders" option should work with a value equal to "0" (\`postcss-loader\` before): errors 1`] = `Array []`; - -exports[`"importLoaders" option should work with a value equal to "0" (\`postcss-loader\` before): module 1`] = ` -"// Imports -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]!./imported.css\\"; -import ___CSS_LOADER_AT_RULE_IMPORT_1___ from \\"-!../../../src/index.js??ruleSet[1].rules[0].use[0]!./other-imported.css\\"; -var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(function(i){return i[1]}); -___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_0___); -___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_1___); -// Module -___CSS_LOADER_EXPORT___.push([module.id, \\".foo {\\\\n color: red;\\\\n color: rgba(0, 0, 255, 0.9);\\\\n}\\\\n\\", \\"\\"]); -// Exports -export default ___CSS_LOADER_EXPORT___; -" -`; - -exports[`"importLoaders" option should work with a value equal to "0" (\`postcss-loader\` before): result 1`] = ` -Array [ - Array [ - "../../src/index.js??ruleSet[1].rules[0].use[0]!./nested-import/imported.css", - ".bar { - color: blue; - color: rgb(0 0 100% / 90%); -} -", - "", - ], - Array [ - "../../src/index.js??ruleSet[1].rules[0].use[0]!./nested-import/other-imported.css", - ".baz { - color: green; - color: rgb(0 0 100% / 90%); -} -", - "", - ], - Array [ - "./nested-import/source.css", - ".foo { - color: red; - color: rgba(0, 0, 255, 0.9); -} -", - "", - ], -] -`; - -exports[`"importLoaders" option should work with a value equal to "0" (\`postcss-loader\` before): warnings 1`] = `Array []`; - -exports[`"importLoaders" option should work with a value equal to "1" ("postcss-loader" before): errors 1`] = `Array []`; - -exports[`"importLoaders" option should work with a value equal to "1" ("postcss-loader" before): module 1`] = ` -"// Imports -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]!../../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./imported.css\\"; -import ___CSS_LOADER_AT_RULE_IMPORT_1___ from \\"-!../../../src/index.js??ruleSet[1].rules[0].use[0]!../../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./other-imported.css\\"; -var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(function(i){return i[1]}); -___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_0___); -___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_1___); -// Module -___CSS_LOADER_EXPORT___.push([module.id, \\".foo {\\\\n color: red;\\\\n color: rgba(0, 0, 255, 0.9);\\\\n}\\\\n\\", \\"\\"]); -// Exports -export default ___CSS_LOADER_EXPORT___; -" -`; - -exports[`"importLoaders" option should work with a value equal to "1" ("postcss-loader" before): result 1`] = ` -Array [ - Array [ - "../../src/index.js??ruleSet[1].rules[0].use[0]!../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./nested-import/imported.css", - ".bar { - color: blue; - color: rgba(0, 0, 255, 0.9); -} -", - "", - ], - Array [ - "../../src/index.js??ruleSet[1].rules[0].use[0]!../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./nested-import/other-imported.css", - ".baz { - color: green; - color: rgba(0, 0, 255, 0.9); -} -", - "", - ], - Array [ - "./nested-import/source.css", - ".foo { - color: red; - color: rgba(0, 0, 255, 0.9); -} -", - "", - ], -] -`; - -exports[`"importLoaders" option should work with a value equal to "1" ("postcss-loader" before): warnings 1`] = `Array []`; - -exports[`"importLoaders" option should work with a value equal to "1" (no loaders before): errors 1`] = `Array []`; - -exports[`"importLoaders" option should work with a value equal to "1" (no loaders before): module 1`] = ` -"// Imports -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]!./imported.css\\"; -import ___CSS_LOADER_AT_RULE_IMPORT_1___ from \\"-!../../../src/index.js??ruleSet[1].rules[0].use[0]!./other-imported.css\\"; -var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(function(i){return i[1]}); -___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_0___); -___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_1___); -// Module -___CSS_LOADER_EXPORT___.push([module.id, \\".foo {\\\\n color: red;\\\\n color: rgb(0 0 100% / 90%);\\\\n}\\\\n\\", \\"\\"]); -// Exports -export default ___CSS_LOADER_EXPORT___; -" -`; - -exports[`"importLoaders" option should work with a value equal to "1" (no loaders before): result 1`] = ` -Array [ - Array [ - "../../src/index.js??ruleSet[1].rules[0].use[0]!./nested-import/imported.css", - ".bar { - color: blue; - color: rgb(0 0 100% / 90%); -} -", - "", - ], - Array [ - "../../src/index.js??ruleSet[1].rules[0].use[0]!./nested-import/other-imported.css", - ".baz { - color: green; - color: rgb(0 0 100% / 90%); -} -", - "", - ], - Array [ - "./nested-import/source.css", - ".foo { - color: red; - color: rgb(0 0 100% / 90%); -} -", - "", - ], -] -`; - -exports[`"importLoaders" option should work with a value equal to "1" (no loaders before): warnings 1`] = `Array []`; - -exports[`"importLoaders" option should work with a value equal to "2" ("postcss-loader" before): errors 1`] = `Array []`; - -exports[`"importLoaders" option should work with a value equal to "2" ("postcss-loader" before): module 1`] = ` -"// Imports -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]!../../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./imported.css\\"; -import ___CSS_LOADER_AT_RULE_IMPORT_1___ from \\"-!../../../src/index.js??ruleSet[1].rules[0].use[0]!../../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./other-imported.css\\"; -var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(function(i){return i[1]}); -___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_0___); -___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_1___); -// Module -___CSS_LOADER_EXPORT___.push([module.id, \\".foo {\\\\n color: red;\\\\n color: rgba(0, 0, 255, 0.9);\\\\n}\\\\n\\", \\"\\"]); -// Exports -export default ___CSS_LOADER_EXPORT___; -" -`; - -exports[`"importLoaders" option should work with a value equal to "2" ("postcss-loader" before): result 1`] = ` -Array [ - Array [ - "../../src/index.js??ruleSet[1].rules[0].use[0]!../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./nested-import/imported.css", - ".bar { - color: blue; - color: rgba(0, 0, 255, 0.9); -} -", - "", - ], - Array [ - "../../src/index.js??ruleSet[1].rules[0].use[0]!../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./nested-import/other-imported.css", - ".baz { - color: green; - color: rgba(0, 0, 255, 0.9); -} -", - "", - ], - Array [ - "./nested-import/source.css", - ".foo { - color: red; - color: rgba(0, 0, 255, 0.9); -} -", - "", - ], -] -`; - -exports[`"importLoaders" option should work with a value equal to "2" ("postcss-loader" before): warnings 1`] = `Array []`; diff --git a/test/import-option.test.js b/test/import-option.test.js index b1d161bd..4afe3318 100644 --- a/test/import-option.test.js +++ b/test/import-option.test.js @@ -1,6 +1,8 @@ import fs from "fs"; import path from "path"; +import postcssPresetEnv from "postcss-preset-env"; + import { compile, getCompiler, @@ -237,4 +239,215 @@ describe('"import" option', () => { expect(getWarnings(stats)).toMatchSnapshot("warnings"); expect(getErrors(stats, true)).toMatchSnapshot("errors"); }); + + it("should work when 'import.loaders' not specified", async () => { + const compiler = getCompiler( + "./nested-import/source.js", + {}, + { + module: { + rules: [ + { + test: /\.css$/i, + rules: [ + { loader: path.resolve(__dirname, "../src") }, + { + loader: "postcss-loader", + options: { + postcssOptions: { + plugins: [postcssPresetEnv({ stage: 0 })], + }, + }, + }, + ], + }, + ], + }, + } + ); + const stats = await compile(compiler); + + expect( + getModuleSource("./nested-import/source.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 a "import.loaders" value equal to "0" (`postcss-loader` before)', async () => { + const compiler = getCompiler( + "./nested-import/source.js", + {}, + { + module: { + rules: [ + { + test: /\.css$/i, + use: [ + { + loader: path.resolve(__dirname, "../src"), + options: { import: { loaders: 0 } }, + }, + { + loader: "postcss-loader", + options: { + postcssOptions: { + plugins: [postcssPresetEnv({ stage: 0 })], + }, + }, + }, + ], + }, + ], + }, + } + ); + const stats = await compile(compiler); + + expect( + getModuleSource("./nested-import/source.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 a "import.loaders" value equal to "1" (no loaders before)', async () => { + const compiler = getCompiler("./nested-import/source.js"); + const stats = await compile(compiler); + + expect( + getModuleSource("./nested-import/source.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 a "import.loaders" value equal to "1" ("postcss-loader" before)', async () => { + const compiler = getCompiler( + "./nested-import/source.js", + {}, + { + module: { + rules: [ + { + test: /\.css$/i, + use: [ + { + loader: path.resolve(__dirname, "../src"), + options: { import: { loaders: 1 } }, + }, + { + loader: "postcss-loader", + options: { + postcssOptions: { + plugins: [postcssPresetEnv({ stage: 0 })], + }, + }, + }, + ], + }, + ], + }, + } + ); + const stats = await compile(compiler); + + expect( + getModuleSource("./nested-import/source.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 a "import.loaders" value equal to "2" ("postcss-loader" before)', async () => { + const compiler = getCompiler( + "./nested-import/source.js", + {}, + { + module: { + rules: [ + { + test: /\.css$/i, + use: [ + { + loader: path.resolve(__dirname, "../src"), + options: { import: { loaders: 2 } }, + }, + { + loader: "postcss-loader", + options: { + postcssOptions: { + plugins: [postcssPresetEnv({ stage: 0 })], + }, + }, + }, + ], + }, + ], + }, + } + ); + const stats = await compile(compiler); + + expect( + getModuleSource("./nested-import/source.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 a "import.loaders" value equal to ""1"" ("postcss-loader" before)', async () => { + const compiler = getCompiler( + "./nested-import/source.js", + {}, + { + module: { + rules: [ + { + test: /\.css$/i, + use: [ + { + loader: path.resolve(__dirname, "../src"), + options: { import: { loaders: "1" } }, + }, + { + loader: "postcss-loader", + options: { + postcssOptions: { + plugins: [postcssPresetEnv({ stage: 0 })], + }, + }, + }, + ], + }, + ], + }, + } + ); + const stats = await compile(compiler); + + expect( + getModuleSource("./nested-import/source.css", stats) + ).toMatchSnapshot("module"); + expect(getExecutedCode("main.bundle.js", compiler, stats)).toMatchSnapshot( + "result" + ); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); + }); }); diff --git a/test/importLoaders-option.test.js b/test/importLoaders-option.test.js deleted file mode 100644 index 60f52ae4..00000000 --- a/test/importLoaders-option.test.js +++ /dev/null @@ -1,225 +0,0 @@ -import path from "path"; - -import postcssPresetEnv from "postcss-preset-env"; - -import { - compile, - getCompiler, - getErrors, - getExecutedCode, - getModuleSource, - getWarnings, -} from "./helpers/index"; - -describe('"importLoaders" option', () => { - it("should work when not specified", async () => { - const compiler = getCompiler( - "./nested-import/source.js", - {}, - { - module: { - rules: [ - { - test: /\.css$/i, - rules: [ - { loader: path.resolve(__dirname, "../src") }, - { - loader: "postcss-loader", - options: { - postcssOptions: { - plugins: [postcssPresetEnv({ stage: 0 })], - }, - }, - }, - ], - }, - ], - }, - } - ); - const stats = await compile(compiler); - - expect( - getModuleSource("./nested-import/source.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 a value equal to "0" (`postcss-loader` before)', async () => { - const compiler = getCompiler( - "./nested-import/source.js", - {}, - { - module: { - rules: [ - { - test: /\.css$/i, - use: [ - { - loader: path.resolve(__dirname, "../src"), - options: { import: { loaders: 0 } }, - }, - { - loader: "postcss-loader", - options: { - postcssOptions: { - plugins: [postcssPresetEnv({ stage: 0 })], - }, - }, - }, - ], - }, - ], - }, - } - ); - const stats = await compile(compiler); - - expect( - getModuleSource("./nested-import/source.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 a value equal to "1" (no loaders before)', async () => { - const compiler = getCompiler("./nested-import/source.js"); - const stats = await compile(compiler); - - expect( - getModuleSource("./nested-import/source.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 a value equal to "1" ("postcss-loader" before)', async () => { - const compiler = getCompiler( - "./nested-import/source.js", - {}, - { - module: { - rules: [ - { - test: /\.css$/i, - use: [ - { - loader: path.resolve(__dirname, "../src"), - options: { import: { loaders: 1 } }, - }, - { - loader: "postcss-loader", - options: { - postcssOptions: { - plugins: [postcssPresetEnv({ stage: 0 })], - }, - }, - }, - ], - }, - ], - }, - } - ); - const stats = await compile(compiler); - - expect( - getModuleSource("./nested-import/source.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 a value equal to "2" ("postcss-loader" before)', async () => { - const compiler = getCompiler( - "./nested-import/source.js", - {}, - { - module: { - rules: [ - { - test: /\.css$/i, - use: [ - { - loader: path.resolve(__dirname, "../src"), - options: { import: { loaders: 2 } }, - }, - { - loader: "postcss-loader", - options: { - postcssOptions: { - plugins: [postcssPresetEnv({ stage: 0 })], - }, - }, - }, - ], - }, - ], - }, - } - ); - const stats = await compile(compiler); - - expect( - getModuleSource("./nested-import/source.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 a value equal to ""1"" ("postcss-loader" before)', async () => { - const compiler = getCompiler( - "./nested-import/source.js", - {}, - { - module: { - rules: [ - { - test: /\.css$/i, - use: [ - { - loader: path.resolve(__dirname, "../src"), - options: { import: { loaders: "1" } }, - }, - { - loader: "postcss-loader", - options: { - postcssOptions: { - plugins: [postcssPresetEnv({ stage: 0 })], - }, - }, - }, - ], - }, - ], - }, - } - ); - const stats = await compile(compiler); - - expect( - getModuleSource("./nested-import/source.css", stats) - ).toMatchSnapshot("module"); - expect(getExecutedCode("main.bundle.js", compiler, stats)).toMatchSnapshot( - "result" - ); - expect(getWarnings(stats)).toMatchSnapshot("warnings"); - expect(getErrors(stats)).toMatchSnapshot("errors"); - }); -});