From 77449e1cca26afd9fd17a7e2d1d894039760edb2 Mon Sep 17 00:00:00 2001 From: Alexander Krasnoyarov Date: Mon, 7 Sep 2020 17:04:14 +0300 Subject: [PATCH] test: union (#469) --- test/__snapshots__/config.test.js.snap | 187 --- test/__snapshots__/parser.test.js.snap | 45 - test/__snapshots__/plugins.test.js.snap | 691 ----------- test/__snapshots__/postcssOptins.test.js.snap | 1080 +++++++++++++++++ test/__snapshots__/stringifier.test.js.snap | 143 --- test/__snapshots__/syntax.test.js.snap | 32 - test/config.test.js | 221 ---- test/parser.test.js | 69 -- test/plugins.test.js | 301 ----- test/postcssOptins.test.js | 654 ++++++++++ test/stringifier.test.js | 71 -- test/syntax.test.js | 53 - 12 files changed, 1734 insertions(+), 1813 deletions(-) delete mode 100644 test/__snapshots__/config.test.js.snap delete mode 100644 test/__snapshots__/parser.test.js.snap delete mode 100644 test/__snapshots__/plugins.test.js.snap delete mode 100644 test/__snapshots__/stringifier.test.js.snap delete mode 100644 test/__snapshots__/syntax.test.js.snap delete mode 100644 test/config.test.js delete mode 100644 test/parser.test.js delete mode 100644 test/plugins.test.js delete mode 100644 test/stringifier.test.js delete mode 100644 test/syntax.test.js diff --git a/test/__snapshots__/config.test.js.snap b/test/__snapshots__/config.test.js.snap deleted file mode 100644 index 25417a32..00000000 --- a/test/__snapshots__/config.test.js.snap +++ /dev/null @@ -1,187 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`"config" option should throw an error on the invalid config: errors 1`] = ` -Array [ - "ModuleBuildError: Module build failed (from \`replaced original path\`): -Error: invalid postcss config", -] -`; - -exports[`"config" option should throw an error on the invalid config: warnings 1`] = `Array []`; - -exports[`"config" option should throw an error on the unresolved config: errors 1`] = ` -Array [ - "ModuleBuildError: Module build failed (from \`replaced original path\`): -Error: No PostCSS Config found in: /test/fixtures/config-scope/css/unresolve.js", -] -`; - -exports[`"config" option should throw an error on the unresolved config: warnings 1`] = `Array []`; - -exports[`"config" option should work "String" value (relative path): css 1`] = ` -"a { color: rgba(0, 0, 0, 1.0) } - -.foo { - float: right; -} -" -`; - -exports[`"config" option should work "String" value (relative path): errors 1`] = `Array []`; - -exports[`"config" option should work "String" value (relative path): warnings 1`] = `Array []`; - -exports[`"config" option should work and resolve "from" and "to" options: css 1`] = ` -"a { color: black } - -.foo { - float: right; -} -" -`; - -exports[`"config" option should work and resolve "from" and "to" options: errors 1`] = `Array []`; - -exports[`"config" option should work and resolve "from" and "to" options: source map 1`] = ` -Object { - "file": "style.css", - "mappings": "AAAA,IAAI,aAAa;;AAEjB;EACE,YAAY;AACd", - "names": Array [], - "sourceRoot": "", - "sources": Array [ - "style.css", - ], - "sourcesContent": Array [ - "a { color: black } - -.foo { - float: right; -} -", - ], - "version": 3, -} -`; - -exports[`"config" option should work and resolve "from" and "to" options: warnings 1`] = `Array []`; - -exports[`"config" option should work with "String" value (absolute path): css 1`] = ` -"a { color: rgba(0, 0, 0, 1.0) } - -.foo { - float: right; -} -" -`; - -exports[`"config" option should work with "String" value (absolute path): errors 1`] = `Array []`; - -exports[`"config" option should work with "String" value (absolute path): warnings 1`] = `Array []`; - -exports[`"config" option should work with "String" value (with path to the directory with the configuration): css 1`] = ` -"a { color: rgba(0, 0, 0, 1.0) } - -.foo { - float: right; -} -" -`; - -exports[`"config" option should work with "String" value (with path to the directory with the configuration): errors 1`] = `Array []`; - -exports[`"config" option should work with "String" value (with path to the directory with the configuration): warnings 1`] = `Array []`; - -exports[`"config" option should work with "String" value and respect all options: css 1`] = ` -"a { - color: black -} - -/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0eWxlLnNzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtFQUNFO0FBREYiLCJmaWxlIjoic3R5bGUuY3NzIiwic291cmNlc0NvbnRlbnQiOlsiYVxuICBjb2xvcjogYmxhY2tcbiJdfQ== */" -`; - -exports[`"config" option should work with "String" value and respect all options: errors 1`] = `Array []`; - -exports[`"config" option should work with "String" value and respect all options: warnings 1`] = `Array []`; - -exports[`"config" option should work with "false" value: css 1`] = ` -"a { color: black } - -.foo { - float: right; -} -" -`; - -exports[`"config" option should work with "false" value: errors 1`] = `Array []`; - -exports[`"config" option should work with "false" value: warnings 1`] = `Array []`; - -exports[`"config" option should work with "package.json" configuration: css 1`] = ` -".import { - color: red; -} - -.test { - color: blue; -} -" -`; - -exports[`"config" option should work with "package.json" configuration: errors 1`] = `Array []`; - -exports[`"config" option should work with "package.json" configuration: warnings 1`] = `Array []`; - -exports[`"config" option should work with "true" value: css 1`] = ` -"a { color: rgba(0, 0, 0, 1.0) } - -.foo { - float: right; -} -" -`; - -exports[`"config" option should work with "true" value: errors 1`] = `Array []`; - -exports[`"config" option should work with "true" value: warnings 1`] = `Array []`; - -exports[`"config" option should work with the "postcssOptions" option: css 1`] = ` -"a { color: rgba(0, 0, 0, 1.0) } - -[dir=ltr] .foo { float: right; -} - -[dir=rtl] .foo { - float: left; -} -" -`; - -exports[`"config" option should work with the "postcssOptions" option: errors 1`] = `Array []`; - -exports[`"config" option should work with the "postcssOptions" option: warnings 1`] = `Array []`; - -exports[`"config" option should work without the specified value in the "postcssOptions" option: css 1`] = ` -"a { color: rgba(0, 0, 0, 1.0) } - -.foo { - float: right; -} -" -`; - -exports[`"config" option should work without the specified value in the "postcssOptions" option: errors 1`] = `Array []`; - -exports[`"config" option should work without the specified value in the "postcssOptions" option: warnings 1`] = `Array []`; - -exports[`"config" option should work without the specified value: css 1`] = ` -"a { color: rgba(0, 0, 0, 1.0) } - -.foo { - float: right; -} -" -`; - -exports[`"config" option should work without the specified value: errors 1`] = `Array []`; - -exports[`"config" option should work without the specified value: warnings 1`] = `Array []`; diff --git a/test/__snapshots__/parser.test.js.snap b/test/__snapshots__/parser.test.js.snap deleted file mode 100644 index 36781ca2..00000000 --- a/test/__snapshots__/parser.test.js.snap +++ /dev/null @@ -1,45 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`"parser" option should throw an error on "unresolved" parser: errors 1`] = ` -Array [ - "ModuleBuildError: Module build failed (from \`replaced original path\`): -TypeError: parser is not a function", - "ModuleError: Module Error (from \`replaced original path\`): -Loading PostCSS \\"unresolved\\" parser failed: Cannot find module 'unresolved' from 'src/utils.js'", -] -`; - -exports[`"parser" option should throw an error on "unresolved" parser: warnings 1`] = `Array []`; - -exports[`"parser" option should work with "Function" value: css 1`] = ` -"a { - color: black -} -" -`; - -exports[`"parser" option should work with "Function" value: errors 1`] = `Array []`; - -exports[`"parser" option should work with "Function" value: warnings 1`] = `Array []`; - -exports[`"parser" option should work with "Object" value: css 1`] = ` -"a { - color: black -} -" -`; - -exports[`"parser" option should work with "Object" value: errors 1`] = `Array []`; - -exports[`"parser" option should work with "Object" value: warnings 1`] = `Array []`; - -exports[`"parser" option should work with "String" value: css 1`] = ` -"a { - color: black -} -" -`; - -exports[`"parser" option should work with "String" value: errors 1`] = `Array []`; - -exports[`"parser" option should work with "String" value: warnings 1`] = `Array []`; diff --git a/test/__snapshots__/plugins.test.js.snap b/test/__snapshots__/plugins.test.js.snap deleted file mode 100644 index 46427c2b..00000000 --- a/test/__snapshots__/plugins.test.js.snap +++ /dev/null @@ -1,691 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`"plugins" option should throw an error on the unresolved plugin: errors 1`] = ` -Array [ - "ModuleError: Module Error (from \`replaced original path\`): -Loading PostCSS \\"postcss-unresolved\\" plugin failed: Cannot find module 'postcss-unresolved' from 'src/utils.js'", -] -`; - -exports[`"plugins" option should throw an error on the unresolved plugin: warnings 1`] = `Array []`; - -exports[`"plugins" option should work with "Array" value and not throw an error on falsy plugin: errors 1`] = `Array []`; - -exports[`"plugins" option should work with "Array" value and not throw an error on falsy plugin: warnings 1`] = `Array []`; - -exports[`"plugins" option should work with "Array" value and override the previous plugin options: css 1`] = ` -"a { - color: black; -} - -a { - color: red; -} - -a { - color: green; -} - -a { - color: blue; -} - -.class { - -x-border-color: blue blue *; - -x-color: * #fafafa; -} - -.class-foo { - border-top-color: blue; - border-right-color: blue; - border-left-color: blue; - background-color: #fafafa; -} - -.phone { - &_title { - width: 500px; - - @media (max-width: 500px) { - width: auto; - } - - body.is_dark & { - color: white; - } - } - - img { - display: block; - } -} -" -`; - -exports[`"plugins" option should work with "Array" value and override the previous plugin options: errors 1`] = `Array []`; - -exports[`"plugins" option should work with "Array" value and override the previous plugin options: warnings 1`] = `Array []`; - -exports[`"plugins" option should work with "Array" value and support disabling plugins from the configuration: css 1`] = ` -"a { - color: black; -} - -a { - color: red; -} - -a { - color: green; -} - -a { - color: blue; -} - -.class { - -x-border-color: blue blue *; - -x-color: * #fafafa; -} - -.class-foo { - -z-border-color: blue blue *; - -z-color: * #fafafa; -} - -.phone { - &_title { - width: 500px; - - @media (max-width: 500px) { - width: auto; - } - - body.is_dark & { - color: white; - } - } - - img { - display: block; - } -} -" -`; - -exports[`"plugins" option should work with "Array" value and support disabling plugins from the configuration: errors 1`] = `Array []`; - -exports[`"plugins" option should work with "Array" value and support disabling plugins from the configuration: warnings 1`] = `Array []`; - -exports[`"plugins" option should work with "Array" value, and config, and override the previous plugin options: css 1`] = ` -"a { - color: black; -} - -a { - color: red; -} - -a { - color: green; -} - -a { - color: blue; -} - -.class { - -x-border-color: blue blue *; - -x-color: * #fafafa; -} - -.class-foo { - border-top-color: blue; - border-right-color: blue; - border-left-color: blue; - background-color: #fafafa; -} - -.phone { - &_title { - width: 500px; - - @media (max-width: 500px) { - width: auto; - } - - body.is_dark & { - color: white; - } - } - - img { - display: block; - } -} -" -`; - -exports[`"plugins" option should work with "Array" value, and config, and override the previous plugin options: errors 1`] = `Array []`; - -exports[`"plugins" option should work with "Array" value, and config, and override the previous plugin options: warnings 1`] = `Array []`; - -exports[`"plugins" option should work with "Array" value: css 1`] = ` -"a { - color: rgba(0, 0, 0, 1.0); -} - -a { - color: rgba(255, 0, 0, 1.0); -} - -a { - color: rgba(0, 255, 0, 1.0); -} - -a { - color: rgba(0, 0, 255, 1.0); -} - -.class { - -x-border-color: blue blue *; - -x-color: * #fafafa; -} - -.class-foo { - border-top-color: rgba(0, 0, 255, 1.0); - border-right-color: rgba(0, 0, 255, 1.0); - border-left-color: rgba(0, 0, 255, 1.0); - background-color: #fafafa; -} - -.phone_title { - width: 500px; - } - -@media (max-width: 500px) { - -.phone_title { - width: auto - } - } - -body.is_dark .phone_title { - color: rgba(0, 0, 0, 0); - } - -.phone img { - display: block; - } -" -`; - -exports[`"plugins" option should work with "Array" value: errors 1`] = `Array []`; - -exports[`"plugins" option should work with "Array" value: warnings 1`] = `Array []`; - -exports[`"plugins" option should work with "Object" value and only disabled plugins: css 1`] = ` -"a { - color: black; -} - -a { - color: red; -} - -a { - color: green; -} - -a { - color: blue; -} - -.class { - -x-border-color: blue blue *; - -x-color: * #fafafa; -} - -.class-foo { - -z-border-color: blue blue *; - -z-color: * #fafafa; -} - -.phone { - &_title { - width: 500px; - - @media (max-width: 500px) { - width: auto; - } - - body.is_dark & { - color: white; - } - } - - img { - display: block; - } -} -" -`; - -exports[`"plugins" option should work with "Object" value and only disabled plugins: errors 1`] = `Array []`; - -exports[`"plugins" option should work with "Object" value and only disabled plugins: warnings 1`] = `Array []`; - -exports[`"plugins" option should work with "Object" value and override the previous plugin options: css 1`] = ` -"a { - color: black; -} - -a { - color: red; -} - -a { - color: green; -} - -a { - color: blue; -} - -.class { - -x-border-color: blue blue *; - -x-color: * #fafafa; -} - -.class-foo { - border-top-color: blue; - border-right-color: blue; - border-left-color: blue; - background-color: #fafafa; -} - -.phone { - &_title { - width: 500px; - - @media (max-width: 500px) { - width: auto; - } - - body.is_dark & { - color: white; - } - } - - img { - display: block; - } -} -" -`; - -exports[`"plugins" option should work with "Object" value and override the previous plugin options: errors 1`] = `Array []`; - -exports[`"plugins" option should work with "Object" value and override the previous plugin options: warnings 1`] = `Array []`; - -exports[`"plugins" option should work with "Object" value and support disabling plugins from the configuration: css 1`] = ` -"a { - color: black; -} - -a { - color: red; -} - -a { - color: green; -} - -a { - color: blue; -} - -.class { - -x-border-color: blue blue *; - -x-color: * #fafafa; -} - -.class-foo { - -z-border-color: blue blue *; - -z-color: * #fafafa; -} - -.phone { - &_title { - width: 500px; - - @media (max-width: 500px) { - width: auto; - } - - body.is_dark & { - color: white; - } - } - - img { - display: block; - } -} -" -`; - -exports[`"plugins" option should work with "Object" value and support disabling plugins from the configuration: errors 1`] = `Array []`; - -exports[`"plugins" option should work with "Object" value and support disabling plugins from the configuration: warnings 1`] = `Array []`; - -exports[`"plugins" option should work with "Object" value, and config, and override the previous plugin options: css 1`] = ` -"a { - color: black; -} - -a { - color: red; -} - -a { - color: green; -} - -a { - color: blue; -} - -.class { - -x-border-color: blue blue *; - -x-color: * #fafafa; -} - -.class-foo { - border-top-color: blue; - border-right-color: blue; - border-left-color: blue; - background-color: #fafafa; -} - -.phone { - &_title { - width: 500px; - - @media (max-width: 500px) { - width: auto; - } - - body.is_dark & { - color: white; - } - } - - img { - display: block; - } -} -" -`; - -exports[`"plugins" option should work with "Object" value, and config, and override the previous plugin options: errors 1`] = `Array []`; - -exports[`"plugins" option should work with "Object" value, and config, and override the previous plugin options: warnings 1`] = `Array []`; - -exports[`"plugins" option should work with "Object" value: css 1`] = ` -"a { - color: black; -} - -a { - color: red; -} - -a { - color: green; -} - -a { - color: rgba(0, 0, 255, 1.0); -} - -.class { - border-top-color: rgba(0, 0, 255, 1.0); - border-right-color: rgba(0, 0, 255, 1.0); - border-left-color: rgba(0, 0, 255, 1.0); - background-color: #fafafa; -} - -.class-foo { - -z-border-color: blue blue *; - -z-color: * #fafafa; -} - -.phone_title { - width: 500px; - } - -@media (max-width: 500px) { - -.phone_title { - width: auto - } - } - -body.is_dark .phone_title { - color: white; - } - -.phone img { - display: block; - } -" -`; - -exports[`"plugins" option should work with "Object" value: errors 1`] = `Array []`; - -exports[`"plugins" option should work with "Object" value: warnings 1`] = `Array []`; - -exports[`"plugins" option should work with empty "Array" value: css 1`] = ` -"a { - color: black; -} - -a { - color: red; -} - -a { - color: green; -} - -a { - color: blue; -} - -.class { - -x-border-color: blue blue *; - -x-color: * #fafafa; -} - -.class-foo { - -z-border-color: blue blue *; - -z-color: * #fafafa; -} - -.phone { - &_title { - width: 500px; - - @media (max-width: 500px) { - width: auto; - } - - body.is_dark & { - color: white; - } - } - - img { - display: block; - } -} -" -`; - -exports[`"plugins" option should work with empty "Array" value: errors 1`] = `Array []`; - -exports[`"plugins" option should work with empty "Array" value: warnings 1`] = `Array []`; - -exports[`"plugins" option should work with empty "Object" value: css 1`] = ` -"a { - color: black; -} - -a { - color: red; -} - -a { - color: green; -} - -a { - color: blue; -} - -.class { - -x-border-color: blue blue *; - -x-color: * #fafafa; -} - -.class-foo { - -z-border-color: blue blue *; - -z-color: * #fafafa; -} - -.phone { - &_title { - width: 500px; - - @media (max-width: 500px) { - width: auto; - } - - body.is_dark & { - color: white; - } - } - - img { - display: block; - } -} -" -`; - -exports[`"plugins" option should work with empty "Object" value: errors 1`] = `Array []`; - -exports[`"plugins" option should work with empty "Object" value: warnings 1`] = `Array []`; - -exports[`"plugins" option should work with the "default" property with options: css 1`] = ` -"a { - color: black; -} - -a { - color: rgba(0, 0, 255, 0.5); -} - -a { - color: green; -} - -a { - color: blue; -} - -.class { - -x-border-color: blue blue *; - -x-color: * #fafafa; -} - -.class-foo { - -z-border-color: blue blue *; - -z-color: * #fafafa; -} - -.phone { - &_title { - width: 500px; - - @media (max-width: 500px) { - width: auto; - } - - body.is_dark & { - color: white; - } - } - - img { - display: block; - } -} -" -`; - -exports[`"plugins" option should work with the "default" property with options: errors 1`] = `Array []`; - -exports[`"plugins" option should work with the "default" property with options: warnings 1`] = `Array []`; - -exports[`"plugins" option should work with the "default" property without options: css 1`] = ` -"a { - color: black; -} - -a { - color: red; -} - -a { - color: green; -} - -a { - color: rgba(0, 0, 255, 1.0); -} - -.class { - -x-border-color: blue blue *; - -x-color: * #fafafa; -} - -.class-foo { - -z-border-color: blue blue *; - -z-color: * #fafafa; -} - -.phone { - &_title { - width: 500px; - - @media (max-width: 500px) { - width: auto; - } - - body.is_dark & { - color: white; - } - } - - img { - display: block; - } -} -" -`; - -exports[`"plugins" option should work with the "default" property without options: errors 1`] = `Array []`; - -exports[`"plugins" option should work with the "default" property without options: warnings 1`] = `Array []`; diff --git a/test/__snapshots__/postcssOptins.test.js.snap b/test/__snapshots__/postcssOptins.test.js.snap index 08b55e2a..23ea45cb 100644 --- a/test/__snapshots__/postcssOptins.test.js.snap +++ b/test/__snapshots__/postcssOptins.test.js.snap @@ -1,5 +1,65 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`"postcssOptions" option should throw an error with "syntax" option on the unresolved syntax: errors 1`] = ` +Array [ + "ModuleBuildError: Module build failed (from \`replaced original path\`): +TypeError: Cannot read property 'parse' of undefined", + "ModuleError: Module Error (from \`replaced original path\`): +Loading PostCSS \\"unresolved\\" syntax failed: Cannot find module 'unresolved' from 'src/utils.js'", +] +`; + +exports[`"postcssOptions" option should throw an error with "syntax" option on the unresolved syntax: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should throw an error with the "config" option on the invalid config: errors 1`] = ` +Array [ + "ModuleBuildError: Module build failed (from \`replaced original path\`): +Error: invalid postcss config", +] +`; + +exports[`"postcssOptions" option should throw an error with the "config" option on the invalid config: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should throw an error with the "config" option on the unresolved config: errors 1`] = ` +Array [ + "ModuleBuildError: Module build failed (from \`replaced original path\`): +Error: No PostCSS Config found in: /test/fixtures/config-scope/css/unresolve.js", +] +`; + +exports[`"postcssOptions" option should throw an error with the "config" option on the unresolved config: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should throw an error with the "parser" option on the unresolved parser: errors 1`] = ` +Array [ + "ModuleBuildError: Module build failed (from \`replaced original path\`): +TypeError: parser is not a function", + "ModuleError: Module Error (from \`replaced original path\`): +Loading PostCSS \\"unresolved\\" parser failed: Cannot find module 'unresolved' from 'src/utils.js'", +] +`; + +exports[`"postcssOptions" option should throw an error with the "parser" option on the unresolved parser: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should throw an error with the "plugins" option on the unresolved plugin: errors 1`] = ` +Array [ + "ModuleError: Module Error (from \`replaced original path\`): +Loading PostCSS \\"postcss-unresolved\\" plugin failed: Cannot find module 'postcss-unresolved' from 'src/utils.js'", +] +`; + +exports[`"postcssOptions" option should throw an error with the "plugins" option on the unresolved plugin: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should throw an error with the "stringifier" option on the unresolved stringifier: errors 1`] = ` +Array [ + "ModuleBuildError: Module build failed (from \`replaced original path\`): +TypeError: this.stringify is not a function", + "ModuleError: Module Error (from \`replaced original path\`): +Loading PostCSS \\"unresolved\\" stringifier failed: Cannot find module 'unresolved' from 'src/utils.js'", +] +`; + +exports[`"postcssOptions" option should throw an error with the "stringifier" option on the unresolved stringifier: warnings 1`] = `Array []`; + exports[`"postcssOptions" option should work "Function" value and with "Array" syntax of the "plugins" option: css 1`] = ` "a { color: rgba(0, 0, 0, 1.0); @@ -259,6 +319,148 @@ exports[`"postcssOptions" option should work with "from", "to" and "map" options exports[`"postcssOptions" option should work with "from", "to" and "map" options (relative paths): warnings 1`] = `Array []`; +exports[`"postcssOptions" option should work with the "config" options "String" value (relative path): css 1`] = ` +"a { color: rgba(0, 0, 0, 1.0) } + +.foo { + float: right; +} +" +`; + +exports[`"postcssOptions" option should work with the "config" options "String" value (relative path): errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "config" options "String" value (relative path): warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "config" options and resolve "from" and "to" options: css 1`] = ` +"a { color: black } + +.foo { + float: right; +} +" +`; + +exports[`"postcssOptions" option should work with the "config" options and resolve "from" and "to" options: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "config" options and resolve "from" and "to" options: source map 1`] = ` +Object { + "file": "style.css", + "mappings": "AAAA,IAAI,aAAa;;AAEjB;EACE,YAAY;AACd", + "names": Array [], + "sourceRoot": "", + "sources": Array [ + "style.css", + ], + "sourcesContent": Array [ + "a { color: black } + +.foo { + float: right; +} +", + ], + "version": 3, +} +`; + +exports[`"postcssOptions" option should work with the "config" options and resolve "from" and "to" options: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "config" options and use plugins: css 1`] = ` +"a { color: rgba(0, 0, 0, 1.0) } + +[dir=ltr] .foo { float: right; +} + +[dir=rtl] .foo { + float: left; +} +" +`; + +exports[`"postcssOptions" option should work with the "config" options and use plugins: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "config" options and use plugins: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "config" options with "String" value (absolute path): css 1`] = ` +"a { color: rgba(0, 0, 0, 1.0) } + +.foo { + float: right; +} +" +`; + +exports[`"postcssOptions" option should work with the "config" options with "String" value (absolute path): errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "config" options with "String" value (absolute path): warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "config" options with "String" value (with path to the directory with the configuration): css 1`] = ` +"a { color: rgba(0, 0, 0, 1.0) } + +.foo { + float: right; +} +" +`; + +exports[`"postcssOptions" option should work with the "config" options with "String" value (with path to the directory with the configuration): errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "config" options with "String" value (with path to the directory with the configuration): warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "config" options with "String" value and respect all options: css 1`] = ` +"a { + color: black +} + +/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0eWxlLnNzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtFQUNFO0FBREYiLCJmaWxlIjoic3R5bGUuY3NzIiwic291cmNlc0NvbnRlbnQiOlsiYVxuICBjb2xvcjogYmxhY2tcbiJdfQ== */" +`; + +exports[`"postcssOptions" option should work with the "config" options with "String" value and respect all options: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "config" options with "String" value and respect all options: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "config" options with "false" value: css 1`] = ` +"a { color: black } + +.foo { + float: right; +} +" +`; + +exports[`"postcssOptions" option should work with the "config" options with "false" value: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "config" options with "false" value: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "config" options with "package.json" configuration: css 1`] = ` +".import { + color: red; +} + +.test { + color: blue; +} +" +`; + +exports[`"postcssOptions" option should work with the "config" options with "package.json" configuration: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "config" options with "package.json" configuration: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "config" options with "true" value: css 1`] = ` +"a { color: rgba(0, 0, 0, 1.0) } + +.foo { + float: right; +} +" +`; + +exports[`"postcssOptions" option should work with the "config" options with "true" value: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "config" options with "true" value: warnings 1`] = `Array []`; + exports[`"postcssOptions" option should work with the "map" option and generate inlined source maps: css 1`] = ` "a { color: black; @@ -312,3 +514,881 @@ exports[`"postcssOptions" option should work with the "map" option and generate exports[`"postcssOptions" option should work with the "map" option and generate inlined source maps: map 1`] = `undefined`; exports[`"postcssOptions" option should work with the "map" option and generate inlined source maps: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "parser" option with "Function" value: css 1`] = ` +"a { + color: black +} +" +`; + +exports[`"postcssOptions" option should work with the "parser" option with "Function" value: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "parser" option with "Function" value: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "parser" option with "Object" value: css 1`] = ` +"a { + color: black +} +" +`; + +exports[`"postcssOptions" option should work with the "parser" option with "Object" value: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "parser" option with "Object" value: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "parser" option with "String" value: css 1`] = ` +"a { + color: black +} +" +`; + +exports[`"postcssOptions" option should work with the "parser" option with "String" value: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "parser" option with "String" value: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Array" value and not throw an error on falsy plugin: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Array" value and not throw an error on falsy plugin: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Array" value and override the previous plugin options: css 1`] = ` +"a { + color: black; +} + +a { + color: red; +} + +a { + color: green; +} + +a { + color: blue; +} + +.class { + -x-border-color: blue blue *; + -x-color: * #fafafa; +} + +.class-foo { + border-top-color: blue; + border-right-color: blue; + border-left-color: blue; + background-color: #fafafa; +} + +.phone { + &_title { + width: 500px; + + @media (max-width: 500px) { + width: auto; + } + + body.is_dark & { + color: white; + } + } + + img { + display: block; + } +} +" +`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Array" value and override the previous plugin options: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Array" value and override the previous plugin options: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Array" value and support disabling plugins from the configuration: css 1`] = ` +"a { + color: black; +} + +a { + color: red; +} + +a { + color: green; +} + +a { + color: blue; +} + +.class { + -x-border-color: blue blue *; + -x-color: * #fafafa; +} + +.class-foo { + -z-border-color: blue blue *; + -z-color: * #fafafa; +} + +.phone { + &_title { + width: 500px; + + @media (max-width: 500px) { + width: auto; + } + + body.is_dark & { + color: white; + } + } + + img { + display: block; + } +} +" +`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Array" value and support disabling plugins from the configuration: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Array" value and support disabling plugins from the configuration: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Array" value, and config, and override the previous plugin options: css 1`] = ` +"a { + color: black; +} + +a { + color: red; +} + +a { + color: green; +} + +a { + color: blue; +} + +.class { + -x-border-color: blue blue *; + -x-color: * #fafafa; +} + +.class-foo { + border-top-color: blue; + border-right-color: blue; + border-left-color: blue; + background-color: #fafafa; +} + +.phone { + &_title { + width: 500px; + + @media (max-width: 500px) { + width: auto; + } + + body.is_dark & { + color: white; + } + } + + img { + display: block; + } +} +" +`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Array" value, and config, and override the previous plugin options: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Array" value, and config, and override the previous plugin options: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Array" value: css 1`] = ` +"a { + color: rgba(0, 0, 0, 1.0); +} + +a { + color: rgba(255, 0, 0, 1.0); +} + +a { + color: rgba(0, 255, 0, 1.0); +} + +a { + color: rgba(0, 0, 255, 1.0); +} + +.class { + -x-border-color: blue blue *; + -x-color: * #fafafa; +} + +.class-foo { + border-top-color: rgba(0, 0, 255, 1.0); + border-right-color: rgba(0, 0, 255, 1.0); + border-left-color: rgba(0, 0, 255, 1.0); + background-color: #fafafa; +} + +.phone_title { + width: 500px; + } + +@media (max-width: 500px) { + +.phone_title { + width: auto + } + } + +body.is_dark .phone_title { + color: rgba(0, 0, 0, 0); + } + +.phone img { + display: block; + } +" +`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Array" value: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Array" value: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Object" value and only disabled plugins: css 1`] = ` +"a { + color: black; +} + +a { + color: red; +} + +a { + color: green; +} + +a { + color: blue; +} + +.class { + -x-border-color: blue blue *; + -x-color: * #fafafa; +} + +.class-foo { + -z-border-color: blue blue *; + -z-color: * #fafafa; +} + +.phone { + &_title { + width: 500px; + + @media (max-width: 500px) { + width: auto; + } + + body.is_dark & { + color: white; + } + } + + img { + display: block; + } +} +" +`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Object" value and only disabled plugins: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Object" value and only disabled plugins: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Object" value and override the previous plugin options: css 1`] = ` +"a { + color: black; +} + +a { + color: red; +} + +a { + color: green; +} + +a { + color: blue; +} + +.class { + -x-border-color: blue blue *; + -x-color: * #fafafa; +} + +.class-foo { + border-top-color: blue; + border-right-color: blue; + border-left-color: blue; + background-color: #fafafa; +} + +.phone { + &_title { + width: 500px; + + @media (max-width: 500px) { + width: auto; + } + + body.is_dark & { + color: white; + } + } + + img { + display: block; + } +} +" +`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Object" value and override the previous plugin options: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Object" value and override the previous plugin options: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Object" value and support disabling plugins from the configuration: css 1`] = ` +"a { + color: black; +} + +a { + color: red; +} + +a { + color: green; +} + +a { + color: blue; +} + +.class { + -x-border-color: blue blue *; + -x-color: * #fafafa; +} + +.class-foo { + -z-border-color: blue blue *; + -z-color: * #fafafa; +} + +.phone { + &_title { + width: 500px; + + @media (max-width: 500px) { + width: auto; + } + + body.is_dark & { + color: white; + } + } + + img { + display: block; + } +} +" +`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Object" value and support disabling plugins from the configuration: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Object" value and support disabling plugins from the configuration: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Object" value, and config, and override the previous plugin options: css 1`] = ` +"a { + color: black; +} + +a { + color: red; +} + +a { + color: green; +} + +a { + color: blue; +} + +.class { + -x-border-color: blue blue *; + -x-color: * #fafafa; +} + +.class-foo { + border-top-color: blue; + border-right-color: blue; + border-left-color: blue; + background-color: #fafafa; +} + +.phone { + &_title { + width: 500px; + + @media (max-width: 500px) { + width: auto; + } + + body.is_dark & { + color: white; + } + } + + img { + display: block; + } +} +" +`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Object" value, and config, and override the previous plugin options: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Object" value, and config, and override the previous plugin options: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Object" value: css 1`] = ` +"a { + color: black; +} + +a { + color: red; +} + +a { + color: green; +} + +a { + color: rgba(0, 0, 255, 1.0); +} + +.class { + border-top-color: rgba(0, 0, 255, 1.0); + border-right-color: rgba(0, 0, 255, 1.0); + border-left-color: rgba(0, 0, 255, 1.0); + background-color: #fafafa; +} + +.class-foo { + -z-border-color: blue blue *; + -z-color: * #fafafa; +} + +.phone_title { + width: 500px; + } + +@media (max-width: 500px) { + +.phone_title { + width: auto + } + } + +body.is_dark .phone_title { + color: white; + } + +.phone img { + display: block; + } +" +`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Object" value: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with "Object" value: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with empty "Array" value: css 1`] = ` +"a { + color: black; +} + +a { + color: red; +} + +a { + color: green; +} + +a { + color: blue; +} + +.class { + -x-border-color: blue blue *; + -x-color: * #fafafa; +} + +.class-foo { + -z-border-color: blue blue *; + -z-color: * #fafafa; +} + +.phone { + &_title { + width: 500px; + + @media (max-width: 500px) { + width: auto; + } + + body.is_dark & { + color: white; + } + } + + img { + display: block; + } +} +" +`; + +exports[`"postcssOptions" option should work with the "plugins" option with empty "Array" value: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with empty "Array" value: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with empty "Object" value: css 1`] = ` +"a { + color: black; +} + +a { + color: red; +} + +a { + color: green; +} + +a { + color: blue; +} + +.class { + -x-border-color: blue blue *; + -x-color: * #fafafa; +} + +.class-foo { + -z-border-color: blue blue *; + -z-color: * #fafafa; +} + +.phone { + &_title { + width: 500px; + + @media (max-width: 500px) { + width: auto; + } + + body.is_dark & { + color: white; + } + } + + img { + display: block; + } +} +" +`; + +exports[`"postcssOptions" option should work with the "plugins" option with empty "Object" value: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with empty "Object" value: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with the "default" property with options: css 1`] = ` +"a { + color: black; +} + +a { + color: rgba(0, 0, 255, 0.5); +} + +a { + color: green; +} + +a { + color: blue; +} + +.class { + -x-border-color: blue blue *; + -x-color: * #fafafa; +} + +.class-foo { + -z-border-color: blue blue *; + -z-color: * #fafafa; +} + +.phone { + &_title { + width: 500px; + + @media (max-width: 500px) { + width: auto; + } + + body.is_dark & { + color: white; + } + } + + img { + display: block; + } +} +" +`; + +exports[`"postcssOptions" option should work with the "plugins" option with the "default" property with options: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with the "default" property with options: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with the "default" property without options: css 1`] = ` +"a { + color: black; +} + +a { + color: red; +} + +a { + color: green; +} + +a { + color: rgba(0, 0, 255, 1.0); +} + +.class { + -x-border-color: blue blue *; + -x-color: * #fafafa; +} + +.class-foo { + -z-border-color: blue blue *; + -z-color: * #fafafa; +} + +.phone { + &_title { + width: 500px; + + @media (max-width: 500px) { + width: auto; + } + + body.is_dark & { + color: white; + } + } + + img { + display: block; + } +} +" +`; + +exports[`"postcssOptions" option should work with the "plugins" option with the "default" property without options: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "plugins" option with the "default" property without options: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "stringifier" option with "Function" value: css 1`] = ` +"
a {
+  color: black;
+}
+
+a {
+  color: red;
+}
+
+a {
+  color: green;
+}
+
+a {
+  color: blue;
+}
+
+.class {
+  -x-border-color: blue blue *;
+  -x-color: * #fafafa;
+}
+
+.class-foo {
+  -z-border-color: blue blue *;
+  -z-color: * #fafafa;
+}
+
+.phone {
+  _title {
+    width: 500px;
+
+    @media (max-width: 500px) {
+      width: auto;
+    }
+
+    body.is_dark  {
+      color: white;
+    }
+  }
+
+  img {
+    display: block;
+  }
+}
+
" +`; + +exports[`"postcssOptions" option should work with the "stringifier" option with "Function" value: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "stringifier" option with "Function" value: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "stringifier" option with "Object" value: css 1`] = ` +"a + color: black + +a + color: red + +a + color: green + +a + color: blue + +.class + -x-border-color: blue blue * + -x-color: * #fafafa + +.class-foo + -z-border-color: blue blue * + -z-color: * #fafafa + +.phone + &_title + width: 500px + + @media (max-width: 500px) + width: auto + + body.is_dark & + color: white + + img + display: block +" +`; + +exports[`"postcssOptions" option should work with the "stringifier" option with "Object" value: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "stringifier" option with "Object" value: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "stringifier" option with "String" value: css 1`] = ` +"a + color: black + +a + color: red + +a + color: green + +a + color: blue + +.class + -x-border-color: blue blue * + -x-color: * #fafafa + +.class-foo + -z-border-color: blue blue * + -z-color: * #fafafa + +.phone + &_title + width: 500px + + @media (max-width: 500px) + width: auto + + body.is_dark & + color: white + + img + display: block +" +`; + +exports[`"postcssOptions" option should work with the "stringifier" option with "String" value: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "stringifier" option with "String" value: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "syntax" option with "Object" value: css 1`] = ` +"a + color: black +" +`; + +exports[`"postcssOptions" option should work with the "syntax" option with "Object" value: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "syntax" option with "Object" value: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "syntax" option with "String" value: css 1`] = ` +"a + color: black +" +`; + +exports[`"postcssOptions" option should work with the "syntax" option with "String" value: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work with the "syntax" option with "String" value: warnings 1`] = `Array []`; + +exports[`"postcssOptions" option should work without the specified values in the "postcssOptions" option: css 1`] = ` +"a { color: rgba(0, 0, 0, 1.0) } + +.foo { + float: right; +} +" +`; + +exports[`"postcssOptions" option should work without the specified values in the "postcssOptions" option: errors 1`] = `Array []`; + +exports[`"postcssOptions" option should work without the specified values in the "postcssOptions" option: warnings 1`] = `Array []`; diff --git a/test/__snapshots__/stringifier.test.js.snap b/test/__snapshots__/stringifier.test.js.snap deleted file mode 100644 index bb031beb..00000000 --- a/test/__snapshots__/stringifier.test.js.snap +++ /dev/null @@ -1,143 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`"stringifier" option should throw an error on "unresolved" stringifier: errors 1`] = ` -Array [ - "ModuleBuildError: Module build failed (from \`replaced original path\`): -TypeError: this.stringify is not a function", - "ModuleError: Module Error (from \`replaced original path\`): -Loading PostCSS \\"unresolved\\" stringifier failed: Cannot find module 'unresolved' from 'src/utils.js'", -] -`; - -exports[`"stringifier" option should throw an error on "unresolved" stringifier: warnings 1`] = `Array []`; - -exports[`"stringifier" option should work "Function" value: css 1`] = ` -"
a {
-  color: black;
-}
-
-a {
-  color: red;
-}
-
-a {
-  color: green;
-}
-
-a {
-  color: blue;
-}
-
-.class {
-  -x-border-color: blue blue *;
-  -x-color: * #fafafa;
-}
-
-.class-foo {
-  -z-border-color: blue blue *;
-  -z-color: * #fafafa;
-}
-
-.phone {
-  _title {
-    width: 500px;
-
-    @media (max-width: 500px) {
-      width: auto;
-    }
-
-    body.is_dark  {
-      color: white;
-    }
-  }
-
-  img {
-    display: block;
-  }
-}
-
" -`; - -exports[`"stringifier" option should work "Function" value: errors 1`] = `Array []`; - -exports[`"stringifier" option should work "Function" value: warnings 1`] = `Array []`; - -exports[`"stringifier" option should work "Object" value: css 1`] = ` -"a - color: black - -a - color: red - -a - color: green - -a - color: blue - -.class - -x-border-color: blue blue * - -x-color: * #fafafa - -.class-foo - -z-border-color: blue blue * - -z-color: * #fafafa - -.phone - &_title - width: 500px - - @media (max-width: 500px) - width: auto - - body.is_dark & - color: white - - img - display: block -" -`; - -exports[`"stringifier" option should work "Object" value: errors 1`] = `Array []`; - -exports[`"stringifier" option should work "Object" value: warnings 1`] = `Array []`; - -exports[`"stringifier" option should work with "String" value: css 1`] = ` -"a - color: black - -a - color: red - -a - color: green - -a - color: blue - -.class - -x-border-color: blue blue * - -x-color: * #fafafa - -.class-foo - -z-border-color: blue blue * - -z-color: * #fafafa - -.phone - &_title - width: 500px - - @media (max-width: 500px) - width: auto - - body.is_dark & - color: white - - img - display: block -" -`; - -exports[`"stringifier" option should work with "String" value: errors 1`] = `Array []`; - -exports[`"stringifier" option should work with "String" value: warnings 1`] = `Array []`; diff --git a/test/__snapshots__/syntax.test.js.snap b/test/__snapshots__/syntax.test.js.snap deleted file mode 100644 index cb7b0e5c..00000000 --- a/test/__snapshots__/syntax.test.js.snap +++ /dev/null @@ -1,32 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`"syntax" option should throw an error on "unresolved" syntax: errors 1`] = ` -Array [ - "ModuleBuildError: Module build failed (from \`replaced original path\`): -TypeError: Cannot read property 'parse' of undefined", - "ModuleError: Module Error (from \`replaced original path\`): -Loading PostCSS \\"unresolved\\" syntax failed: Cannot find module 'unresolved' from 'src/utils.js'", -] -`; - -exports[`"syntax" option should throw an error on "unresolved" syntax: warnings 1`] = `Array []`; - -exports[`"syntax" option should work with "Object" value: css 1`] = ` -"a - color: black -" -`; - -exports[`"syntax" option should work with "Object" value: errors 1`] = `Array []`; - -exports[`"syntax" option should work with "Object" value: warnings 1`] = `Array []`; - -exports[`"syntax" option should work with "String" value: css 1`] = ` -"a - color: black -" -`; - -exports[`"syntax" option should work with "String" value: errors 1`] = `Array []`; - -exports[`"syntax" option should work with "String" value: warnings 1`] = `Array []`; diff --git a/test/config.test.js b/test/config.test.js deleted file mode 100644 index 367140ac..00000000 --- a/test/config.test.js +++ /dev/null @@ -1,221 +0,0 @@ -import path from 'path'; - -import { - compile, - getCompiler, - getErrors, - getCodeFromBundle, - getWarnings, -} from './helpers'; - -const testDirectory = path.resolve(__dirname, './fixtures', 'config-autoload'); - -describe('"config" option', () => { - it('should work without the specified value', async () => { - const compiler = getCompiler('./config-scope/css/index.js'); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.css', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should work without the specified value in the "postcssOptions" option', async () => { - const compiler = getCompiler('./config-scope/css/index.js', { - postcssOptions: {}, - }); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.css', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should work with "false" value', async () => { - const compiler = getCompiler('./config-scope/css/index.js', { - postcssOptions: { - config: false, - }, - }); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.css', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should work with "true" value', async () => { - const compiler = getCompiler('./config-scope/css/index.js', { - postcssOptions: { - config: true, - }, - }); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.css', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should work with "String" value (absolute path)', async () => { - const compiler = getCompiler('./config-scope/css/index.js', { - postcssOptions: { - config: path.resolve( - __dirname, - './fixtures/config-scope/css/custom.config.js' - ), - }, - }); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.css', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should work "String" value (relative path)', async () => { - const compiler = getCompiler('./config-scope/css/index.js', { - postcssOptions: { - config: 'test/fixtures/config-scope/css/custom.config.js', - }, - }); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.css', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should work with "String" value (with path to the directory with the configuration)', async () => { - const compiler = getCompiler('./config-scope/css/index.js', { - postcssOptions: { - config: 'test/fixtures/config-scope', - }, - }); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.css', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should work with "package.json" configuration', async () => { - const compiler = getCompiler('./config-autoload/pkg/index.js', { - postcssOptions: { - config: path.resolve(testDirectory, 'pkg'), - }, - }); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('index.css', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should work with the "postcssOptions" option', async () => { - const compiler = getCompiler('./config-scope/css/index.js', { - postcssOptions: { - config: true, - plugins: ['postcss-rtl'], - }, - }); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.css', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should work with "String" value and respect all options', async () => { - const compiler = getCompiler('./sss/index.js', { - postcssOptions: { - config: path.resolve( - __dirname, - './fixtures/config-scope/all-options/postcss.config.js' - ), - }, - }); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.sss', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should throw an error on the unresolved config', async () => { - const compiler = getCompiler('./config-scope/css/index.js', { - postcssOptions: { - config: path.resolve( - __dirname, - './fixtures/config-scope/css/unresolve.js' - ), - }, - }); - const stats = await compile(compiler); - - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats, true)).toMatchSnapshot('errors'); - }); - - it('should throw an error on the invalid config', async () => { - const compiler = getCompiler('./config-scope/css/index.js', { - postcssOptions: { - config: path.resolve( - __dirname, - './fixtures/config-scope/css/invalid.config.js' - ), - }, - }); - const stats = await compile(compiler); - - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats, true)).toMatchSnapshot('errors'); - }); - - it('should work and resolve "from" and "to" options', async () => { - const compiler = getCompiler('./config-scope/css/index.js', { - postcssOptions: { - config: path.resolve( - __dirname, - './fixtures/config-scope/from-to/postcss.config.js' - ), - }, - }); - const stats = await compile(compiler); - - const { css, sourceMap } = getCodeFromBundle('style.css', stats); - - sourceMap.sourceRoot = ''; - sourceMap.sources = sourceMap.sources.map((source) => { - expect(path.isAbsolute(source)).toBe(false); - expect(source).toBe(path.normalize(source)); - - return source.replace(/\\/g, '/'); - }); - - expect(css).toMatchSnapshot('css'); - expect(sourceMap).toMatchSnapshot('source map'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); -}); diff --git a/test/parser.test.js b/test/parser.test.js deleted file mode 100644 index ff0c19ef..00000000 --- a/test/parser.test.js +++ /dev/null @@ -1,69 +0,0 @@ -import { - compile, - getCompiler, - getErrors, - getCodeFromBundle, - getWarnings, -} from './helpers'; - -describe('"parser" option', () => { - it('should work with "String" value', async () => { - const compiler = getCompiler('./sss/index.js', { - postcssOptions: { - parser: 'sugarss', - }, - }); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.sss', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should work with "Object" value', async () => { - const compiler = getCompiler('./sss/index.js', { - postcssOptions: { - // eslint-disable-next-line global-require,import/no-dynamic-require - parser: require('sugarss'), - }, - }); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.sss', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should work with "Function" value', async () => { - const compiler = getCompiler('./sss/index.js', { - postcssOptions: { - // eslint-disable-next-line global-require,import/no-dynamic-require - parser: require('sugarss').parse, - }, - }); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.sss', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should throw an error on "unresolved" parser', async () => { - const compiler = getCompiler('./sss/index.js', { - postcssOptions: { - parser: 'unresolved', - }, - }); - - const stats = await compile(compiler); - - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats, true)).toMatchSnapshot('errors'); - }); -}); diff --git a/test/plugins.test.js b/test/plugins.test.js deleted file mode 100644 index 54f2aded..00000000 --- a/test/plugins.test.js +++ /dev/null @@ -1,301 +0,0 @@ -import path from 'path'; - -import { - compile, - getCompiler, - getErrors, - getCodeFromBundle, - getWarnings, -} from './helpers'; - -import myPostcssPlugin from './fixtures/plugin/plugin'; - -jest.setTimeout(30000); - -describe('"plugins" option', () => { - it('should work with "Array" value', async () => { - const compiler = getCompiler('./css/index.js', { - postcssOptions: { - plugins: [ - 'postcss-nested', - ['postcss-short', { prefix: 'x' }], - myPostcssPlugin, - // Like: - // ` - // import myPlugin from './path/to/plugin.mjs'; - // - // const initPlugin = myPlugin(); - // ` - (root) => { - root.walkDecls((decl) => { - if (decl.value === 'red') { - // eslint-disable-next-line no-param-reassign - decl.value = 'rgba(255, 0, 0, 1.0)'; - } - }); - }, - // Like: - // ` - // import myPlugin from './path/to/plugin.mjs'; - // ` - { - postcss: (root) => { - root.walkDecls((decl) => { - if (decl.value === 'green') { - // eslint-disable-next-line no-param-reassign - decl.value = 'rgba(0, 255, 0, 1.0)'; - } - }); - }, - }, - require.resolve('./fixtures/plugin/other-plugin'), - myPostcssPlugin({ color: 'white', alpha: 0 }), - { 'postcss-short': { prefix: 'z' } }, - ], - }, - }); - const stats = await compile(compiler); - const codeFromBundle = getCodeFromBundle('style.css', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should work with "Object" value', async () => { - const compiler = getCompiler('./css/index.js', { - postcssOptions: { - plugins: { - 'postcss-import': {}, - 'postcss-nested': {}, - 'postcss-short': { prefix: 'x' }, - [require.resolve('./fixtures/plugin/other-plugin')]: {}, - }, - }, - }); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.css', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should work with empty "Array" value', async () => { - const compiler = getCompiler('./css/index.js', { - postcssOptions: { - plugins: [], - }, - }); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.css', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should work with empty "Object" value', async () => { - const compiler = getCompiler('./css/index.js', { - postcssOptions: { - plugins: {}, - }, - }); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.css', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should work with "Array" value and support disabling plugins from the configuration', async () => { - const compiler = getCompiler('./css/index.js', { - postcssOptions: { - config: path.resolve(__dirname, './fixtures/css/plugins.config.js'), - plugins: [{ 'postcss-short': false }], - }, - }); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.css', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should work with "Object" value and support disabling plugins from the configuration', async () => { - const compiler = getCompiler('./css/index.js', { - postcssOptions: { - config: path.resolve(__dirname, './fixtures/css/plugins.config.js'), - plugins: { - 'postcss-short': false, - }, - }, - }); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.css', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should work with "Object" value and only disabled plugins', async () => { - const compiler = getCompiler('./css/index.js', { - postcssOptions: { - plugins: { - 'postcss-import': false, - 'postcss-nested': false, - 'postcss-short': false, - }, - }, - }); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.css', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should work with "Array" value and override the previous plugin options', async () => { - const compiler = getCompiler('./css/index.js', { - postcssOptions: { - plugins: [ - ['postcss-short', { prefix: 'x' }], - ['postcss-short', { prefix: 'z' }], - ], - }, - }); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.css', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should work with "Object" value and override the previous plugin options', async () => { - const compiler = getCompiler('./css/index.js', { - postcssOptions: { - plugins: { - 'postcss-short': { prefix: 'x' }, - // eslint-disable-next-line no-dupe-keys - 'postcss-short': { prefix: 'z' }, - }, - }, - }); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.css', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should work with "Array" value, and config, and override the previous plugin options', async () => { - const compiler = getCompiler('./css/index.js', { - postcssOptions: { - config: path.resolve(__dirname, './fixtures/css/plugins.config.js'), - plugins: [['postcss-short', { prefix: 'z' }]], - }, - }); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.css', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should work with "Object" value, and config, and override the previous plugin options', async () => { - const compiler = getCompiler('./css/index.js', { - postcssOptions: { - config: path.resolve(__dirname, './fixtures/css/plugins.config.js'), - plugins: { - 'postcss-short': { prefix: 'z' }, - }, - }, - }); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.css', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should throw an error on the unresolved plugin', async () => { - const compiler = getCompiler('./css/index.js', { - postcssOptions: { - plugins: ['postcss-unresolved'], - }, - }); - const stats = await compile(compiler); - - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats, true)).toMatchSnapshot('errors'); - }); - - it('should work with "Array" value and not throw an error on falsy plugin', async () => { - const compiler = getCompiler('./css/index.js', { - postcssOptions: { - // eslint-disable-next-line no-undefined - plugins: [undefined, null, '', 0], - }, - }); - const stats = await compile(compiler); - - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats, true)).toMatchSnapshot('errors'); - }); - - it('should work with the "default" property without options', async () => { - const compiler = getCompiler('./css/index.js', { - postcssOptions: { - plugins: [ - path.resolve(__dirname, './fixtures/plugin/default-other-plugin.js'), - ], - }, - }); - const stats = await compile(compiler); - const codeFromBundle = getCodeFromBundle('style.css', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should work with the "default" property with options', async () => { - const compiler = getCompiler('./css/index.js', { - postcssOptions: { - plugins: [ - [ - path.resolve( - __dirname, - './fixtures/plugin/default-other-plugin.js' - ), - { alpha: 0.5, color: 'red' }, - ], - ], - }, - }); - const stats = await compile(compiler); - const codeFromBundle = getCodeFromBundle('style.css', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); -}); diff --git a/test/postcssOptins.test.js b/test/postcssOptins.test.js index cf0fa42c..cc48e999 100644 --- a/test/postcssOptins.test.js +++ b/test/postcssOptins.test.js @@ -1,3 +1,5 @@ +import path from 'path'; + import { compile, getCompiler, @@ -5,8 +7,24 @@ import { getCodeFromBundle, getWarnings, } from './helpers'; +import myPostcssPlugin from './fixtures/plugin/plugin'; + +jest.setTimeout(30000); describe('"postcssOptions" option', () => { + it('should work without the specified values in the "postcssOptions" option', async () => { + const compiler = getCompiler('./config-scope/css/index.js', { + postcssOptions: {}, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + it('should work with "from", "to" and "map" options (absolute paths)', async () => { const compiler = getCompiler('./css/index.js', { postcssOptions: { @@ -120,4 +138,640 @@ describe('"postcssOptions" option', () => { expect(getWarnings(stats)).toMatchSnapshot('warnings'); expect(getErrors(stats)).toMatchSnapshot('errors'); }); + + it('should work with the "parser" option with "String" value', async () => { + const compiler = getCompiler('./sss/index.js', { + postcssOptions: { + parser: 'sugarss', + }, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.sss', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work with the "parser" option with "Object" value', async () => { + const compiler = getCompiler('./sss/index.js', { + postcssOptions: { + // eslint-disable-next-line global-require,import/no-dynamic-require + parser: require('sugarss'), + }, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.sss', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work with the "parser" option with "Function" value', async () => { + const compiler = getCompiler('./sss/index.js', { + postcssOptions: { + // eslint-disable-next-line global-require,import/no-dynamic-require + parser: require('sugarss').parse, + }, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.sss', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should throw an error with the "parser" option on the unresolved parser', async () => { + const compiler = getCompiler('./sss/index.js', { + postcssOptions: { + parser: 'unresolved', + }, + }); + + const stats = await compile(compiler); + + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats, true)).toMatchSnapshot('errors'); + }); + + it('should work with the "stringifier" option with "String" value', async () => { + const compiler = getCompiler('./css/index.js', { + postcssOptions: { + stringifier: 'sugarss', + }, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work with the "stringifier" option with "Object" value', async () => { + const compiler = getCompiler('./css/index.js', { + postcssOptions: { + // eslint-disable-next-line global-require + stringifier: require('sugarss'), + }, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work with the "stringifier" option with "Function" value', async () => { + // eslint-disable-next-line global-require + const Midas = require('midas'); + const midas = new Midas(); + + const compiler = getCompiler('./css/index.js', { + postcssOptions: { + stringifier: midas.stringifier, + }, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should throw an error with the "stringifier" option on the unresolved stringifier', async () => { + const compiler = getCompiler('./css/index.js', { + postcssOptions: { + stringifier: 'unresolved', + }, + }); + const stats = await compile(compiler); + + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats, true)).toMatchSnapshot('errors'); + }); + + it('should work with the "syntax" option with "String" value', async () => { + const compiler = getCompiler('./sss/index.js', { + postcssOptions: { + syntax: 'sugarss', + }, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.sss', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work with the "syntax" option with "Object" value', async () => { + const compiler = getCompiler('./sss/index.js', { + postcssOptions: { + // eslint-disable-next-line global-require + syntax: require('sugarss'), + }, + }); + + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.sss', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should throw an error with "syntax" option on the unresolved syntax', async () => { + const compiler = getCompiler('./sss/index.js', { + postcssOptions: { + syntax: 'unresolved', + }, + }); + const stats = await compile(compiler); + + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats, true)).toMatchSnapshot('errors'); + }); + + it('should work with the "plugins" option with "Array" value', async () => { + const compiler = getCompiler('./css/index.js', { + postcssOptions: { + plugins: [ + 'postcss-nested', + ['postcss-short', { prefix: 'x' }], + myPostcssPlugin, + // Like: + // ` + // import myPlugin from './path/to/plugin.mjs'; + // + // const initPlugin = myPlugin(); + // ` + (root) => { + root.walkDecls((decl) => { + if (decl.value === 'red') { + // eslint-disable-next-line no-param-reassign + decl.value = 'rgba(255, 0, 0, 1.0)'; + } + }); + }, + // Like: + // ` + // import myPlugin from './path/to/plugin.mjs'; + // ` + { + postcss: (root) => { + root.walkDecls((decl) => { + if (decl.value === 'green') { + // eslint-disable-next-line no-param-reassign + decl.value = 'rgba(0, 255, 0, 1.0)'; + } + }); + }, + }, + require.resolve('./fixtures/plugin/other-plugin'), + myPostcssPlugin({ color: 'white', alpha: 0 }), + { 'postcss-short': { prefix: 'z' } }, + ], + }, + }); + const stats = await compile(compiler); + const codeFromBundle = getCodeFromBundle('style.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work with the "plugins" option with "Object" value', async () => { + const compiler = getCompiler('./css/index.js', { + postcssOptions: { + plugins: { + 'postcss-import': {}, + 'postcss-nested': {}, + 'postcss-short': { prefix: 'x' }, + [require.resolve('./fixtures/plugin/other-plugin')]: {}, + }, + }, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work with the "plugins" option with empty "Array" value', async () => { + const compiler = getCompiler('./css/index.js', { + postcssOptions: { + plugins: [], + }, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work with the "plugins" option with empty "Object" value', async () => { + const compiler = getCompiler('./css/index.js', { + postcssOptions: { + plugins: {}, + }, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work with the "plugins" option with "Array" value and support disabling plugins from the configuration', async () => { + const compiler = getCompiler('./css/index.js', { + postcssOptions: { + config: path.resolve(__dirname, './fixtures/css/plugins.config.js'), + plugins: [{ 'postcss-short': false }], + }, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work with the "plugins" option with "Object" value and support disabling plugins from the configuration', async () => { + const compiler = getCompiler('./css/index.js', { + postcssOptions: { + config: path.resolve(__dirname, './fixtures/css/plugins.config.js'), + plugins: { + 'postcss-short': false, + }, + }, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work with the "plugins" option with "Object" value and only disabled plugins', async () => { + const compiler = getCompiler('./css/index.js', { + postcssOptions: { + plugins: { + 'postcss-import': false, + 'postcss-nested': false, + 'postcss-short': false, + }, + }, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work with the "plugins" option with "Array" value and override the previous plugin options', async () => { + const compiler = getCompiler('./css/index.js', { + postcssOptions: { + plugins: [ + ['postcss-short', { prefix: 'x' }], + ['postcss-short', { prefix: 'z' }], + ], + }, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work with the "plugins" option with "Object" value and override the previous plugin options', async () => { + const compiler = getCompiler('./css/index.js', { + postcssOptions: { + plugins: { + 'postcss-short': { prefix: 'x' }, + // eslint-disable-next-line no-dupe-keys + 'postcss-short': { prefix: 'z' }, + }, + }, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work with the "plugins" option with "Array" value, and config, and override the previous plugin options', async () => { + const compiler = getCompiler('./css/index.js', { + postcssOptions: { + config: path.resolve(__dirname, './fixtures/css/plugins.config.js'), + plugins: [['postcss-short', { prefix: 'z' }]], + }, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work with the "plugins" option with "Object" value, and config, and override the previous plugin options', async () => { + const compiler = getCompiler('./css/index.js', { + postcssOptions: { + config: path.resolve(__dirname, './fixtures/css/plugins.config.js'), + plugins: { + 'postcss-short': { prefix: 'z' }, + }, + }, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should throw an error with the "plugins" option on the unresolved plugin', async () => { + const compiler = getCompiler('./css/index.js', { + postcssOptions: { + plugins: ['postcss-unresolved'], + }, + }); + const stats = await compile(compiler); + + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats, true)).toMatchSnapshot('errors'); + }); + + it('should work with the "plugins" option with "Array" value and not throw an error on falsy plugin', async () => { + const compiler = getCompiler('./css/index.js', { + postcssOptions: { + // eslint-disable-next-line no-undefined + plugins: [undefined, null, '', 0], + }, + }); + const stats = await compile(compiler); + + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats, true)).toMatchSnapshot('errors'); + }); + + it('should work with the "plugins" option with the "default" property without options', async () => { + const compiler = getCompiler('./css/index.js', { + postcssOptions: { + plugins: [ + path.resolve(__dirname, './fixtures/plugin/default-other-plugin.js'), + ], + }, + }); + const stats = await compile(compiler); + const codeFromBundle = getCodeFromBundle('style.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work with the "plugins" option with the "default" property with options', async () => { + const compiler = getCompiler('./css/index.js', { + postcssOptions: { + plugins: [ + [ + path.resolve( + __dirname, + './fixtures/plugin/default-other-plugin.js' + ), + { alpha: 0.5, color: 'red' }, + ], + ], + }, + }); + const stats = await compile(compiler); + const codeFromBundle = getCodeFromBundle('style.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work with the "config" options with "false" value', async () => { + const compiler = getCompiler('./config-scope/css/index.js', { + postcssOptions: { + config: false, + }, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work with the "config" options with "true" value', async () => { + const compiler = getCompiler('./config-scope/css/index.js', { + postcssOptions: { + config: true, + }, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work with the "config" options with "String" value (absolute path)', async () => { + const compiler = getCompiler('./config-scope/css/index.js', { + postcssOptions: { + config: path.resolve( + __dirname, + './fixtures/config-scope/css/custom.config.js' + ), + }, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work with the "config" options "String" value (relative path)', async () => { + const compiler = getCompiler('./config-scope/css/index.js', { + postcssOptions: { + config: 'test/fixtures/config-scope/css/custom.config.js', + }, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work with the "config" options with "String" value (with path to the directory with the configuration)', async () => { + const compiler = getCompiler('./config-scope/css/index.js', { + postcssOptions: { + config: 'test/fixtures/config-scope', + }, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work with the "config" options with "package.json" configuration', async () => { + const compiler = getCompiler('./config-autoload/pkg/index.js', { + postcssOptions: { + config: path.resolve(__dirname, './fixtures', 'config-autoload/pkg'), + }, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('index.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work with the "config" options and use plugins', async () => { + const compiler = getCompiler('./config-scope/css/index.js', { + postcssOptions: { + config: true, + plugins: ['postcss-rtl'], + }, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work with the "config" options with "String" value and respect all options', async () => { + const compiler = getCompiler('./sss/index.js', { + postcssOptions: { + config: path.resolve( + __dirname, + './fixtures/config-scope/all-options/postcss.config.js' + ), + }, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.sss', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should throw an error with the "config" option on the unresolved config', async () => { + const compiler = getCompiler('./config-scope/css/index.js', { + postcssOptions: { + config: path.resolve( + __dirname, + './fixtures/config-scope/css/unresolve.js' + ), + }, + }); + const stats = await compile(compiler); + + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats, true)).toMatchSnapshot('errors'); + }); + + it('should throw an error with the "config" option on the invalid config', async () => { + const compiler = getCompiler('./config-scope/css/index.js', { + postcssOptions: { + config: path.resolve( + __dirname, + './fixtures/config-scope/css/invalid.config.js' + ), + }, + }); + const stats = await compile(compiler); + + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats, true)).toMatchSnapshot('errors'); + }); + + it('should work with the "config" options and resolve "from" and "to" options', async () => { + const compiler = getCompiler('./config-scope/css/index.js', { + postcssOptions: { + config: path.resolve( + __dirname, + './fixtures/config-scope/from-to/postcss.config.js' + ), + }, + }); + const stats = await compile(compiler); + + const { css, sourceMap } = getCodeFromBundle('style.css', stats); + + sourceMap.sourceRoot = ''; + sourceMap.sources = sourceMap.sources.map((source) => { + expect(path.isAbsolute(source)).toBe(false); + expect(source).toBe(path.normalize(source)); + + return source.replace(/\\/g, '/'); + }); + + expect(css).toMatchSnapshot('css'); + expect(sourceMap).toMatchSnapshot('source map'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); }); diff --git a/test/stringifier.test.js b/test/stringifier.test.js deleted file mode 100644 index 1103e5da..00000000 --- a/test/stringifier.test.js +++ /dev/null @@ -1,71 +0,0 @@ -import { - compile, - getCompiler, - getErrors, - getCodeFromBundle, - getWarnings, -} from './helpers'; - -describe('"stringifier" option', () => { - it('should work with "String" value', async () => { - const compiler = getCompiler('./css/index.js', { - postcssOptions: { - stringifier: 'sugarss', - }, - }); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.css', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should work "Object" value', async () => { - const compiler = getCompiler('./css/index.js', { - postcssOptions: { - // eslint-disable-next-line global-require - stringifier: require('sugarss'), - }, - }); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.css', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should work "Function" value', async () => { - // eslint-disable-next-line global-require - const Midas = require('midas'); - const midas = new Midas(); - - const compiler = getCompiler('./css/index.js', { - postcssOptions: { - stringifier: midas.stringifier, - }, - }); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.css', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should throw an error on "unresolved" stringifier', async () => { - const compiler = getCompiler('./css/index.js', { - postcssOptions: { - stringifier: 'unresolved', - }, - }); - const stats = await compile(compiler); - - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats, true)).toMatchSnapshot('errors'); - }); -}); diff --git a/test/syntax.test.js b/test/syntax.test.js deleted file mode 100644 index 7089e4cc..00000000 --- a/test/syntax.test.js +++ /dev/null @@ -1,53 +0,0 @@ -import { - compile, - getCompiler, - getErrors, - getCodeFromBundle, - getWarnings, -} from './helpers'; - -describe('"syntax" option', () => { - it('should work with "String" value', async () => { - const compiler = getCompiler('./sss/index.js', { - postcssOptions: { - syntax: 'sugarss', - }, - }); - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.sss', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should work with "Object" value', async () => { - const compiler = getCompiler('./sss/index.js', { - postcssOptions: { - // eslint-disable-next-line global-require - syntax: require('sugarss'), - }, - }); - - const stats = await compile(compiler); - - const codeFromBundle = getCodeFromBundle('style.sss', stats); - - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); - }); - - it('should throw an error on "unresolved" syntax', async () => { - const compiler = getCompiler('./sss/index.js', { - postcssOptions: { - syntax: 'unresolved', - }, - }); - const stats = await compile(compiler); - - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats, true)).toMatchSnapshot('errors'); - }); -});