Files

35 lines
1.2 KiB
TypeScript

import { defineConfig } from 'vitest/config';
import { fileURLToPath } from 'node:url';
const shimPath = fileURLToPath(new URL('./vitest.rn-shim.ts', import.meta.url));
// Vitest cannot transform React Native's Flow-typed source. We redirect
// every `react-native` reference to a minimal host-component shim
// (`vitest.rn-shim.ts`) so @testing-library/react-native v12 + jsdom can
// render the few primitives PinInput uses.
//
// Two interception layers are needed:
// 1. resolve.alias — covers ESM imports vite sees during transformation
// of inlined dependencies (e.g. when @testing-library/react-native
// goes through vite's pipeline because of `server.deps.inline`).
// 2. setupFiles patches Module._resolveFilename so any pure-CJS
// `require("react-native")` that escapes vite also lands on the shim.
export default defineConfig({
test: {
environment: 'jsdom',
include: ['**/*.test.ts', '**/*.test.tsx'],
setupFiles: ['./vitest.setup.ts'],
server: {
deps: {
inline: [/@testing-library\/react-native/],
},
},
},
resolve: {
alias: [
{ find: /^react-native$/, replacement: shimPath },
{ find: /^react-native\/(.*)$/, replacement: shimPath },
],
},
});