Skip to content

Commit

Permalink
test: add new worker
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Aug 6, 2024
1 parent f316326 commit 70c746c
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ playground/html/invalid.html
playground/html/valid.html
playground/external/public/[email protected]
playground/ssr-html/public/[email protected]
playground/worker/classic-worker.js
playground/worker/classic-iife.js
5 changes: 5 additions & 0 deletions playground/worker/__tests__/es/worker-es.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ test('classic worker', async () => {
'A classic',
true,
)
await untilUpdated(
() => page.textContent('.classic-iife'),
'classic-iife',
true,
)
})

test('emit chunk', async () => {
Expand Down
5 changes: 5 additions & 0 deletions playground/worker/classic-iife.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(() => {
self.addEventListener('message', () => {
self.postMessage('classic-iife');
})
})()
2 changes: 0 additions & 2 deletions playground/worker/classic-worker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
(() => {})() // this is to test `importScripts` injection doesn't break the code

let base = `/${self.location.pathname.split('/')[1]}`
if (base.endsWith('.js') || base === `/worker-entries`) base = '' // for dev

Expand Down
1 change: 1 addition & 0 deletions playground/worker/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ <h2 class="format-iife">format iife:</h2>
</p>
<code class="classic-worker"></code>
<code class="classic-worker-import"></code>
<code class="classic-iife"></code>

<p>
new SharedWorker(new URL('./classic-shared-worker.js', import.meta.url), {
Expand Down
6 changes: 6 additions & 0 deletions playground/worker/worker/main-classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ classicSharedWorker.port.addEventListener('message', (ev) => {
text('.classic-shared-worker', JSON.stringify(ev.data))
})
classicSharedWorker.port.start()

const classicIife = new Worker(new URL('../classic-iife.js', import.meta.url))
classicIife.addEventListener('message', (e) => {
text('.classic-iife', e.data)
})
classicIife.postMessage('ping')

0 comments on commit 70c746c

Please sign in to comment.