From b3e63784b096bea7e7c2654e7c9d0adcc2094b7a Mon Sep 17 00:00:00 2001 From: Alexander Akait <4567934+alexander-akait@users.noreply.github.com> Date: Mon, 4 Oct 2021 20:52:10 +0300 Subject: [PATCH] refactor: error/warning messages (#125) --- src/index.js | 12 ++--- .../CssMinimizerPlugin.test.js.snap | 48 +++++++++---------- test/__snapshots__/cache-option.test.js.snap | 20 ++++---- test/__snapshots__/minify-option.test.js.snap | 10 ++-- .../sourceMap-option.test.js.snap | 4 +- .../warningsFilter-option.test.js.snap | 4 +- 6 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/index.js b/src/index.js index e408374..24fc205 100644 --- a/src/index.js +++ b/src/index.js @@ -106,7 +106,7 @@ class CssMinimizerPlugin { } const builtWarning = new Error( - `${file} from Css Minimizer Plugin\n${warningMessage}${ + `${file} from Css Minimizer plugin\n${warningMessage}${ locationMessage ? ` ${locationMessage}` : "" }` ); @@ -122,7 +122,7 @@ class CssMinimizerPlugin { let builtError; if (typeof error === "string") { - builtError = new Error(`${file} from Css Minimizer Plugin\n${error}`); + builtError = new Error(`${file} from Css Minimizer plugin\n${error}`); builtError.file = file; return builtError; @@ -138,7 +138,7 @@ class CssMinimizerPlugin { if (original && original.source && requestShortener) { builtError = new Error( - `${file} from Css Minimizer Plugin\n${ + `${file} from Css Minimizer plugin\n${ error.message } [${requestShortener.shorten(original.source)}:${original.line},${ original.column @@ -154,7 +154,7 @@ class CssMinimizerPlugin { } builtError = new Error( - `${file} from Css Minimizer Plugin\n${error.message} [${file}:${ + `${file} from Css Minimizer plugin\n${error.message} [${file}:${ error.line },${error.column}]${ error.stack ? `\n${error.stack.split("\n").slice(1).join("\n")}` : "" @@ -167,7 +167,7 @@ class CssMinimizerPlugin { if (error.stack) { builtError = new Error( - `${file} from Css Minimizer Plugin\n${error.stack}` + `${file} from Css Minimizer plugin\n${error.stack}` ); builtError.file = file; @@ -175,7 +175,7 @@ class CssMinimizerPlugin { } builtError = new Error( - `${file} from Css Minimizer Plugin\n${error.message}` + `${file} from Css Minimizer plugin\n${error.message}` ); builtError.file = file; diff --git a/test/__snapshots__/CssMinimizerPlugin.test.js.snap b/test/__snapshots__/CssMinimizerPlugin.test.js.snap index f315a16..b320a6f 100644 --- a/test/__snapshots__/CssMinimizerPlugin.test.js.snap +++ b/test/__snapshots__/CssMinimizerPlugin.test.js.snap @@ -1,47 +1,47 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`CssMinimizerPlugin buildError method 1`] = ` -[Error: test.css from Css Minimizer Plugin +[Error: test.css from Css Minimizer plugin Message] `; exports[`CssMinimizerPlugin buildError method 2`] = ` -[Error: test.css from Css Minimizer Plugin +[Error: test.css from Css Minimizer plugin Message [test.css:1,1]] `; exports[`CssMinimizerPlugin buildError method 3`] = ` -[Error: test.css from Css Minimizer Plugin +[Error: test.css from Css Minimizer plugin Message [http://example.com/www/js/one.css:1,1][test.css:1,1]] `; exports[`CssMinimizerPlugin buildError method 4`] = ` -[Error: test.css from Css Minimizer Plugin +[Error: test.css from Css Minimizer plugin Stack] `; exports[`CssMinimizerPlugin buildWarning method 1`] = ` -[Warning: undefined from Css Minimizer Plugin +[Warning: undefined from Css Minimizer plugin Warning test.css:1:1] `; exports[`CssMinimizerPlugin buildWarning method 2`] = ` -[Warning: test.css from Css Minimizer Plugin +[Warning: test.css from Css Minimizer plugin Warning test.css:1:1] `; exports[`CssMinimizerPlugin buildWarning method 3`] = ` -[Warning: test.css from Css Minimizer Plugin +[Warning: test.css from Css Minimizer plugin Warning test.css:1:1] `; exports[`CssMinimizerPlugin buildWarning method 4`] = ` -[Warning: test.css from Css Minimizer Plugin +[Warning: test.css from Css Minimizer plugin Warning http://example.com/www/js/one.css:1:1] `; exports[`CssMinimizerPlugin buildWarning method 5`] = ` -[Warning: test.css from Css Minimizer Plugin +[Warning: test.css from Css Minimizer plugin Warning http://example.com/www/js/one.css:1:1] `; @@ -49,7 +49,7 @@ exports[`CssMinimizerPlugin buildWarning method 6`] = `null`; exports[`CssMinimizerPlugin should build error: error 1`] = ` Array [ - "Error: error.css from Css Minimizer Plugin + "Error: error.css from Css Minimizer plugin /error.css:1:1: Unknown word [error.css:1,1]", ] `; @@ -60,7 +60,7 @@ exports[`CssMinimizerPlugin should build warning: error 1`] = `Array []`; exports[`CssMinimizerPlugin should build warning: warning 1`] = ` Array [ - "Warning: foo.css from Css Minimizer Plugin + "Warning: foo.css from Css Minimizer plugin [warning-plugin] Warning", ] `; @@ -87,7 +87,7 @@ exports[`CssMinimizerPlugin should run plugin against assets added later by plug exports[`CssMinimizerPlugin should throw error from postcss: error 1`] = ` Array [ - "Error: foo.css from Css Minimizer Plugin + "Error: foo.css from Css Minimizer plugin error-plugin: /foo.css:2:3: Postcss error [webpack://./test/foo.css:2,2][foo.css:2,3]", ] `; @@ -313,11 +313,11 @@ a { exports[`CssMinimizerPlugin should work with warnings and use memory cache when the "cache" option is "true" and the asset has been changed: errors 1`] = ` Array [ - "Warning: foo.css from Css Minimizer Plugin + "Warning: foo.css from Css Minimizer plugin [warning-plugin] Warning from foo.css", - "Warning: style-2.css from Css Minimizer Plugin + "Warning: style-2.css from Css Minimizer plugin [warning-plugin] Warning from style-2.css", - "Warning: style.css from Css Minimizer Plugin + "Warning: style.css from Css Minimizer plugin [warning-plugin] Warning from style.css", ] `; @@ -328,11 +328,11 @@ exports[`CssMinimizerPlugin should work with warnings and use memory cache when exports[`CssMinimizerPlugin should work with warnings and use memory cache when the "cache" option is "true" and the asset has been changed: warnings 2`] = ` Array [ - "Warning: foo.css from Css Minimizer Plugin + "Warning: foo.css from Css Minimizer plugin [warning-plugin] Warning from foo.css", - "Warning: style-2.css from Css Minimizer Plugin + "Warning: style-2.css from Css Minimizer plugin [warning-plugin] Warning from style-2.css", - "Warning: style.css from Css Minimizer Plugin + "Warning: style.css from Css Minimizer plugin [warning-plugin] Warning from style.css", ] `; @@ -367,11 +367,11 @@ a { exports[`CssMinimizerPlugin should work with warnings and use memory cache when the "cache" option is "true": errors 1`] = ` Array [ - "Warning: foo.css from Css Minimizer Plugin + "Warning: foo.css from Css Minimizer plugin [warning-plugin] Warning from foo.css", - "Warning: style-2.css from Css Minimizer Plugin + "Warning: style-2.css from Css Minimizer plugin [warning-plugin] Warning from style-2.css", - "Warning: style.css from Css Minimizer Plugin + "Warning: style.css from Css Minimizer plugin [warning-plugin] Warning from style.css", ] `; @@ -382,11 +382,11 @@ exports[`CssMinimizerPlugin should work with warnings and use memory cache when exports[`CssMinimizerPlugin should work with warnings and use memory cache when the "cache" option is "true": warnings 2`] = ` Array [ - "Warning: foo.css from Css Minimizer Plugin + "Warning: foo.css from Css Minimizer plugin [warning-plugin] Warning from foo.css", - "Warning: style-2.css from Css Minimizer Plugin + "Warning: style-2.css from Css Minimizer plugin [warning-plugin] Warning from style-2.css", - "Warning: style.css from Css Minimizer Plugin + "Warning: style.css from Css Minimizer plugin [warning-plugin] Warning from style.css", ] `; diff --git a/test/__snapshots__/cache-option.test.js.snap b/test/__snapshots__/cache-option.test.js.snap index 574b5de..b9e1996 100644 --- a/test/__snapshots__/cache-option.test.js.snap +++ b/test/__snapshots__/cache-option.test.js.snap @@ -132,30 +132,30 @@ exports[`"cache" option should work with the "filesystem" value for the "cache.t exports[`"cache" option should work with the "filesystem" value for the "cache.type" option and output warnings: warnings 1`] = ` Array [ - "Warning: five.css from Css Minimizer Plugin + "Warning: five.css from Css Minimizer plugin [warning-plugin] Warning from five.css", - "Warning: four.css from Css Minimizer Plugin + "Warning: four.css from Css Minimizer plugin [warning-plugin] Warning from four.css", - "Warning: one.css from Css Minimizer Plugin + "Warning: one.css from Css Minimizer plugin [warning-plugin] Warning from one.css", - "Warning: three.css from Css Minimizer Plugin + "Warning: three.css from Css Minimizer plugin [warning-plugin] Warning from three.css", - "Warning: two.css from Css Minimizer Plugin + "Warning: two.css from Css Minimizer plugin [warning-plugin] Warning from two.css", ] `; exports[`"cache" option should work with the "filesystem" value for the "cache.type" option and output warnings: warnings 2`] = ` Array [ - "Warning: five.css from Css Minimizer Plugin + "Warning: five.css from Css Minimizer plugin [warning-plugin] Warning from five.css", - "Warning: four.css from Css Minimizer Plugin + "Warning: four.css from Css Minimizer plugin [warning-plugin] Warning from four.css", - "Warning: one.css from Css Minimizer Plugin + "Warning: one.css from Css Minimizer plugin [warning-plugin] Warning from one.css", - "Warning: three.css from Css Minimizer Plugin + "Warning: three.css from Css Minimizer plugin [warning-plugin] Warning from three.css", - "Warning: two.css from Css Minimizer Plugin + "Warning: two.css from Css Minimizer plugin [warning-plugin] Warning from two.css", ] `; diff --git a/test/__snapshots__/minify-option.test.js.snap b/test/__snapshots__/minify-option.test.js.snap index cd9cc2e..0f9ab12 100644 --- a/test/__snapshots__/minify-option.test.js.snap +++ b/test/__snapshots__/minify-option.test.js.snap @@ -10,13 +10,13 @@ exports[`"minify" option should work and allow to return errors and warnings fro exports[`"minify" option should work and allow to return errors and warnings from custom function: warning 1`] = ` Array [ - "Error: foo.css from Css Minimizer Plugin + "Error: foo.css from Css Minimizer plugin Error 1", - "Error: foo.css from Css Minimizer Plugin + "Error: foo.css from Css Minimizer plugin Error: Error 2", - "Warning: foo.css from Css Minimizer Plugin + "Warning: foo.css from Css Minimizer plugin Warning 1", - "Warning: foo.css from Css Minimizer Plugin + "Warning: foo.css from Css Minimizer plugin Warning 2", ] `; @@ -100,7 +100,7 @@ body a { exports[`"minify" option should work throw an error if minimizer function doesn't return: error 1`] = ` Array [ - "Error: foo.css from Css Minimizer Plugin + "Error: foo.css from Css Minimizer plugin Error: Minimizer function doesn't return result", ] `; diff --git a/test/__snapshots__/sourceMap-option.test.js.snap b/test/__snapshots__/sourceMap-option.test.js.snap index c4bbf0d..0551bfe 100644 --- a/test/__snapshots__/sourceMap-option.test.js.snap +++ b/test/__snapshots__/sourceMap-option.test.js.snap @@ -2,10 +2,10 @@ exports[`when applied with "sourceMap" option should work and emit warning on valid sourcemap and minimizer error: errors 1`] = ` Array [ - "Error: broken-source-map.css from Css Minimizer Plugin + "Error: broken-source-map.css from Css Minimizer plugin error-plugin: /broken-source-map.css:1:7: Postcss error [test:1,5][broken-source-map.css:1,7]", "ModuleBuildError: Module build failed (from ../../node_modules/mini-css-extract-plugin/dist/loader.js): -Error: broken-source-map.css from Css Minimizer Plugin", +Error: broken-source-map.css from Css Minimizer plugin", ] `; diff --git a/test/__snapshots__/warningsFilter-option.test.js.snap b/test/__snapshots__/warningsFilter-option.test.js.snap index 30ee0a7..c214ef0 100644 --- a/test/__snapshots__/warningsFilter-option.test.js.snap +++ b/test/__snapshots__/warningsFilter-option.test.js.snap @@ -36,9 +36,9 @@ exports[`warningsFilter option should match snapshot for a "function" value: err exports[`warningsFilter option should match snapshot for a "function" value: warnings 1`] = ` Array [ - "Warning: bar1.css from Css Minimizer Plugin + "Warning: bar1.css from Css Minimizer plugin [warning-plugin] Warning from bar1.css", - "Warning: bar2.css from Css Minimizer Plugin + "Warning: bar2.css from Css Minimizer plugin [warning-plugin] Warning from bar2.css", ] `;