Problem: - Multiple rapid calls to sendTranscript() created race conditions - Old requests continued using local abortController variable - Responses from superseded requests could still be processed - Session stop didn't reliably prevent pending responses Solution: - Changed abort checks from `abortController.signal.aborted` to `abortControllerRef.current !== abortController` - Ensures request checks if it's still the active one, not just aborted - Added checks at 4 critical points: before API call, after API call, before retry, and after retry Changes: - VoiceContext.tsx:268 - Check before initial API call - VoiceContext.tsx:308 - Check after API response - VoiceContext.tsx:344 - Check before retry - VoiceContext.tsx:359 - Check after retry response Testing: - Added Jest test configuration - Added test suite with 5 race condition scenarios - Added manual testing documentation - Verified with TypeScript linting (no new errors) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
31 lines
597 B
JavaScript
31 lines
597 B
JavaScript
// Jest setup for React Native Testing Library
|
|
|
|
// Mock Expo modules
|
|
jest.mock('expo-speech', () => ({
|
|
speak: jest.fn(),
|
|
stop: jest.fn(),
|
|
isSpeakingAsync: jest.fn().mockResolvedValue(false),
|
|
}));
|
|
|
|
jest.mock('expo-secure-store', () => ({
|
|
getItemAsync: jest.fn(),
|
|
setItemAsync: jest.fn(),
|
|
deleteItemAsync: jest.fn(),
|
|
}));
|
|
|
|
jest.mock('expo-constants', () => ({
|
|
expoConfig: {
|
|
extra: {},
|
|
},
|
|
}));
|
|
|
|
// Mock console methods during tests to reduce noise
|
|
global.console = {
|
|
...console,
|
|
log: jest.fn(),
|
|
debug: jest.fn(),
|
|
info: jest.fn(),
|
|
warn: jest.fn(),
|
|
error: jest.fn(),
|
|
};
|