From 4c472adbf1ff080d367734e81c44fb99db664fd8 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Wed, 31 Jul 2019 17:29:21 +0200 Subject: [PATCH] capture infrastructure log --- test/StatsTestCases.test.js | 5 +++ .../__snapshots__/StatsTestCases.test.js.snap | 40 +++++++++++++++---- test/helpers/LogTestPlugin.js | 1 + 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/test/StatsTestCases.test.js b/test/StatsTestCases.test.js index 4ab83467937..80e3c549874 100644 --- a/test/StatsTestCases.test.js +++ b/test/StatsTestCases.test.js @@ -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 @@ -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; @@ -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") @@ -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, "") .replace(/\u001b\[1m/g, "") diff --git a/test/__snapshots__/StatsTestCases.test.js.snap b/test/__snapshots__/StatsTestCases.test.js.snap index f777c5f7469..8c43cd8efb4 100644 --- a/test/__snapshots__/StatsTestCases.test.js.snap +++ b/test/__snapshots__/StatsTestCases.test.js.snap @@ -1236,7 +1236,8 @@ Child 4 chunks: `; exports[`StatsTestCases should print correct stats for logging 1`] = ` -"Hash: aa5b75cccf66cd9b1ffa +" [LogTestPlugin] Info +Hash: aa5b75cccf66cd9b1ffa Time: Xms Built at: Thu Jan 01 1970 00:00:00 GMT Asset Size Chunks Chunk Names @@ -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 +" [LogTestPlugin] Error + [LogTestPlugin] Warning + [LogTestPlugin] Info +Hash: 2b293d5b94136dfe6d9c Time: Xms Built at: Thu Jan 01 1970 00:00:00 GMT Asset Size Chunks Chunk Names @@ -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`] = ` -" +" [LogTestPlugin] Error + [LogTestPlugin] Warning + [LogTestPlugin] Info + LOG from LogTestPlugin Error + 11 hidden lines @@ -1971,7 +1978,10 @@ 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`] = ` -" +" [LogTestPlugin] Error + [LogTestPlugin] Warning + [LogTestPlugin] Info + LOG from LogTestPlugin Error Warning @@ -1979,7 +1989,10 @@ LOG from LogTestPlugin `; exports[`StatsTestCases should print correct stats for preset-minimal 1`] = ` -" 6 modules +" [LogTestPlugin] Error + [LogTestPlugin] Warning + [LogTestPlugin] Info + 6 modules LOG from LogTestPlugin Error @@ -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`] = ` +" [LogTestPlugin] Error + [LogTestPlugin] Warning + [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 +" [LogTestPlugin] Error + [LogTestPlugin] Warning + [LogTestPlugin] Info +Hash: 2b293d5b94136dfe6d9c Time: Xms Built at: Thu Jan 01 1970 00:00:00 GMT Asset Size Chunks Chunk Names @@ -2088,7 +2109,10 @@ Entrypoints: `; exports[`StatsTestCases should print correct stats for preset-verbose 1`] = ` -"Hash: 2b293d5b94136dfe6d9c +" [LogTestPlugin] Error + [LogTestPlugin] Warning + [LogTestPlugin] Info +Hash: 2b293d5b94136dfe6d9c Time: Xms Built at: Thu Jan 01 1970 00:00:00 GMT Asset Size Chunks Chunk Names diff --git a/test/helpers/LogTestPlugin.js b/test/helpers/LogTestPlugin.js index 0e1a1c321fa..3849e104696 100644 --- a/test/helpers/LogTestPlugin.js +++ b/test/helpers/LogTestPlugin.js @@ -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);