From 56e12fd6207373b07eaa7bafe335f9d4af974348 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Wed, 31 Jul 2019 17:16:37 +0200 Subject: [PATCH] extract LogTestPlugin --- .../__snapshots__/StatsTestCases.test.js.snap | 34 ++++++++++++------- test/helpers/LogTestPlugin.js | 30 ++++++++++++++++ test/statsCases/logging/webpack.config.js | 18 ++-------- .../preset-detailed/webpack.config.js | 20 ++--------- .../webpack.config.js | 20 ++--------- .../preset-errors-warnings/webpack.config.js | 20 ++--------- .../preset-minimal/webpack.config.js | 20 ++--------- test/statsCases/preset-none/webpack.config.js | 20 ++--------- .../preset-normal/webpack.config.js | 20 ++--------- .../preset-verbose/webpack.config.js | 20 ++--------- 10 files changed, 67 insertions(+), 155 deletions(-) create mode 100644 test/helpers/LogTestPlugin.js diff --git a/test/__snapshots__/StatsTestCases.test.js.snap b/test/__snapshots__/StatsTestCases.test.js.snap index 130be5be105..f777c5f7469 100644 --- a/test/__snapshots__/StatsTestCases.test.js.snap +++ b/test/__snapshots__/StatsTestCases.test.js.snap @@ -1244,9 +1244,13 @@ Built at: Thu Jan 01 1970 00:00:00 GMT Entrypoint main = main.js [0] ./index.js 0 bytes {0} [built] -LOG from MyPlugin - Plugin is now active -<+> Nested +LOG from LogTestPlugin +<-> Group + Info + Log + <+> Collaped group + Log + End + 3 hidden lines DEBUG LOG from node_modules/custom-loader/index.js node_modules/custom-loader/index.js!index.js @@ -1941,13 +1945,15 @@ chunk {3} 3.js 54 bytes <{0}> >{1}< [rendered] [5] ./e.js 22 bytes {1} [depth 2] [built] ModuleConcatenation bailout: Module is not an ECMAScript module -LOG from MyPlugin +LOG from LogTestPlugin <-> Group Error Warning Info Log <+> Collaped group + Log + End + 3 hidden lines" `; @@ -1955,9 +1961,9 @@ exports[`StatsTestCases should print correct stats for preset-errors-only 1`] = exports[`StatsTestCases should print correct stats for preset-errors-only-error 1`] = ` " -LOG from MyPlugin +LOG from LogTestPlugin Error -+ 9 hidden lines ++ 11 hidden lines ERROR in ./index.js Module not found: Error: Can't resolve 'does-not-exist' in 'Xdir/preset-errors-only-error' @@ -1966,19 +1972,19 @@ Module not found: Error: Can't resolve 'does-not-exist' in 'Xdir/preset-errors-o exports[`StatsTestCases should print correct stats for preset-errors-warnings 1`] = ` " -LOG from MyPlugin +LOG from LogTestPlugin Error Warning -+ 8 hidden lines" ++ 10 hidden lines" `; exports[`StatsTestCases should print correct stats for preset-minimal 1`] = ` " 6 modules -LOG from MyPlugin +LOG from LogTestPlugin Error Warning -+ 8 hidden lines" ++ 10 hidden lines" `; exports[`StatsTestCases should print correct stats for preset-minimal-simple 1`] = `" 1 module"`; @@ -2014,11 +2020,11 @@ Entrypoint main = main.js [4] ./d.js 22 bytes {1} [built] [5] ./e.js 22 bytes {1} [built] -LOG from MyPlugin +LOG from LogTestPlugin Error Warning Info -+ 7 hidden lines" ++ 9 hidden lines" `; exports[`StatsTestCases should print correct stats for preset-normal-performance 1`] = ` @@ -2124,7 +2130,7 @@ chunk {3} 3.js 54 bytes <{0}> >{1}< [rendered] amd require ./c [0] ./index.js 3:0-16 [0] Xms -> factory:Xms building:Xms = Xms -LOG from MyPlugin +LOG from LogTestPlugin <-> Group Error Warning @@ -2132,6 +2138,8 @@ LOG from MyPlugin Log <-> Collaped group Log inside collapsed group + Log + End + 1 hidden lines LOG from webpack.buildChunkGraph.visitModules diff --git a/test/helpers/LogTestPlugin.js b/test/helpers/LogTestPlugin.js new file mode 100644 index 00000000000..0e1a1c321fa --- /dev/null +++ b/test/helpers/LogTestPlugin.js @@ -0,0 +1,30 @@ +module.exports = class LogTestPlugin { + constructor(noTraced) { + this.noTraced = noTraced; + } + apply(compiler) { + const logSome = logger => { + logger.group("Group"); + if (!this.noTraced) { + logger.error("Error"); + logger.warn("Warning"); + } + logger.info("Info"); + logger.log("Log"); + logger.debug("Debug"); + logger.groupCollapsed("Collaped group"); + logger.log("Log inside collapsed group"); + logger.groupEnd(); + logger.log("Log"); + logger.groupEnd(); + logger.log("End"); + }; + compiler.hooks.compilation.tap("LogTestPlugin", compilation => { + const logger = compilation.getLogger("LogTestPlugin"); + logSome(logger); + + const otherLogger = compilation.getLogger("LogOtherTestPlugin"); + otherLogger.debug("debug message only"); + }); + } +}; diff --git a/test/statsCases/logging/webpack.config.js b/test/statsCases/logging/webpack.config.js index ce49b7dc908..8d89f8f6ad1 100644 --- a/test/statsCases/logging/webpack.config.js +++ b/test/statsCases/logging/webpack.config.js @@ -1,18 +1,4 @@ -class MyPlugin { - apply(compiler) { - compiler.hooks.compilation.tap("MyPlugin", compilation => { - const logger = compilation.getLogger("MyPlugin"); - logger.info("Plugin is now active"); - logger.debug("Debug message should not be visible"); - logger.groupCollapsed("Nested"); - logger.log("Log inside collapsed group"); - logger.groupEnd("Nested"); - - const otherLogger = compilation.getLogger("MyOtherPlugin"); - otherLogger.debug("debug message only"); - }); - } -} +const LogTestPlugin = require("../../helpers/LogTestPlugin"); module.exports = { mode: "production", @@ -26,7 +12,7 @@ module.exports = { } ] }, - plugins: [new MyPlugin()], + plugins: [new LogTestPlugin(true)], stats: { colors: true, logging: true, diff --git a/test/statsCases/preset-detailed/webpack.config.js b/test/statsCases/preset-detailed/webpack.config.js index 69502271482..a41b087a26d 100644 --- a/test/statsCases/preset-detailed/webpack.config.js +++ b/test/statsCases/preset-detailed/webpack.config.js @@ -1,24 +1,8 @@ -class MyPlugin { - apply(compiler) { - compiler.hooks.compilation.tap("MyPlugin", compilation => { - const logger = compilation.getLogger("MyPlugin"); - logger.group("Group"); - logger.error("Error"); - logger.warn("Warning"); - logger.info("Info"); - logger.log("Log"); - logger.debug("Debug"); - logger.groupCollapsed("Collaped group"); - logger.log("Log inside collapsed group"); - logger.groupEnd(); - logger.groupEnd(); - }); - } -} +const LogTestPlugin = require("../../helpers/LogTestPlugin"); module.exports = { mode: "production", entry: "./index", stats: "detailed", - plugins: [new MyPlugin()] + plugins: [new LogTestPlugin()] }; diff --git a/test/statsCases/preset-errors-only-error/webpack.config.js b/test/statsCases/preset-errors-only-error/webpack.config.js index 2ac28317527..38a3f320168 100644 --- a/test/statsCases/preset-errors-only-error/webpack.config.js +++ b/test/statsCases/preset-errors-only-error/webpack.config.js @@ -1,24 +1,8 @@ -class MyPlugin { - apply(compiler) { - compiler.hooks.compilation.tap("MyPlugin", compilation => { - const logger = compilation.getLogger("MyPlugin"); - logger.group("Group"); - logger.error("Error"); - logger.warn("Warning"); - logger.info("Info"); - logger.log("Log"); - logger.debug("Debug"); - logger.groupCollapsed("Collaped group"); - logger.log("Log inside collapsed group"); - logger.groupEnd(); - logger.groupEnd(); - }); - } -} +const LogTestPlugin = require("../../helpers/LogTestPlugin"); module.exports = { mode: "production", entry: "./index", stats: "errors-only", - plugins: [new MyPlugin()] + plugins: [new LogTestPlugin()] }; diff --git a/test/statsCases/preset-errors-warnings/webpack.config.js b/test/statsCases/preset-errors-warnings/webpack.config.js index 038aa982fe9..f8ccd58cc17 100644 --- a/test/statsCases/preset-errors-warnings/webpack.config.js +++ b/test/statsCases/preset-errors-warnings/webpack.config.js @@ -1,24 +1,8 @@ -class MyPlugin { - apply(compiler) { - compiler.hooks.compilation.tap("MyPlugin", compilation => { - const logger = compilation.getLogger("MyPlugin"); - logger.group("Group"); - logger.error("Error"); - logger.warn("Warning"); - logger.info("Info"); - logger.log("Log"); - logger.debug("Debug"); - logger.groupCollapsed("Collaped group"); - logger.log("Log inside collapsed group"); - logger.groupEnd(); - logger.groupEnd(); - }); - } -} +const LogTestPlugin = require("../../helpers/LogTestPlugin"); module.exports = { mode: "production", entry: "./index", stats: "errors-warnings", - plugins: [new MyPlugin()] + plugins: [new LogTestPlugin()] }; diff --git a/test/statsCases/preset-minimal/webpack.config.js b/test/statsCases/preset-minimal/webpack.config.js index 45e664f3508..fd9934b2fe0 100644 --- a/test/statsCases/preset-minimal/webpack.config.js +++ b/test/statsCases/preset-minimal/webpack.config.js @@ -1,24 +1,8 @@ -class MyPlugin { - apply(compiler) { - compiler.hooks.compilation.tap("MyPlugin", compilation => { - const logger = compilation.getLogger("MyPlugin"); - logger.group("Group"); - logger.error("Error"); - logger.warn("Warning"); - logger.info("Info"); - logger.log("Log"); - logger.debug("Debug"); - logger.groupCollapsed("Collaped group"); - logger.log("Log inside collapsed group"); - logger.groupEnd(); - logger.groupEnd(); - }); - } -} +const LogTestPlugin = require("../../helpers/LogTestPlugin"); module.exports = { mode: "production", entry: "./index", stats: "minimal", - plugins: [new MyPlugin()] + plugins: [new LogTestPlugin()] }; diff --git a/test/statsCases/preset-none/webpack.config.js b/test/statsCases/preset-none/webpack.config.js index 0a3d5be8ffb..750ca8a5130 100644 --- a/test/statsCases/preset-none/webpack.config.js +++ b/test/statsCases/preset-none/webpack.config.js @@ -1,24 +1,8 @@ -class MyPlugin { - apply(compiler) { - compiler.hooks.compilation.tap("MyPlugin", compilation => { - const logger = compilation.getLogger("MyPlugin"); - logger.group("Group"); - logger.error("Error"); - logger.warn("Warning"); - logger.info("Info"); - logger.log("Log"); - logger.debug("Debug"); - logger.groupCollapsed("Collaped group"); - logger.log("Log inside collapsed group"); - logger.groupEnd(); - logger.groupEnd(); - }); - } -} +const LogTestPlugin = require("../../helpers/LogTestPlugin"); module.exports = { mode: "production", entry: "./index", stats: false, - plugins: [new MyPlugin()] + plugins: [new LogTestPlugin()] }; diff --git a/test/statsCases/preset-normal/webpack.config.js b/test/statsCases/preset-normal/webpack.config.js index 5d85c8aabeb..ae534acc109 100644 --- a/test/statsCases/preset-normal/webpack.config.js +++ b/test/statsCases/preset-normal/webpack.config.js @@ -1,24 +1,8 @@ -class MyPlugin { - apply(compiler) { - compiler.hooks.compilation.tap("MyPlugin", compilation => { - const logger = compilation.getLogger("MyPlugin"); - logger.group("Group"); - logger.error("Error"); - logger.warn("Warning"); - logger.info("Info"); - logger.log("Log"); - logger.debug("Debug"); - logger.groupCollapsed("Collaped group"); - logger.log("Log inside collapsed group"); - logger.groupEnd(); - logger.groupEnd(); - }); - } -} +const LogTestPlugin = require("../../helpers/LogTestPlugin"); module.exports = { mode: "production", entry: "./index", stats: "normal", - plugins: [new MyPlugin()] + plugins: [new LogTestPlugin()] }; diff --git a/test/statsCases/preset-verbose/webpack.config.js b/test/statsCases/preset-verbose/webpack.config.js index e4d57fe96ae..bb9778aea44 100644 --- a/test/statsCases/preset-verbose/webpack.config.js +++ b/test/statsCases/preset-verbose/webpack.config.js @@ -1,25 +1,9 @@ -class MyPlugin { - apply(compiler) { - compiler.hooks.compilation.tap("MyPlugin", compilation => { - const logger = compilation.getLogger("MyPlugin"); - logger.group("Group"); - logger.error("Error"); - logger.warn("Warning"); - logger.info("Info"); - logger.log("Log"); - logger.debug("Debug"); - logger.groupCollapsed("Collaped group"); - logger.log("Log inside collapsed group"); - logger.groupEnd(); - logger.groupEnd(); - }); - } -} +const LogTestPlugin = require("../../helpers/LogTestPlugin"); module.exports = { mode: "production", entry: "./index", profile: true, stats: "verbose", - plugins: [new MyPlugin()] + plugins: [new LogTestPlugin()] };