-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change Worker from inherit to member (#2)
* Change Worker from inherit to member * Add tests
- Loading branch information
1 parent
e122e5f
commit e47333b
Showing
4 changed files
with
31 additions
and
6 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
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 |
---|---|---|
@@ -1,19 +1,19 @@ | ||
import AdderWorker from 'worker:./workers/Adder.worker.ts'; | ||
|
||
describe('Test', () => | ||
describe('JestTransform', () => | ||
{ | ||
it('should work', async () => | ||
new Promise<void>((resolve) => | ||
{ | ||
const worker = new AdderWorker(); | ||
|
||
worker.onmessage = (event) => | ||
worker.worker.onmessage = (event) => | ||
{ | ||
expect(event.data).toBe(2); | ||
resolve(); | ||
}; | ||
|
||
worker.postMessage({ a: 1, b: 1 }); | ||
worker.worker.postMessage({ a: 1, b: 1 }); | ||
}) | ||
); | ||
}); |
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,23 @@ | ||
import AdderWorker from 'worker:./workers/Adder.worker.ts'; | ||
|
||
describe('NoWorker', () => | ||
{ | ||
let savedWorker: typeof Worker; | ||
|
||
beforeAll(() => | ||
{ | ||
savedWorker = globalThis.Worker; | ||
// @ts-expect-error: remove Worker | ||
delete globalThis.Worker; | ||
}); | ||
afterAll(() => | ||
{ | ||
globalThis.Worker = savedWorker; | ||
}); | ||
|
||
it('should throw if no Worker', () => | ||
{ | ||
expect(() => new AdderWorker()).toThrow(ReferenceError); | ||
} | ||
); | ||
}); |
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