Skip to content

Commit

Permalink
merge testsetup
Browse files Browse the repository at this point in the history
  • Loading branch information
KorbinianK committed May 1, 2024
1 parent b5db617 commit ebdd08c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
29 changes: 0 additions & 29 deletions packages/bridge-ui/scripts/setupTestEnvironmentCompatibility.ts

This file was deleted.

29 changes: 29 additions & 0 deletions packages/bridge-ui/src/tests/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,32 @@ import dotenv from 'dotenv';
dotenv.config({ path: './.env.test' });

vi.mock('@wagmi/core');

// Source: https://github.com/vitest-dev/vitest/issues/4043#issuecomment-1905172846
// This snippet 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,
});
}
2 changes: 1 addition & 1 deletion packages/bridge-ui/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default defineProject({
test: {
environment: 'jsdom',
// setupFiles: ['./../../setup.ts'],
setupFiles: ['./scripts/setupTestEnvironmentCompatibility.ts', './src/tests/setup.ts'],
setupFiles: ['./src/tests/setup.ts'],
globals: true,
include: ['./**/*.{test,spec}.{js,ts}'],
},
Expand Down

0 comments on commit ebdd08c

Please sign in to comment.