-
-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: simple custom worker syntax (#6899)
- Loading branch information
Showing
18 changed files
with
315 additions
and
37 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
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
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
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
24 changes: 24 additions & 0 deletions
24
packages/rspack-test-tools/tests/configCases/worker/custom-worker-call-syntax/index.js
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,24 @@ | ||
it("should allow to create a WebWorker", async () => { | ||
const worker = MyWorker(new URL("./worker.js", import.meta.url), { | ||
type: "module" | ||
}); | ||
worker.postMessage("ok"); | ||
const result = await new Promise(resolve => { | ||
worker.onmessage = event => { | ||
resolve(event.data); | ||
}; | ||
}); | ||
expect(result).toBe("data: OK, thanks"); | ||
await worker.terminate(); | ||
}); | ||
|
||
it("should allow to share chunks", async () => { | ||
const promise = import("./module"); | ||
const script = document.head._children[0]; | ||
const src = script.src; | ||
const file = src.slice(src.lastIndexOf("/")); | ||
__non_webpack_require__(`./${file}`); | ||
script.onload(); | ||
const { upper } = await promise; | ||
expect(upper("ok")).toBe("OK"); | ||
}); |
3 changes: 3 additions & 0 deletions
3
packages/rspack-test-tools/tests/configCases/worker/custom-worker-call-syntax/module.js
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,3 @@ | ||
export function upper(str) { | ||
return str.toUpperCase(); | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/rspack-test-tools/tests/configCases/worker/custom-worker-call-syntax/test.config.js
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,8 @@ | ||
module.exports = { | ||
findBundle: function(i, options) { | ||
return ["main.js"]; | ||
}, | ||
moduleScope(scope) { | ||
scope["MyWorker"] = (...args) => new scope.Worker(...args); | ||
}, | ||
}; |
17 changes: 17 additions & 0 deletions
17
...es/rspack-test-tools/tests/configCases/worker/custom-worker-call-syntax/webpack.config.js
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,17 @@ | ||
/** @type {import("@rspack/core").Configuration} */ | ||
module.exports = { | ||
output: { | ||
filename: "[name].js" | ||
}, | ||
target: "web", | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.[cm]?js$/, | ||
parser: { | ||
worker: ["MyWorker()", "..."] | ||
} | ||
} | ||
] | ||
} | ||
}; |
4 changes: 4 additions & 0 deletions
4
packages/rspack-test-tools/tests/configCases/worker/custom-worker-call-syntax/worker.js
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,4 @@ | ||
onmessage = async event => { | ||
const { upper } = await import("./module"); | ||
postMessage(`data: ${upper(event.data)}, thanks`); | ||
}; |
Oops, something went wrong.
9284d3f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Ran ecosystem CI: Open
9284d3f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Benchmark detail: Open