Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 37 additions & 32 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,59 @@
import { webcrypto } from 'crypto';
import { TextDecoder, TextEncoder } from 'util';
import '@testing-library/jest-dom';
import './src/i18n/config';
import { installIndexedDBMock } from './test-utils/indexeddb-mock';

// Polyfill crypto.subtle and TextEncoder/TextDecoder for jsdom
if (typeof globalThis.crypto !== 'undefined' && !globalThis.crypto.subtle) {
const { webcrypto } = require('crypto');
Object.defineProperty(globalThis, 'crypto', {
value: webcrypto,
writable: false,
configurable: true,
});
}
const { TextEncoder, TextDecoder } = require('util');
// jsdom does not provide TextEncoder/TextDecoder globally; back them with Node's.
if (typeof globalThis.TextEncoder === 'undefined') {
globalThis.TextEncoder = TextEncoder;
}
if (typeof globalThis.TextDecoder === 'undefined') {
globalThis.TextDecoder = TextDecoder;
}

// jsdom does not implement the Web Crypto SubtleCrypto API; back it with Node's
// webcrypto so code paths that encrypt/decrypt (e.g. session storage) work.
if (typeof globalThis.crypto === 'undefined') {
Object.defineProperty(globalThis, 'crypto', { value: webcrypto, configurable: true });
} else if (!globalThis.crypto.subtle) {
try {
Object.defineProperty(globalThis.crypto, 'subtle', { value: webcrypto.subtle, configurable: true });
} catch {
Object.defineProperty(globalThis, 'crypto', { value: webcrypto, configurable: true });
}
}

// Mock File System Access API (showSaveFilePicker)
if (typeof globalThis.window === 'undefined') {
// running in node - provide a minimal window and document
globalThis.window = globalThis;
// running in node - provide a minimal window and document
globalThis.window = globalThis;
}

if (!('showSaveFilePicker' in globalThis)) {
globalThis.showSaveFilePicker = async (options = {}) => {
const chunks = [];
return {
createWritable: async () => ({
write: async (data) => {
// accept Blob or write request
if (data instanceof Blob) {
const array = new Uint8Array(await data.arrayBuffer());
chunks.push(array);
} else if (data && data.data instanceof Blob) {
const array = new Uint8Array(await data.data.arrayBuffer());
chunks.push(array);
}
},
close: async () => {},
}),
};
};
globalThis.showSaveFilePicker = async (options = {}) => {
const chunks = [];
return {
createWritable: async () => ({
write: async (data) => {
// accept Blob or write request
if (data instanceof Blob) {
const array = new Uint8Array(await data.arrayBuffer());
chunks.push(array);
} else if (data && data.data instanceof Blob) {
const array = new Uint8Array(await data.data.arrayBuffer());
chunks.push(array);
}
},
close: async () => {},
}),
};
};
}

// Install enhanced IndexedDB mock for tests
try {
installIndexedDBMock();
installIndexedDBMock();
} catch (e) {
// ignore if already installed or environment prevents it
// ignore if already installed or environment prevents it
}
18 changes: 3 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@dnd-kit/core": "^6.3.1",
"@dnd-kit/sortable": "^10.0.0",
"@dnd-kit/utilities": "^3.2.2",
"@next/swc-win32-x64-msvc": "^14.2.4",
"@stellar/freighter-api": "^6.0.1",
"@stellar/stellar-sdk": "^11.3.0",
"clsx": "^2.1.1",
Expand Down Expand Up @@ -59,5 +60,8 @@
"postcss": "^8.4.38",
"tailwindcss": "^3.4.4",
"typescript": "^5.4.5"
},
"optionalDependencies": {
"@next/swc-win32-x64-msvc": "^14.2.4"
}
}
Loading
Loading