-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(web-worker): don't rely on browser API when it's not provided (#4014
- Loading branch information
1 parent
bf83936
commit e78a449
Showing
6 changed files
with
47 additions
and
34 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
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// @vitest-environment jsdom | ||
|
||
import { expect, it } from 'vitest' | ||
|
||
it('worker with invalid url throws an error', async () => { | ||
const url = import.meta.url | ||
const worker = new Worker(new URL('../src/workerInvalid-path.ts', url)) | ||
const event = await new Promise<ErrorEvent>((resolve) => { | ||
worker.onerror = (e) => { | ||
resolve(e) | ||
} | ||
}) | ||
expect(event).toBeInstanceOf(ErrorEvent) | ||
// Error is in different context when running in VM. This is consistent with jest. | ||
if (!import.meta.env.VITEST_VM_POOL) | ||
expect(event.error).toBeInstanceOf(Error) | ||
expect(event.error.message).toContain('Failed to load') | ||
}) | ||
|
||
it('throws an error on invalid path', async () => { | ||
expect(SharedWorker).toBeDefined() | ||
const worker = new SharedWorker('./some-invalid-path') | ||
const event = await new Promise<ErrorEvent>((resolve) => { | ||
worker.onerror = (e) => { | ||
resolve(e) | ||
} | ||
}) | ||
expect(event).toBeInstanceOf(ErrorEvent) | ||
// Error is in different context when running in VM. This is consistent with jest. | ||
if (!import.meta.env.VITEST_VM_POOL) | ||
expect(event.error).toBeInstanceOf(Error) | ||
expect(event.error.message).toContain('Failed to load') | ||
}) |
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