-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0251283
commit b5db617
Showing
2 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
packages/bridge-ui/scripts/setupTestEnvironmentCompatibility.ts
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,29 @@ | ||
// Source: https://github.com/vitest-dev/vitest/issues/4043#issuecomment-1905172846 | ||
|
||
// This file is needed in order to support Uint8Array with vitest and jsdom. | ||
if (process.env.VITEST === 'true') { | ||
class ESBuildAndJSDOMCompatibleTextEncoder extends TextEncoder { | ||
constructor() { | ||
super(); | ||
} | ||
|
||
encode(input: string) { | ||
if (typeof input !== 'string') { | ||
throw new TypeError('`input` must be a string'); | ||
} | ||
|
||
const decodedURI = decodeURIComponent(encodeURIComponent(input)); | ||
const arr = new Uint8Array(decodedURI.length); | ||
const chars = decodedURI.split(''); | ||
for (let i = 0; i < chars.length; i++) { | ||
arr[i] = decodedURI[i].charCodeAt(0); | ||
} | ||
return arr; | ||
} | ||
} | ||
|
||
Object.defineProperty(global, 'TextEncoder', { | ||
value: ESBuildAndJSDOMCompatibleTextEncoder, | ||
writable: true, | ||
}); | ||
} |
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