Skip to content

Commit d7bc5c1

Browse files
test: cover asset path normalization and exact hot update sets
1 parent 78f92f7 commit d7bc5c1

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

‎test/watchCases/clean/hot-update-slow-rebuild/0/index.js‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const fs = require("fs");
22

3-
const isUpdate = (name) => name.endsWith(".hot-update.json");
3+
const isUpdate = (name) => /\.hot-update\.js(on)?$/.test(name);
44

55
it("should rebuild on a module change", () => {
66
expect(require("./changing-module")).toBe(WATCH_STEP);
@@ -10,13 +10,15 @@ it("should keep the last update until a newer one is emitted", () => {
1010
const emitted = STATS_JSON.assets
1111
.map((asset) => asset.name)
1212
.filter(isUpdate);
13-
const older = fs
14-
.readdirSync(STATS_JSON.outputPath)
15-
.filter((name) => isUpdate(name) && !emitted.includes(name));
16-
expect(emitted).toHaveLength(WATCH_STEP === "0" ? 0 : 1);
13+
const previous = STATE.previousUpdates || [];
14+
const actual = fs.readdirSync(STATS_JSON.outputPath).filter(isUpdate);
15+
expect(emitted.some((name) => name.endsWith(".json"))).toBe(
16+
WATCH_STEP !== "0"
17+
);
1718
// step 3 starts more than 10 seconds after step 2 emitted its update,
1819
// which a client may still be about to request, so it has to be there
19-
expect(older).toHaveLength(WATCH_STEP === "0" || WATCH_STEP === "1" ? 0 : 1);
20+
expect(actual.sort()).toEqual([...emitted, ...previous].sort());
21+
STATE.previousUpdates = emitted;
2022
});
2123

2224
if (WATCH_STEP === "2") {

‎test/watchCases/clean/removed-assets/0/index.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ it("should keep only the extra asset of the current build", () => {
1414
expect(exists(`extra.${i}.txt`)).toBe(i === step);
1515
}
1616
});
17+
18+
it("should keep an asset whose name goes through a directory", () => {
19+
expect(exists("kept.txt")).toBe(true);
20+
});

‎test/watchCases/clean/removed-assets/webpack.config.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ module.exports = {
3232
`extra.${currentWatchStep.step}.txt`,
3333
new compiler.webpack.sources.RawSource("extra")
3434
);
35+
// written to `kept.txt`, so it has to be matched to that file
36+
compilation.emitAsset(
37+
"nested/../kept.txt",
38+
new compiler.webpack.sources.RawSource("kept")
39+
);
3540
});
3641
});
3742
compiler.hooks.afterEmit.tap("Test", (compilation) => {

0 commit comments

Comments
 (0)