-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Mark Wubben <mark@novemberborn.net>
- Loading branch information
1 parent
639b905
commit ffed948
Showing
5 changed files
with
88 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
8 changes: 8 additions & 0 deletions
8
test/shared-workers/multiple-workers-are-loaded/fixtures/package.json
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,8 @@ | ||
{ | ||
"type": "module", | ||
"ava": { | ||
"files": [ | ||
"*.js" | ||
] | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
test/shared-workers/multiple-workers-are-loaded/fixtures/test.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,30 @@ | ||
import test from 'ava'; | ||
import {registerSharedWorker} from 'ava/plugin'; | ||
|
||
const worker1 = registerSharedWorker({ | ||
filename: new URL('worker.mjs#1', import.meta.url), | ||
supportedProtocols: ['ava-4'], | ||
initialData: { | ||
id: '1', | ||
}, | ||
}); | ||
|
||
const worker2 = registerSharedWorker({ | ||
filename: new URL('worker.mjs#2', import.meta.url), | ||
supportedProtocols: ['ava-4'], | ||
initialData: { | ||
id: '2', | ||
}, | ||
}); | ||
|
||
const messageFromWorker1 = worker1.subscribe().next(); | ||
const messageFromWorker2 = worker2.subscribe().next(); | ||
|
||
test('can load multiple workers', async t => { | ||
const {value: {data: dataFromWorker1}} = await messageFromWorker1; | ||
const {value: {data: dataFromWorker2}} = await messageFromWorker2; | ||
|
||
t.deepEqual(dataFromWorker1, {id: '1'}); | ||
t.deepEqual(dataFromWorker2, {id: '2'}); | ||
t.pass(); | ||
}); |
9 changes: 9 additions & 0 deletions
9
test/shared-workers/multiple-workers-are-loaded/fixtures/worker.mjs
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,9 @@ | ||
export default async ({negotiateProtocol}) => { | ||
const protocol = negotiateProtocol(['ava-4']); | ||
|
||
await protocol.ready(); | ||
|
||
for await (const testWorker of protocol.testWorkers()) { | ||
testWorker.publish(protocol.initialData); | ||
} | ||
}; |
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,9 @@ | ||
import test from '@ava/test'; | ||
|
||
import {fixture} from '../../helpers/exec.js'; | ||
|
||
test('can load multiple workers', async t => { | ||
await fixture(); | ||
|
||
t.pass(); | ||
}); |