Skip to content

Commit

Permalink
refactor: error/warning messages (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Oct 4, 2021
1 parent 119a66a commit b3e6378
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 49 deletions.
12 changes: 6 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}` : ""
}`
);
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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")}` : ""
Expand All @@ -167,15 +167,15 @@ 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;

return builtError;
}

builtError = new Error(
`${file} from Css Minimizer Plugin\n${error.message}`
`${file} from Css Minimizer plugin\n${error.message}`
);
builtError.file = file;

Expand Down
48 changes: 24 additions & 24 deletions test/__snapshots__/CssMinimizerPlugin.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
// 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]
`;

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]",
]
`;
Expand All @@ -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",
]
`;
Expand All @@ -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]",
]
`;
Expand Down Expand Up @@ -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",
]
`;
Expand All @@ -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",
]
`;
Expand Down Expand Up @@ -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",
]
`;
Expand All @@ -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",
]
`;
Expand Down
20 changes: 10 additions & 10 deletions test/__snapshots__/cache-option.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
`;
Expand Down
10 changes: 5 additions & 5 deletions test/__snapshots__/minify-option.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
`;
Expand Down Expand Up @@ -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",
]
`;
Expand Down
4 changes: 2 additions & 2 deletions test/__snapshots__/sourceMap-option.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
`;

Expand Down
4 changes: 2 additions & 2 deletions test/__snapshots__/warningsFilter-option.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
`;

0 comments on commit b3e6378

Please sign in to comment.