Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13450 from webpack/test/hmr-move-between-runtime
add test case for moving modules and chunks between runtimes
- Loading branch information
Showing
14 changed files
with
157 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default "chunk"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default "chunkS"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const update = () => | ||
new Promise((resolve, reject) => { | ||
NEXT(err => { | ||
if (err) reject(err); | ||
else resolve(); | ||
}); | ||
}); | ||
|
||
const expectMessage = (w, msg) => | ||
new Promise((resolve, reject) => { | ||
w.onmessage = ({ data }) => { | ||
if (data === msg) resolve(); | ||
else reject(new Error(data)); | ||
}; | ||
}); | ||
|
||
const next = w => { | ||
const p = expectMessage(w, "next"); | ||
w.postMessage("next"); | ||
return p; | ||
}; | ||
|
||
it("should support hot module replacement in WebWorkers", async () => { | ||
const a = new Worker(new URL("workerA.js", import.meta.url)); | ||
const b = new Worker(new URL("workerB.js", import.meta.url)); | ||
for (let i = 0; i < 7; i++) { | ||
await update(); | ||
await next(a); | ||
await next(b); | ||
} | ||
await a.terminate(); | ||
await b.terminate(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default "module"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export default 0; | ||
--- | ||
export default 1; | ||
import "./module"; | ||
--- | ||
export default 2; | ||
import "./module"; | ||
--- | ||
export default 3; | ||
--- | ||
export default 4; | ||
if (Math.random() < 0) import("./chunk"); | ||
--- | ||
export default 5; | ||
if (Math.random() < 0) import("./chunk"); | ||
--- | ||
export default 6; | ||
--- | ||
export default 7; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export default 0; | ||
--- | ||
export default 1; | ||
import "./moduleS"; | ||
--- | ||
export default 2; | ||
import "./moduleS"; | ||
--- | ||
export default 3; | ||
--- | ||
export default 4; | ||
if (Math.random() < 0) import("./chunkS"); | ||
--- | ||
export default 5; | ||
if (Math.random() < 0) import("./chunkS"); | ||
--- | ||
export default 6; | ||
--- | ||
export default 7; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export default 0; | ||
--- | ||
export default 1; | ||
--- | ||
export default 2; | ||
import "./module"; | ||
--- | ||
export default 3; | ||
import "./module"; | ||
--- | ||
export default 4; | ||
--- | ||
export default 5; | ||
if (Math.random() < 0) import("./chunk"); | ||
--- | ||
export default 6; | ||
if (Math.random() < 0) import("./chunk"); | ||
--- | ||
export default 7; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export default 0; | ||
--- | ||
export default 1; | ||
--- | ||
export default 2; | ||
import "./moduleS"; | ||
--- | ||
export default 3; | ||
import "./moduleS"; | ||
--- | ||
export default 4; | ||
--- | ||
export default 5; | ||
if (Math.random() < 0) import("./chunkS"); | ||
--- | ||
export default 6; | ||
if (Math.random() < 0) import("./chunkS"); | ||
--- | ||
export default 7; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default "moduleS"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
var supportsWorker = require("../../../helpers/supportsWorker"); | ||
|
||
module.exports = function (config) { | ||
return supportsWorker(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export default fn => { | ||
self.onmessage = async ({ data: msg }) => { | ||
try { | ||
switch (msg) { | ||
case "next": | ||
if (!(await import.meta.webpackHot.check(true))) | ||
throw new Error("No update found"); | ||
await fn(); | ||
self.postMessage("next"); | ||
break; | ||
default: | ||
throw new Error("Unexpected message"); | ||
} | ||
} catch (e) { | ||
self.postMessage("error: " + e.stack); | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import worker from "./worker"; | ||
import "./moduleA"; | ||
worker(() => import(/* webpackChunkName: "shared" */ "./moduleAs")); | ||
import.meta.webpackHot.accept("./moduleA"); | ||
import.meta.webpackHot.accept("./moduleAs"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import worker from "./worker"; | ||
import "./moduleB"; | ||
worker(() => import(/* webpackChunkName: "shared" */ "./moduleBs")); | ||
import.meta.webpackHot.accept("./moduleB"); | ||
import.meta.webpackHot.accept("./moduleBs"); |