Commit fd6ec21c authored by Tobias Koppers's avatar Tobias Koppers

Add snapshot test for module SharedWorker (type: 'module')

Verifies that new SharedWorker(url, { type: 'module' }) correctly
generates an ESM bootstrap (using import() instead of importScripts)
and ESM-format chunks. The 'esm' modifier in the module name confirms
is_esm=true is detected from the { type: 'module' } options.
Co-Authored-By: 's avatarClaude <noreply@anthropic.com>
parent 723b92b6
const url = new URL('./worker.js', import.meta.url)
new SharedWorker(url, { type: 'module' })
{
"runtime": "Browser",
"runtimeType": "Development",
"minifyType": "NoMinify",
"environment": "Browser"
}
export default [
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/workers/module_shared/input/worker.js [test] (ecmascript)", ((__turbopack_context__, module, exports) => {
self.onconnect = (e)=>e.ports[0].postMessage('hello');
}),
];
//# sourceMappingURL=0_9x_turbopack-tests_tests_snapshot_workers_module_shared_input_worker_0_x4a-b.js.map
\ No newline at end of file
{
"version": 3,
"sources": [],
"sections": [
{"offset": {"line": 3, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/workers/module_shared/input/worker.js"],"sourcesContent":["self.onconnect = (e) => e.ports[0].postMessage('hello')\n"],"names":["self","onconnect","e","ports","postMessage"],"mappings":"AAAAA,KAAKC,SAAS,GAAG,CAACC,IAAMA,EAAEC,KAAK,CAAC,EAAE,CAACC,WAAW,CAAC"}}]
}
\ No newline at end of file
function abort(message) {
console.error(message);
throw new Error(message);
}
if (
typeof self["WorkerGlobalScope"] === "undefined" ||
!(self instanceof self["WorkerGlobalScope"])
) {
abort("Worker entrypoint must be loaded in a worker context");
}
// Try querystring first (SharedWorker), then hash (regular Worker)
var url = new URL(location.href);
var paramsString = url.searchParams.get("params");
if (!paramsString && url.hash.startsWith("#params=")) {
paramsString = decodeURIComponent(url.hash.slice("#params=".length));
}
if (!paramsString) abort("Missing worker bootstrap config");
var params = JSON.parse(paramsString);
var param = (n) => typeof params[n] === 'string' ? params[n] : '';
var chunkUrls = Array.isArray(params[0]) ? params[0] : [];
Object.assign(self, {
TURBOPACK_NEXT_CHUNK_URLS: chunkUrls,
TURBOPACK_ASSET_SUFFIX: param(1)
});
await Promise.all(chunkUrls.map(function(chunk) {
var chunkUrl = new URL(chunk, location.origin);
if (chunkUrl.origin !== location.origin) {
abort("Refusing to load script from foreign origin: " + chunkUrl.origin);
}
return import(chunkUrl.toString());
}));
\ No newline at end of file
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push(["output/1do3_crates_turbopack-tests_tests_snapshot_workers_module_shared_input_0en4vkb._.js",
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/workers/module_shared/input/worker.js (static in ecmascript)", ((__turbopack_context__) => {
__turbopack_context__.q("/static/worker.1n36e5vaxakik.js");}),
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/workers/module_shared/input/worker.js [test] (ecmascript, worker loader, esm)", ((__turbopack_context__) => {
__turbopack_context__.v(function(Ctor, opts) {
return __turbopack_context__.b(Ctor, "output/0ley_crates_turbopack-tests_tests_snapshot_workers_module_shared_output_0-szzr7._.js", ["output/0_9x_turbopack-tests_tests_snapshot_workers_module_shared_input_worker_0_x4a-b.js","output/0rv8_turbopack-tests_tests_snapshot_workers_module_shared_input_worker_1468xbf.js"], opts);
});
}),
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/workers/module_shared/input/index.js [test] (ecmascript)", ((__turbopack_context__, module, exports) => {
var __TURBOPACK__import$2e$meta__ = {
get url () {
return `file://${__turbopack_context__.P("turbopack/crates/turbopack-tests/tests/snapshot/workers/module_shared/input/index.js")}`;
}
};
const url = new __turbopack_context__.U(__turbopack_context__.r("[project]/turbopack/crates/turbopack-tests/tests/snapshot/workers/module_shared/input/worker.js (static in ecmascript)"));
__turbopack_context__.r("[project]/turbopack/crates/turbopack-tests/tests/snapshot/workers/module_shared/input/worker.js [test] (ecmascript, worker loader, esm)")(SharedWorker, {
type: 'module'
});
}),
]);
//# sourceMappingURL=1do3_crates_turbopack-tests_tests_snapshot_workers_module_shared_input_0en4vkb._.js.map
\ No newline at end of file
{
"version": 3,
"sources": [],
"sections": [
{"offset": {"line": 12, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/workers/module_shared/input/index.js"],"sourcesContent":["const url = new URL('./worker.js', import.meta.url)\nnew SharedWorker(url, { type: 'module' })\n"],"names":["url","SharedWorker","type"],"mappings":";;;;;AAAA,MAAMA;AACN,mKAAIC,cAAkB;IAAEC,MAAM;AAAS"}}]
}
\ No newline at end of file
self.onconnect = (e) => e.ports[0].postMessage('hello')
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment