Skip to content

Commit abf91be

Browse files
test: keep expected warnings and logs out of the test output (#22795)
* test: keep expected warnings and logs out of the test output Claude-Session: https://claude.ai/code/session_017TkBWTk3wcyUcJYDp5ZhaP * test: restore console.log after the mini-css-extract case even when it fails Claude-Session: https://claude.ai/code/session_017TkBWTk3wcyUcJYDp5ZhaP * test: close the compiler after a failed build so its cache does not store in the background A compiler left open after a fatal error still stored its filesystem cache once idle, racing the next compiler on the same cache directory ("Caching failed for pack: ENOENT ... rename"). Closing it exposed a crash in ResolverCachePlugin when a resolve finishes after close, which now returns the uncached result. Claude-Session: https://claude.ai/code/session_017TkBWTk3wcyUcJYDp5ZhaP * test: report an error from closing the compiler after a failed build Claude-Session: https://claude.ai/code/session_017TkBWTk3wcyUcJYDp5ZhaP * test: drop the trace-warnings hint after the import assertion warning Node prints the "(Use `node --trace-warnings ...`)" hint once, after the first warning of a process. The VM Modules warning used to be that one; with it filtered, the hint follows V8's `assert` deprecation instead and was left behind as an infrastructure error (interop-amd on Node.js 18). Claude-Session: https://claude.ai/code/session_017TkBWTk3wcyUcJYDp5ZhaP
1 parent f9d4992 commit abf91be

11 files changed

Lines changed: 136 additions & 17 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": patch
3+
---
4+
5+
Keep a resolve that ends after the compiler closed from throwing.

‎lib/cache/ResolverCachePlugin.js‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,20 @@ class ResolverCachePlugin {
256256
const fileDependencies = newResolveContext.fileDependencies;
257257
const contextDependencies = newResolveContext.contextDependencies;
258258
const missingDependencies = newResolveContext.missingDependencies;
259-
// Only reachable past the `!fileSystemInfo` guard on the resolve tap.
260-
const fsInfo = /** @type {FileSystemInfo} */ (fileSystemInfo);
261-
fsInfo.createSnapshot(
259+
const resolveResult = withYield ? yieldResult : result;
260+
// the compiler was closed while resolving, e.g. after a bailed build
261+
if (!fileSystemInfo) {
262+
if (withYield && result) {
263+
/** @type {ResolveRequest[]} */
264+
(yieldResult).push(result);
265+
}
266+
return callback(
267+
null,
268+
/** @type {ResolveRequest} */
269+
(resolveResult)
270+
);
271+
}
272+
fileSystemInfo.createSnapshot(
262273
resolveTime,
263274
/** @type {Dependencies} */
264275
(fileDependencies),
@@ -269,7 +280,6 @@ class ResolverCachePlugin {
269280
snapshotOptions,
270281
(err, snapshot) => {
271282
if (err) return callback(err);
272-
const resolveResult = withYield ? yieldResult : result;
273283
// since we intercept resolve hook
274284
// we still can get result in callback
275285
if (withYield && result) {
@@ -445,7 +455,11 @@ class ResolverCachePlugin {
445455
const processCacheResult = (err, cacheEntry) => {
446456
if (err) return done(err);
447457

448-
if (cacheEntry && dependsOnChangedPath(cacheEntry.snapshot)) {
458+
// the compiler was closed while reading the cache
459+
if (
460+
cacheEntry &&
461+
(!fileSystemInfo || dependsOnChangedPath(cacheEntry.snapshot))
462+
) {
449463
cacheInvalidResolves++;
450464
return doRealResolve(
451465
itemCache,

‎test/harness/globalSetup.js‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55

66
"use strict";
77

8+
const path = require("path");
89
const { create } = require("../helpers/browserslistConfigPackages");
910

10-
module.exports = create;
11+
module.exports = () => {
12+
// Trust the self-signed certificate of the lazy-compilation https case, so
13+
// its client verifies it rather than turning verification off. Read when a
14+
// worker starts, so it has to be set here, before Jest spawns them.
15+
process.env.NODE_EXTRA_CA_CERTS = path.resolve(
16+
__dirname,
17+
"../hotCases/lazy-compilation/https/cert.pem"
18+
);
19+
20+
return create();
21+
};

‎test/harness/setupTestFramework.js‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,35 @@ if (process.env.DEBUG_INFO) {
139139
it = addDebugInfo(it);
140140
}
141141

142+
// parsing/asm-js holds "use asm" functions that are not valid asm.js on
143+
// purpose, and V8 reports each one it rejects on stderr. Run them as plain
144+
// JavaScript, as V8 does once it has rejected them.
145+
try {
146+
require("v8").setFlagsFromString("--no-validate-asm");
147+
} catch (_err) {
148+
// a runtime without V8 flags has no asm.js validation to report either
149+
}
150+
151+
// Experimental features the test runner enables on purpose; their warning on
152+
// every worker says nothing about the change under test.
153+
const realProcess = vm.runInThisContext("process");
154+
const originalEmitWarning = realProcess.emitWarning;
155+
// this file runs once per test file, while the process outlives them
156+
if (!originalEmitWarning.skipsKnownWarnings) {
157+
realProcess.emitWarning = function emitWarning(warning, ...args) {
158+
const type =
159+
typeof args[0] === "string" ? args[0] : args[0] && args[0].type;
160+
if (
161+
type === "ExperimentalWarning" &&
162+
/^(VM Modules|stripTypeScriptTypes) /.test(String(warning))
163+
) {
164+
return;
165+
}
166+
return originalEmitWarning.call(this, warning, ...args);
167+
};
168+
realProcess.emitWarning.skipsKnownWarnings = true;
169+
}
170+
142171
// cspell:word wabt
143172
// Workaround for a memory leak in wabt: it leaks an Error object on construction,
144173
// so it leaks the whole stack trace.

‎test/helpers/captureStdio.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module.exports = (
3333
)
3434
// Ignore deprecated `import * as pkg from "file.json" assert { type: "json" };`
3535
.replace(
36-
/\([^)]+\) (\[[^\]]+\]\s*)?(V8:).* 'assert' is deprecated in import statements and support will be removed in a future version; use 'with' instead\n/g,
36+
/\([^)]+\) (\[[^\]]+\]\s*)?(V8:).* 'assert' is deprecated in import statements and support will be removed in a future version; use 'with' instead\n(\(Use .node.+\)\n)?/g,
3737
""
3838
)
3939
// Babel's note on instrumenting a source over 500KB for coverage, written

‎test/hotCases/css/mini-css-extract/a.js‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,38 @@ const readStyles = () =>
66
"utf-8"
77
);
88

9+
const log = console.log;
10+
// restored even when the test fails or times out before it finishes
11+
afterEach(() => {
12+
console.log = log;
13+
});
14+
915
it("should apply a hot update to the extracted stylesheet", function (done) {
1016
expect(readStyles()).toContain("color: red;");
1117

18+
// mini-css-extract-plugin reports the reload on the console: check it there
19+
// rather than let it reach the test output
20+
const logs = [];
21+
console.log = (...args) => {
22+
logs.push(args.join(" "));
23+
};
24+
const finish = (err) => {
25+
console.log = log;
26+
done(err);
27+
};
28+
1229
NEXT(
13-
require("../../update")(done, true, () => {
30+
require("../../update")(finish, true, () => {
1431
expect(readStyles()).toContain("color: blue;");
15-
16-
done();
32+
// the plugin debounces the reload by 50ms
33+
setTimeout(() => {
34+
try {
35+
expect(logs.join("\n")).toContain("Reload all css");
36+
} catch (err) {
37+
return finish(err);
38+
}
39+
finish();
40+
}, 100);
1741
})
1842
);
1943
});

‎test/hotCases/lazy-compilation/https/index.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
// Avoid errors because of self-signed certificate
2-
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
1+
// Node.js trusts the self-signed certificate through NODE_EXTRA_CA_CERTS (see
2+
// test/harness/globalSetup.js); Bun and Deno need verification turned off
3+
if (process.versions.bun || process.versions.deno) {
4+
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
5+
}
36

47
it("should compile to lazy imported module", (done) => {
58
let resolved;

‎test/hotCases/universal/dev-server-client/index.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import "./quiet-log";
12
import value from "./module";
23
// universal regular-HMR client: works on web (dev-server EventSource signal)
34
// and Node (same emitter signal) without a platform-specific client
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// hot/dev-server logs every step at "info"; keep only warnings and errors so
2+
// the test output stays quiet. Imported first, before the client logs.
3+
require("../../../../hot/log").setLogLevel("warning");

‎test/templates/ConfigTestCases.js‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,22 @@ const describeCases = (config) => {
319319
setTimeout(done, 200);
320320
};
321321

322+
/**
323+
* Closes the compiler before reporting a failed build. Left open, its
324+
* filesystem cache still stores the pack once idle, after the test is
325+
* over and at the same time as the next compiler on the same cache
326+
* directory, and one store then renames a file away from the other.
327+
* @param {import("../../").Compiler} compiler compiler that failed
328+
* @param {Error} err the fatal error
329+
* @param {(err?: Error) => void} done done callback
330+
*/
331+
const closeAfterFatalError = (compiler, err, done) => {
332+
compiler.close((closeErr) => {
333+
if (closeErr) return done(closeErr);
334+
handleFatalError(err, done);
335+
});
336+
};
337+
322338
/**
323339
* Runs the compiler, reporting a synchronous throw from a hook
324340
* (e.g. a `compilation` tap) to the callback like a failed run.
@@ -350,7 +366,7 @@ const describeCases = (config) => {
350366

351367
runCompiler(compiler, (err) => {
352368
deprecationTracker();
353-
if (err) return handleFatalError(err, done);
369+
if (err) return closeAfterFatalError(compiler, err, done);
354370
// Check after close: the disk cache is stored during close,
355371
// so store failures (warnings) only surface afterwards.
356372
compiler.close((closeErr) => {
@@ -401,7 +417,11 @@ const describeCases = (config) => {
401417
runCompiler(compiler, (err, stats) => {
402418
deprecationTracker();
403419
if (err) {
404-
return handleFatalError(/** @type {Error} */ (err), done);
420+
return closeAfterFatalError(
421+
compiler,
422+
/** @type {Error} */ (err),
423+
done
424+
);
405425
}
406426
const { modules, children, errorsCount } =
407427
/** @type {import("../../").Stats} */ (stats).toJson({
@@ -690,7 +710,11 @@ const describeCases = (config) => {
690710

691711
compiler.run((err) => {
692712
if (err) {
693-
return handleFatalError(/** @type {Error} */ (err), done);
713+
return closeAfterFatalError(
714+
compiler,
715+
/** @type {Error} */ (err),
716+
done
717+
);
694718
}
695719
compiler.run((error, stats) => {
696720
compiler.close((err) => {

0 commit comments

Comments
 (0)