test: configure Vitest testing framework
- Add vitest, @testing-library/react, @vitest/ui, jsdom dependencies - Create vitest.config.ts with jsdom environment and coverage settings - Add tests/setup.ts with localStorage mock and crypto mock - Add tests/gateway/ws-client.test.ts for GatewayClient unit tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
50
tests/setup.ts
Normal file
50
tests/setup.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Test setup file for Vitest
|
||||
* Configure global test environment
|
||||
*/
|
||||
|
||||
import { beforeAll, beforeEach } from 'vitest';
|
||||
|
||||
// Mock localStorage
|
||||
const localStorageMock = (() => {
|
||||
let store: Record<string, string> = {};
|
||||
return {
|
||||
getItem: (key: string) => store[key] || null,
|
||||
setItem: (key: string, value: string) => {
|
||||
store[key] = value.toString();
|
||||
},
|
||||
removeItem: (key: string) => {
|
||||
delete store[key];
|
||||
},
|
||||
clear: () => {
|
||||
store = {};
|
||||
},
|
||||
get length() {
|
||||
return Object.keys(store).length;
|
||||
},
|
||||
key: (index: number) => {
|
||||
return Object.keys(store)[index] || null;
|
||||
},
|
||||
};
|
||||
})();
|
||||
|
||||
// Setup global mocks
|
||||
beforeAll(() => {
|
||||
// Mock crypto.randomUUID if not available
|
||||
if (!globalThis.crypto) {
|
||||
globalThis.crypto = {
|
||||
randomUUID: () => 'test-uuid-1234',
|
||||
subtle: {
|
||||
digest: async () => new ArrayBuffer(16),
|
||||
},
|
||||
} as any;
|
||||
}
|
||||
});
|
||||
|
||||
// Setup before each test
|
||||
beforeEach(() => {
|
||||
localStorageMock.clear();
|
||||
});
|
||||
|
||||
// Export for use in tests
|
||||
export { localStorageMock };
|
||||
Reference in New Issue
Block a user