Skip to content

Commit

Permalink
extract LogTestPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Aug 1, 2019
1 parent def2947 commit 56e12fd
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 155 deletions.
34 changes: 21 additions & 13 deletions test/__snapshots__/StatsTestCases.test.js.snap
Expand Up @@ -1244,9 +1244,13 @@ Built at: Thu Jan 01 1970 <CLR=BOLD>00:00:00</CLR> GMT
Entrypoint <CLR=BOLD>main</CLR> = <CLR=32,BOLD>main.js</CLR>
[0] <CLR=BOLD>./index.js</CLR> 0 bytes {<CLR=33,BOLD>0</CLR>}<CLR=32,BOLD> [built]</CLR>
<CLR=BOLD>LOG from MyPlugin</CLR>
<i> <CLR=32,BOLD>Plugin is now active</CLR>
<+> <CLR=36,BOLD>Nested</CLR>
<CLR=BOLD>LOG from LogTestPlugin</CLR>
<-> <CLR=36,BOLD>Group</CLR>
<i> <CLR=32,BOLD>Info</CLR>
<CLR=BOLD>Log</CLR>
<+> <CLR=36,BOLD>Collaped group</CLR>
<CLR=BOLD>Log</CLR>
<CLR=BOLD>End</CLR>
+ 3 hidden lines
<CLR=31,BOLD>DEBUG </CLR><CLR=BOLD>LOG from node_modules/custom-loader/index.js node_modules/custom-loader/index.js!index.js</CLR>
Expand Down Expand Up @@ -1941,23 +1945,25 @@ 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
<e> Error
<w> Warning
<i> Info
Log
<+> Collaped group
Log
End
+ 3 hidden lines"
`;
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
<e> 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'
Expand All @@ -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
<e> Error
<w> 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
<e> Error
<w> Warning
+ 8 hidden lines"
+ 10 hidden lines"
`;
exports[`StatsTestCases should print correct stats for preset-minimal-simple 1`] = `" 1 module"`;
Expand Down Expand Up @@ -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
<e> Error
<w> Warning
<i> Info
+ 7 hidden lines"
+ 9 hidden lines"
`;
exports[`StatsTestCases should print correct stats for preset-normal-performance 1`] = `
Expand Down Expand Up @@ -2124,14 +2130,16 @@ 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
<e> Error
<w> Warning
<i> Info
Log
<-> Collaped group
Log inside collapsed group
Log
End
+ 1 hidden lines
LOG from webpack.buildChunkGraph.visitModules
Expand Down
30 changes: 30 additions & 0 deletions 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");
});
}
};
18 changes: 2 additions & 16 deletions 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",
Expand All @@ -26,7 +12,7 @@ module.exports = {
}
]
},
plugins: [new MyPlugin()],
plugins: [new LogTestPlugin(true)],
stats: {
colors: true,
logging: true,
Expand Down
20 changes: 2 additions & 18 deletions 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()]
};
20 changes: 2 additions & 18 deletions 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()]
};
20 changes: 2 additions & 18 deletions 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()]
};
20 changes: 2 additions & 18 deletions 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()]
};
20 changes: 2 additions & 18 deletions 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()]
};
20 changes: 2 additions & 18 deletions 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()]
};
20 changes: 2 additions & 18 deletions 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()]
};

0 comments on commit 56e12fd

Please sign in to comment.