-
-
Notifications
You must be signed in to change notification settings - Fork 627
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: generate correct worker expression with trusted types (#8143)
- Loading branch information
1 parent
1c7a37c
commit ddd7eb9
Showing
6 changed files
with
125 additions
and
20 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
45 changes: 45 additions & 0 deletions
45
packages/rspack-test-tools/tests/configCases/trusted-types/web-worker/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,45 @@ | ||
const fs = __non_webpack_require__("fs"); | ||
const path = __non_webpack_require__("path"); | ||
|
||
|
||
function createWorker() { | ||
new Worker(new URL("./worker.js", import.meta.url), { | ||
type: "module" | ||
}); | ||
} | ||
|
||
createWorker; | ||
|
||
it("should generate correct new Worker statement", async () => { | ||
const content = fs.readFileSync(__filename, "utf-8"); | ||
const method = "__webpack_require__.tu"; | ||
expect(content).toContain(`new Worker(${method}(new URL(`) | ||
}); | ||
|
||
|
||
function createWorkerWithChunkName() { | ||
new Worker(/* webpackChunkName: "someChunkName" */new URL("./worker.js", import.meta.url)); | ||
} | ||
|
||
createWorkerWithChunkName | ||
|
||
it("should generate correct new Worker statement with magic comments", async () => { | ||
const content = fs.readFileSync(__filename, "utf-8"); | ||
const chunkName = "someChunkName"; | ||
expect(content).toContain(`new Worker(/* webpackChunkName: "${chunkName}" */__webpack_require__.tu(new URL(`) | ||
expect(fs.existsSync(path.join(__dirname, `${chunkName}.js`))).toBeTruthy(); | ||
}); | ||
|
||
|
||
function createWorkerWithChunkNameInnner() { | ||
new Worker(new URL(/* webpackChunkName: "someChunkName2" */ "./worker.js", import.meta.url)); | ||
} | ||
|
||
createWorkerWithChunkNameInnner | ||
|
||
it("should generate correct new Worker statement with magic comments", async () => { | ||
const content = fs.readFileSync(__filename, "utf-8"); | ||
const chunkName = "someChunkName2"; | ||
expect(content).toContain(`new Worker(__webpack_require__.tu(new URL(/* webpackChunkName: "${chunkName}" */`) | ||
expect(fs.existsSync(path.join(__dirname, `${chunkName}.js`))).toBeTruthy(); | ||
}); |
3 changes: 3 additions & 0 deletions
3
packages/rspack-test-tools/tests/configCases/trusted-types/web-worker/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(s) { | ||
return s.toUpperCase(); | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/rspack-test-tools/tests/configCases/trusted-types/web-worker/rspack.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,12 @@ | ||
module.exports = { | ||
output: { | ||
filename: "[name].js", | ||
chunkFilename: "[name].js", | ||
trustedTypes: true | ||
}, | ||
node: { | ||
__dirname: false, | ||
__filename: false | ||
}, | ||
target: "web" | ||
}; |
5 changes: 5 additions & 0 deletions
5
packages/rspack-test-tools/tests/configCases/trusted-types/web-worker/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,5 @@ | ||
module.exports = { | ||
findBundle: function (i, options) { | ||
return ["main.js"]; | ||
} | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/rspack-test-tools/tests/configCases/trusted-types/web-worker/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,3 @@ | ||
onmessage = async event => { | ||
postMessage(`data: ${event.data}, thanks`); | ||
}; |
ddd7eb9
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
ddd7eb9
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