Skip to content

Commit 745ba27

Browse files
test(watch): cover pending close and entry rebuilds (#22435)
* test(watch): cover pending close and entry rebuilds Extract close, entry context and MultiCompiler watch cases from feat/incremental-make. Refs #21556. * test(watch): rewrite fixture files so Windows sees the change copyFileSync keeps the source mtime on Windows, so the watcher never noticed the update and close-pending timed out. * test(css): re-resolve a WebKit style difference before re-reading it WebKit kept Beer CSS's root <div> resolved with nothing inherited through renders of both frames, failing syntax-equivalence (webkit). Each re-read now dirties the element with an inline custom property first. Claude-Session: https://claude.ai/code/session_01Dp9zrcrMNKB7SPShAVzh4G * test(css): restore the style attribute a WebKit re-read dirties Leaving the dirtying custom property set added a `style` attribute, so a `[style]` selector could hide a real difference on the re-read. Claude-Session: https://claude.ai/code/session_01Dp9zrcrMNKB7SPShAVzh4G --------- Co-authored-by: alexander-akait <[email protected]>
1 parent 8eb4eb6 commit 745ba27

21 files changed

Lines changed: 317 additions & 2 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
"use strict";
2+
3+
const assert = require("assert");
4+
const { NormalModule } = require("../..");
5+
6+
/** @import { Compiler, LoaderContext } from "../../" */
7+
/** @typedef {(error: Error | null, source?: string) => void} LoaderCallback */
8+
/** @typedef {LoaderContext<Record<string, never>> & { watchTestBarrier?: (source: string, callback: LoaderCallback) => void }} BarrierLoaderContext */
9+
10+
/**
11+
* Pauses the next watch loader after it has read its source.
12+
* @returns {{ plugin: (compiler: Compiler) => void, arm: () => Promise<void>, release: () => void }} loader barrier
13+
*/
14+
const createWatchLoaderBarrier = () => {
15+
/** @type {(() => void) | undefined} */
16+
let reached;
17+
/** @type {(() => void) | undefined} */
18+
let resume;
19+
return {
20+
/**
21+
* @param {Compiler} compiler watched compiler
22+
* @returns {void}
23+
*/
24+
plugin(compiler) {
25+
compiler.hooks.compilation.tap("WatchLoaderBarrier", (compilation) => {
26+
if (!compiler.watchMode) return;
27+
NormalModule.getCompilationHooks(compilation).loader.tap(
28+
"WatchLoaderBarrier",
29+
(loaderContext) => {
30+
/** @type {BarrierLoaderContext} */ (
31+
loaderContext
32+
).watchTestBarrier = (source, callback) => {
33+
if (!reached) return callback(null, source);
34+
resume = () => callback(null, source);
35+
const notify = reached;
36+
reached = undefined;
37+
notify();
38+
};
39+
}
40+
);
41+
});
42+
},
43+
/**
44+
* @returns {Promise<void>} resolves when the next loader is paused
45+
*/
46+
arm() {
47+
assert(!reached && !resume, "A loader barrier is already armed");
48+
return new Promise((resolve, reject) => {
49+
const timeout = setTimeout(() => {
50+
reached = undefined;
51+
reject(new Error("Timed out waiting for the watch loader"));
52+
}, 10000);
53+
reached = () => {
54+
clearTimeout(timeout);
55+
resolve();
56+
};
57+
});
58+
},
59+
/**
60+
* @returns {void}
61+
*/
62+
release() {
63+
const callback = resume;
64+
resume = undefined;
65+
if (callback) callback();
66+
}
67+
};
68+
};
69+
70+
module.exports = createWatchLoaderBarrier;

‎test/helpers/syntaxEquivalence.js‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,9 +2382,20 @@ const compareStyles = async ({ pairs, types }) => {
23822382
// WHY: WebKit can hand back one element's style resolved with nothing
23832383
// inherited — Beer CSS's root `<div>` read every default in one frame
23842384
// once, with a box in both and its own children inheriting fine. That is
2385-
// a stale read, not the cascade, so a difference counts only once it
2386-
// survives renders of both frames; a sheet's real one reads the same.
2385+
// a stale read, not the cascade, and renders alone keep it (seen in CI):
2386+
// nothing marks the element dirty. So each re-read first dirties it by
2387+
// setting a custom property and restoring its exact `style` attribute,
2388+
// leaving `[style]` selectors as they were; a sheet's difference survives.
23872389
for (let retry = 0; retry < 2 && found.length > 0; retry++) {
2390+
for (const { i } of found) {
2391+
for (const list of read) {
2392+
const element = /** @type {HTMLElement} */ (list[i]);
2393+
const original = element.getAttribute("style");
2394+
element.style.setProperty("--eq-dirty", String(retry));
2395+
if (original === null) element.removeAttribute("style");
2396+
else element.setAttribute("style", original);
2397+
}
2398+
}
23882399
await settleFrames();
23892400
found = found.filter((entry) => {
23902401
const changed = differ(
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const value = 1;
2+
3+
it("should rebuild an entry registered with its own context", () => {
4+
expect(value).toBe(WATCH_STEP === "0" ? 1 : 2);
5+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const value = 2;
2+
3+
it("should rebuild an entry registered with its own context", () => {
4+
expect(value).toBe(WATCH_STEP === "0" ? 1 : 2);
5+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"use strict";
2+
3+
/**
4+
* @param {string} source source
5+
* @returns {string} source
6+
*/
7+
module.exports = (source) => source;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use strict";
2+
3+
module.exports = {
4+
findBundle: () => "./bundle.js"
5+
};
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"use strict";
2+
3+
const path = require("path");
4+
const { EntryPlugin } = require("../../../../");
5+
const EntryDependency = require("../../../../lib/entry/EntryDependency");
6+
7+
const PLUGIN_NAME = "EntryCustomContextTest";
8+
9+
/**
10+
* Registers a fresh entry dependency with its own context on every make.
11+
* @param {import("../../../../").Compiler} compiler compiler
12+
* @returns {void}
13+
*/
14+
const addEntryWithOwnContext = (compiler) => {
15+
const context = path.resolve(compiler.context, "lib");
16+
17+
compiler.hooks.compilation.tap(
18+
PLUGIN_NAME,
19+
(compilation, { normalModuleFactory }) => {
20+
compilation.dependencyFactories.set(
21+
/** @type {Parameters<typeof compilation.dependencyFactories.set>[0]} */
22+
(/** @type {unknown} */ (EntryDependency)),
23+
normalModuleFactory
24+
);
25+
}
26+
);
27+
compiler.hooks.make.tapAsync(PLUGIN_NAME, (compilation, callback) => {
28+
compilation.addEntry(
29+
context,
30+
EntryPlugin.createDependency("./index.js", { name: "main" }),
31+
{ name: "main" },
32+
(err) => callback(err)
33+
);
34+
});
35+
};
36+
37+
/** @type {import("../../../../").Configuration} */
38+
module.exports = {
39+
mode: "development",
40+
entry: {},
41+
output: {
42+
filename: "bundle.js"
43+
},
44+
module: {
45+
rules: [
46+
{
47+
test: /index\.js$/,
48+
use: path.resolve(__dirname, "loader.js")
49+
}
50+
]
51+
},
52+
plugins: [addEntryWithOwnContext]
53+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
it("should close once with a blocked loader and a pending invalidation", async () => {
2+
expect(require("./value")).toBe(0);
3+
await CLOSE_PENDING();
4+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 2;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 1;

0 commit comments

Comments
 (0)