Skip to content

Commit

Permalink
capture infrastructure log
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Aug 1, 2019
1 parent 56e12fd commit 4c472ad
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
5 changes: 5 additions & 0 deletions test/StatsTestCases.test.js
Expand Up @@ -6,6 +6,7 @@ const fs = require("fs");

const webpack = require("../lib/webpack");
const Stats = require("../lib/Stats");
const captureStdio = require("./helpers/captureStdio");

/**
* Escapes regular expression metacharacters
Expand Down Expand Up @@ -66,7 +67,9 @@ describe("StatsTestCases", () => {
})
);
});
const captured = captureStdio(process.stderr);
const c = webpack(options);
captured.restore();
const compilers = c.compilers ? c.compilers : [c];
compilers.forEach(c => {
const ifs = c.inputFileSystem;
Expand Down Expand Up @@ -111,6 +114,7 @@ describe("StatsTestCases", () => {
let actual = stats.toString(toStringOptions);
expect(typeof actual).toBe("string");
if (!hasColorSetting) {
actual = captured.toString() + actual;
actual = actual
.replace(/\u001b\[[0-9;]*m/g, "")
.replace(/[.0-9]+(\s?ms)/g, "X$1")
Expand All @@ -119,6 +123,7 @@ describe("StatsTestCases", () => {
"$1 Thu Jan 01 1970 00:00:00 GMT"
);
} else {
actual = captured.toStringRaw() + actual;
actual = actual
.replace(/\u001b\[1m\u001b\[([0-9;]*)m/g, "<CLR=$1,BOLD>")
.replace(/\u001b\[1m/g, "<CLR=BOLD>")
Expand Down
40 changes: 32 additions & 8 deletions test/__snapshots__/StatsTestCases.test.js.snap
Expand Up @@ -1236,7 +1236,8 @@ Child 4 chunks:
`;

exports[`StatsTestCases should print correct stats for logging 1`] = `
"Hash: <CLR=BOLD>aa5b75cccf66cd9b1ffa</CLR>
"<i> <CLR=32,BOLD>[LogTestPlugin] Info</CLR>
Hash: <CLR=BOLD>aa5b75cccf66cd9b1ffa</CLR>
Time: <CLR=BOLD>X</CLR>ms
Built at: Thu Jan 01 1970 <CLR=BOLD>00:00:00</CLR> GMT
<CLR=BOLD>Asset</CLR> <CLR=BOLD>Size</CLR> <CLR=BOLD>Chunks</CLR> <CLR=39,BOLD><CLR=22> <CLR=39,BOLD><CLR=22><CLR=BOLD>Chunk Names</CLR>
Expand Down Expand Up @@ -1915,7 +1916,10 @@ chunk {6} preloaded3.js (preloaded3) 0 bytes <{2}> [rendered]"
`;

exports[`StatsTestCases should print correct stats for preset-detailed 1`] = `
"Hash: 2b293d5b94136dfe6d9c
"<e> [LogTestPlugin] Error
<w> [LogTestPlugin] Warning
<i> [LogTestPlugin] Info
Hash: 2b293d5b94136dfe6d9c
Time: Xms
Built at: Thu Jan 01 1970 00:00:00 GMT
Asset Size Chunks Chunk Names
Expand Down Expand Up @@ -1960,7 +1964,10 @@ LOG from LogTestPlugin
exports[`StatsTestCases should print correct stats for preset-errors-only 1`] = `""`;
exports[`StatsTestCases should print correct stats for preset-errors-only-error 1`] = `
"
"<e> [LogTestPlugin] Error
<w> [LogTestPlugin] Warning
<i> [LogTestPlugin] Info
LOG from LogTestPlugin
<e> Error
+ 11 hidden lines
Expand All @@ -1971,15 +1978,21 @@ 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`] = `
"
"<e> [LogTestPlugin] Error
<w> [LogTestPlugin] Warning
<i> [LogTestPlugin] Info
LOG from LogTestPlugin
<e> Error
<w> Warning
+ 10 hidden lines"
`;
exports[`StatsTestCases should print correct stats for preset-minimal 1`] = `
" 6 modules
"<e> [LogTestPlugin] Error
<w> [LogTestPlugin] Warning
<i> [LogTestPlugin] Info
6 modules
LOG from LogTestPlugin
<e> Error
Expand All @@ -1997,14 +2010,22 @@ Child verbose:
[0] ./index.js 8 bytes {0} [built]"
`;
exports[`StatsTestCases should print correct stats for preset-none 1`] = `""`;
exports[`StatsTestCases should print correct stats for preset-none 1`] = `
"<e> [LogTestPlugin] Error
<w> [LogTestPlugin] Warning
<i> [LogTestPlugin] Info
"
`;
exports[`StatsTestCases should print correct stats for preset-none-array 1`] = `""`;
exports[`StatsTestCases should print correct stats for preset-none-error 1`] = `""`;
exports[`StatsTestCases should print correct stats for preset-normal 1`] = `
"Hash: 2b293d5b94136dfe6d9c
"<e> [LogTestPlugin] Error
<w> [LogTestPlugin] Warning
<i> [LogTestPlugin] Info
Hash: 2b293d5b94136dfe6d9c
Time: Xms
Built at: Thu Jan 01 1970 00:00:00 GMT
Asset Size Chunks Chunk Names
Expand Down Expand Up @@ -2088,7 +2109,10 @@ Entrypoints:
`;

exports[`StatsTestCases should print correct stats for preset-verbose 1`] = `
"Hash: 2b293d5b94136dfe6d9c
"<e> [LogTestPlugin] Error
<w> [LogTestPlugin] Warning
<i> [LogTestPlugin] Info
Hash: 2b293d5b94136dfe6d9c
Time: Xms
Built at: Thu Jan 01 1970 00:00:00 GMT
Asset Size Chunks Chunk Names
Expand Down
1 change: 1 addition & 0 deletions test/helpers/LogTestPlugin.js
Expand Up @@ -19,6 +19,7 @@ module.exports = class LogTestPlugin {
logger.groupEnd();
logger.log("End");
};
logSome(compiler.getInfrastructureLogger("LogTestPlugin"));
compiler.hooks.compilation.tap("LogTestPlugin", compilation => {
const logger = compilation.getLogger("LogTestPlugin");
logSome(logger);
Expand Down

0 comments on commit 4c472ad

Please sign in to comment.