- Update Jest config with module name mapping for uuid and node-fetch - Add Babel transform for mixed JS/TS support - Configure transformIgnorePatterns for ES modules - Add comprehensive test mocks for uuid and node-fetch - Setup import.meta environment variables for Jest compatibility - Increase test timeout to 30 seconds for integration tests
59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
// Test setup file
|
|
// Configure jsdom and global test utilities
|
|
|
|
import 'jest-environment-jsdom';
|
|
|
|
// Mock localStorage
|
|
const localStorageMock = {
|
|
getItem: jest.fn(),
|
|
setItem: jest.fn(),
|
|
removeItem: jest.fn(),
|
|
clear: jest.fn(),
|
|
length: 0,
|
|
key: jest.fn(),
|
|
} as Storage;
|
|
|
|
Object.defineProperty(window, 'localStorage', {
|
|
value: localStorageMock,
|
|
});
|
|
|
|
// Mock fetch
|
|
global.fetch = jest.fn();
|
|
|
|
// Mock import.meta for Jest
|
|
Object.defineProperty(globalThis, 'import', {
|
|
value: {
|
|
meta: {
|
|
env: {
|
|
NODE_ENV: 'test',
|
|
VITE_COUCHDB_URL: 'http://localhost:5984',
|
|
VITE_COUCHDB_USERNAME: 'admin',
|
|
VITE_COUCHDB_PASSWORD: 'password',
|
|
VITE_MAILGUN_API_KEY: 'test-key',
|
|
VITE_MAILGUN_DOMAIN: 'test.mailgun.org',
|
|
VITE_MAILGUN_BASE_URL: 'https://api.mailgun.net',
|
|
VITE_MAILGUN_FROM_NAME: 'Test App',
|
|
VITE_MAILGUN_FROM_EMAIL: 'test@example.com',
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
// Setup console to avoid noise in tests
|
|
const originalError = console.error;
|
|
beforeAll(() => {
|
|
console.error = (...args: unknown[]) => {
|
|
if (
|
|
typeof args[0] === 'string' &&
|
|
args[0].includes('Warning: ReactDOM.render is deprecated')
|
|
) {
|
|
return;
|
|
}
|
|
originalError.call(console, ...args);
|
|
};
|
|
});
|
|
|
|
afterAll(() => {
|
|
console.error = originalError;
|
|
});
|