-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: worklet detection in production mode
- Loading branch information
Showing
8 changed files
with
85 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
let audioContext = null; | ||
|
||
it("should allow to create a paintWorklet worklet", async () => { | ||
if (audioContext === null) { | ||
audioContext = new AudioContext(); | ||
} | ||
|
||
let pseudoWorklet = await audioContext.audioWorklet.addModule(new URL("./worklet.js", import.meta.url)); | ||
|
||
pseudoWorklet = new pseudoWorklet(); | ||
|
||
expect(pseudoWorklet.url).not.toContain("asset-"); | ||
|
||
pseudoWorklet.postMessage("ok"); | ||
|
||
const result = await new Promise(resolve => { | ||
pseudoWorklet.onmessage = event => { | ||
resolve(event.data); | ||
}; | ||
}); | ||
expect(result).toBe("data: OK, thanks"); | ||
|
||
await pseudoWorklet.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,3 @@ | ||
export function upper(str) { | ||
return str.toUpperCase(); | ||
} |
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,22 @@ | ||
let outputDirectory; | ||
|
||
module.exports = { | ||
moduleScope(scope) { | ||
const FakeWorker = require("../../../helpers/createFakeWorker")({ | ||
outputDirectory | ||
}); | ||
|
||
// Pseudo code | ||
scope.AudioContext = class AudioContext { | ||
constructor() { | ||
this.audioWorklet = { | ||
addModule: url => Promise.resolve(FakeWorker.bind(null, url)) | ||
}; | ||
} | ||
}; | ||
}, | ||
findBundle: function (i, options) { | ||
outputDirectory = options.output.path; | ||
return ["main.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 @@ | ||
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,20 @@ | ||
/** @type {import("../../../../").Configuration} */ | ||
module.exports = { | ||
output: { | ||
filename: "[name].js" | ||
}, | ||
optimization: { | ||
innerGraph: true | ||
}, | ||
target: "web", | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.[cm]?js$/, | ||
parser: { | ||
worker: ["*audioContext.audioWorklet.addModule()", "..."] | ||
} | ||
} | ||
] | ||
} | ||
}; |
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`); | ||
}; |