Files
paseo/packages/app/vitest.config.ts
T
Mohamed Boudra d9d6509880 fix(test): resolve Metro .web.ts variants in vitest
message-input.tsx imports ./composer-height-mirror, which only exists
as .web.ts / .native.ts / .d.ts. Metro picks the right variant at build
time, but vitest was using Vite's default extension list and failing to
resolve the import — breaking app tests in CI.

Prepend `.web.*` variants to `resolve.extensions` in both the root and
app vitest configs so test runs (which already alias react-native →
react-native-web) pick the web implementation, matching what Metro
does for the web bundle.
2026-04-19 15:11:37 +07:00

84 lines
2.6 KiB
TypeScript

import { defineConfig, configDefaults } from "vitest/config";
import path from "path";
import fs from "fs";
const appNodeModules = path.resolve(__dirname, "node_modules");
const rootNodeModules = path.resolve(__dirname, "../../node_modules");
const resolvePackageEntry = (packageName: string) => {
const appPackagePath = path.resolve(appNodeModules, packageName);
return fs.existsSync(appPackagePath)
? appPackagePath
: path.resolve(rootNodeModules, packageName);
};
export default defineConfig({
test: {
environment: "node",
exclude: [...configDefaults.exclude, "e2e/**"],
setupFiles: [path.resolve(__dirname, "vitest.setup.ts")],
/**
* Expo pulls in native tooling (xcode, etc.) that executes files relying on `process.send`.
* Vitest's default worker pool uses worker_threads, which intentionally stub that API and
* immediately throw `Unexpected call to process.send`. Running the suite in forked processes
* keeps `process.send` intact so the app tests can boot before hitting the intentional failures.
*/
pool: "forks",
poolOptions: {
forks: {
maxForks: 2,
},
},
server: {
deps: {
fallbackCJS: true,
inline: ["zustand", "@tanstack/react-query", "react-native-web"],
},
},
},
resolve: {
extensions: [
".web.mjs",
".web.js",
".web.mts",
".web.ts",
".web.jsx",
".web.tsx",
".mjs",
".js",
".mts",
".ts",
".jsx",
".tsx",
".json",
],
alias: [
{
find: /^@getpaseo\/relay\/e2ee$/,
replacement: path.resolve(__dirname, "../relay/src/e2ee.ts"),
},
{
find: /^@getpaseo\/relay$/,
replacement: path.resolve(__dirname, "../relay/src/index.ts"),
},
{ find: "@", replacement: path.resolve(__dirname, "src") },
{ find: "@server", replacement: path.resolve(__dirname, "../server/src") },
// Point to the ESM build so Vite can transform its imports and apply the
// react alias below (the CJS build uses require('react') which bypasses
// Vite alias resolution).
{
find: "react-native",
replacement: path.resolve(rootNodeModules, "react-native-web/dist/index.js"),
},
{ find: "react", replacement: resolvePackageEntry("react") },
{
find: "react-dom",
replacement: resolvePackageEntry("react-dom"),
},
{
find: "@xterm/addon-ligatures",
replacement: path.resolve(__dirname, "test-stubs/xterm-addon-ligatures.ts"),
},
],
},
});