Skip to content

Commit 9b46fef

Browse files
committed
e2e: the library converts inside a Web Worker via the CDN recipe
The worker-mode guarantee for the playground lane: spawns a module Worker on a live page, imports interscript from the esm.sh pin documented in interscript-ts docs/CDN.md, converts bgnpcgn-ukr through the ISC strategy, and asserts the output - proving both the worker context and the CDN recipe on every CI run. Verified locally: 1 passed.
1 parent bcce441 commit 9b46fef

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

e2e/worker-engine.spec.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Worker-mode guarantee: the package runs inside a Web Worker — the
3+
* architecture every browser runtime entry point uses to keep
4+
* conversions off the main thread. Imports via the CDN recipe pinned
5+
* in interscript-ts/docs/CDN.md, so each CI run re-proves that recipe
6+
* too.
7+
*/
8+
import { test, expect } from "@playwright/test"
9+
10+
const CDN = "https://esm.sh/interscript@5.3.0"
11+
12+
const WORKER_SOURCE = `
13+
self.onmessage = async (event) => {
14+
try {
15+
const { configure, iscStrategy, transliterateAsync } = await import("${CDN}")
16+
configure({
17+
strategies: [iscStrategy({ baseUrl: "https://interscript.org/maps" })],
18+
})
19+
const output = await transliterateAsync("bgnpcgn-ukr-Cyrl-Latn-2019", event.data)
20+
self.postMessage({ ok: true, output })
21+
} catch (error) {
22+
self.postMessage({ ok: false, error: String(error) })
23+
}
24+
}
25+
`
26+
27+
test("the library converts inside a Web Worker via the CDN recipe", async ({ page }) => {
28+
await page.goto("/")
29+
const result = await page.evaluate(
30+
async ({ source, input }) => {
31+
const url = URL.createObjectURL(new Blob([source], { type: "text/javascript" }))
32+
const worker = new Worker(url, { type: "module" })
33+
try {
34+
return await new Promise((resolve) => {
35+
worker.onmessage = (event) => resolve(event.data)
36+
worker.postMessage(input)
37+
})
38+
} finally {
39+
worker.terminate()
40+
URL.revokeObjectURL(url)
41+
}
42+
},
43+
{ source: WORKER_SOURCE, input: "Антон Олегович" },
44+
)
45+
expect(result.ok).toBe(true)
46+
expect(result.output).toBe("Anton Olehovych")
47+
})

0 commit comments

Comments
 (0)