diff --git a/apps/mobile/src/modules/onramp/components/OnrampForm/__tests__/useOnrampForm.spec.tsx b/apps/mobile/src/modules/onramp/components/OnrampForm/__tests__/useOnrampForm.spec.tsx index 048294e70..79cca4678 100644 --- a/apps/mobile/src/modules/onramp/components/OnrampForm/__tests__/useOnrampForm.spec.tsx +++ b/apps/mobile/src/modules/onramp/components/OnrampForm/__tests__/useOnrampForm.spec.tsx @@ -108,6 +108,13 @@ vi.mock('@perawallet/wallet-core-assets', () => ({ vi.mock('@perawallet/wallet-core-blockchain', () => ({ useNetwork: () => ({ network: 'mainnet' }), + // Analytics (packages/analytics/src/log.ts) reads useNetworkStore.getState().network on every + // trackEvent. Without it, each analytics call logs "No useNetworkStore export on the mock", and + // that pending console forwarding intermittently crashes the vitest worker at teardown + // (EnvironmentTeardownError, blamed on messages.test.tsx in the same worker). + useNetworkStore: Object.assign(() => 'mainnet', { + getState: () => ({ network: 'mainnet' }), + }), })) vi.mock('@hooks/useToast', () => ({ diff --git a/apps/mobile/vitest.integration-setup.ts b/apps/mobile/vitest.integration-setup.ts index 5c2b62e41..0717d3e87 100644 --- a/apps/mobile/vitest.integration-setup.ts +++ b/apps/mobile/vitest.integration-setup.ts @@ -29,8 +29,14 @@ import { useBottomSheetStore } from './src/modules/bottom-sheet' // Reset it after each integration test so flows that count requests, or // assert sheet visibility from a known clean slate, aren't poisoned by // the previous case. -afterEach(() => { +afterEach(async () => { useBottomSheetStore.getState().resetState() + // Drain the macrotask queue so any background async that settles just after a flow test + // finishes (a late query resolve / logger.warn from polling code — see the + // waitForConfirmation note below) forwards its console DURING the test window rather than at + // worker teardown, where a pending forward crashes as + // `EnvironmentTeardownError: Closing rpc while "onUserConsoleLog" was pending` and fails CI. + await new Promise(resolve => setTimeout(resolve, 0)) }) // jsdom installs its own `Uint8Array` constructor on `globalThis`. Node's