mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-23 09:42:53 +00:00
* fix(app): keep sidebar order keys that end in whitespace A project view key embeds the project's path, so a directory whose name ends in a space produces a key that ends in a space. The sidebar order store trimmed every key on write, so the stored key could never match the key the sidebar looks up. computeSidebarOrderUpdates saw the project as missing from the order on every pass, appended it, and the store trimmed it away again, setting a fresh array each time. The effect that applies those updates re-ran on every render until React gave up with error #185, and the app failed to load until the folder was renamed. Keep keys verbatim on the runtime setters, dropping only blank keys and duplicates. Migration of persisted state still trims, where a stray space is an artifact of an older format rather than part of the key. Fixes #4880 * test(app): give AsyncStorage a real in-memory stub instead of mocking it `docs/testing.md` bans `vi.mock`, and the test added here mocked `@react-native-async-storage/async-storage` only because the module has no Node implementation: its default export reaches for the native module, so every write from the persist middleware rejects and a test that touches a persisted store drowns in unhandled rejections. That is exactly the case `test-stubs/` exists for, reached through the resolve.alias in `vitest.config.ts` the same way react-native-unistyles, react-native-svg and expo-linking are. The stub is a real in-memory key-value store with the same contract, so a test can read back what a store wrote rather than inspect a recording double. `sidebar-view-store.test.ts` carried the same mock for the same reason and no longer needs it either. * test(app): give the AsyncStorage stub the multi-key calls the app uses `provider-snapshot-cache` declares its own `ProviderSnapshotStorage` port and is handed the real AsyncStorage, so it calls `multiGet` and `multiRemove` during reconciliation and cleanup. The stub stopped at the single-key calls, which is fine until a test reaches the provider cache and then fails with `storage.multiGet is not a function`. `multiSet` comes along with them so the three multi-key calls behave as a set rather than leaving the next caller to notice the gap the same way. * test(app): cover a project folder name ending in a space end to end Adds a browser regression for #4880: the daemon accepts a directory whose name ends in a space, and the sidebar has to render its project row instead of tearing the app down with "Maximum update depth exceeded" on every load. * test(app): move the trailing-space spec setup behind a seeded-project helper docs/testing.md asks for E2E bodies that read like plain English with the setup in helpers, and for helpers that own the project record until cleanup. The spec did its directory creation, daemon seeding, and removal inline. seedProjectNamedWithTrailingSpace owns the directory and the daemon project and returns a cleanup, the same shape seedWorkspace returns, which cannot be used here because mkdtemp appends the random suffix and so cannot produce a name that ends in a space. The body is now goto, assert the row, assert no error screen. The row is still located by its sidebar-project-row test id, which is how every other sidebar spec and the shared sidebar helpers address a project row. --------- Co-authored-by: L4XB <lukas.buck@e-mail.de> Co-authored-by: paseo-bot[bot] <paseo-bot[bot]@users.noreply.github.com>
201 lines
7.1 KiB
TypeScript
201 lines
7.1 KiB
TypeScript
import { defineConfig, configDefaults } from "vitest/config";
|
|
import { playwright } from "@vitest/browser-playwright";
|
|
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/**"],
|
|
projects: [
|
|
{
|
|
extends: true,
|
|
test: {
|
|
name: "unit",
|
|
environment: "node",
|
|
include: ["src/**/*.{test,spec}.{ts,tsx}", "native-release-version.test.ts"],
|
|
setupFiles: [path.resolve(__dirname, "vitest.setup.ts")],
|
|
exclude: [...configDefaults.exclude, "e2e/**", "src/**/*.browser.{test,spec}.{ts,tsx}"],
|
|
},
|
|
},
|
|
{
|
|
extends: true,
|
|
test: {
|
|
name: "browser",
|
|
fileParallelism: false,
|
|
include: ["src/**/*.browser.{test,spec}.{ts,tsx}"],
|
|
browser: {
|
|
enabled: true,
|
|
provider: playwright(),
|
|
headless: true,
|
|
connectTimeout: 180_000,
|
|
instances: [{ browser: "chromium" }],
|
|
screenshotDirectory: ".vitest-screenshots",
|
|
},
|
|
globalSetup: path.resolve(__dirname, "src/runtime/websocket-test-global-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",
|
|
maxWorkers: 2,
|
|
server: {
|
|
deps: {
|
|
fallbackCJS: true,
|
|
inline: [
|
|
"zustand",
|
|
"@tanstack/react-query",
|
|
"react-native-web",
|
|
"react-native-gesture-handler",
|
|
"react-native-keyboard-controller",
|
|
],
|
|
},
|
|
},
|
|
},
|
|
// Reanimated and gesture-handler pick platform files by extension
|
|
// (e.g. `GestureHandlerRootView.web.js`). Vite's optimizer does not apply `resolve.extensions`,
|
|
// so it scans the native files and dies on imports react-native-web has no answer for.
|
|
// Unbundled, the same imports go through the resolver below and land on the web files.
|
|
optimizeDeps: {
|
|
// Bundle the CJS dependencies of the excluded gesture-handler package for the browser.
|
|
include: [
|
|
"react/jsx-runtime",
|
|
"react-native-gesture-handler > hoist-non-react-statics",
|
|
"react-native-gesture-handler > invariant",
|
|
],
|
|
exclude: [
|
|
"react-native-reanimated",
|
|
"react-native-gesture-handler",
|
|
"react-native-keyboard-controller",
|
|
],
|
|
},
|
|
// The globals a React Native bundler defines, which esbuild is no longer there to supply for
|
|
// the package excluded above.
|
|
define: {
|
|
"process.env.JEST_WORKER_ID": "undefined",
|
|
__DEV__: "false",
|
|
global: "globalThis",
|
|
},
|
|
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") },
|
|
// Keep keyboard-controller's imports in Vite so native aliases and platform extensions apply.
|
|
{
|
|
find: /^react-native-keyboard-controller$/,
|
|
replacement: path.resolve(
|
|
resolvePackageEntry("react-native-keyboard-controller"),
|
|
"lib/module/index.js",
|
|
),
|
|
},
|
|
// The CJS entry bypasses Vite's React Native alias and web-extension resolution.
|
|
{
|
|
find: /^react-native-gesture-handler$/,
|
|
replacement: path.resolve(
|
|
rootNodeModules,
|
|
"react-native-gesture-handler/lib/module/index.js",
|
|
),
|
|
},
|
|
// Must precede the `react-native` alias: a string `find` matches by prefix, so this subpath
|
|
// would otherwise resolve inside a react-native-web *file* and break the dependency scan.
|
|
// Reanimated only imports it on the native path, which no test takes.
|
|
{
|
|
find: /^react-native\/Libraries\/Renderer\/shims\/ReactFabric$/,
|
|
replacement: path.resolve(__dirname, "test-stubs/react-native-fabric-shim.ts"),
|
|
},
|
|
// 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\/lib\/addon-ligatures\.mjs$/,
|
|
replacement: path.resolve(__dirname, "test-stubs/xterm-addon-ligatures.ts"),
|
|
},
|
|
{
|
|
find: /^@xterm\/addon-ligatures$/,
|
|
replacement: path.resolve(__dirname, "test-stubs/xterm-addon-ligatures.ts"),
|
|
},
|
|
{
|
|
find: /^react-native-unistyles$/,
|
|
replacement: path.resolve(__dirname, "test-stubs/react-native-unistyles.ts"),
|
|
},
|
|
{
|
|
find: /^react-native-svg$/,
|
|
replacement: path.resolve(__dirname, "test-stubs/react-native-svg.ts"),
|
|
},
|
|
// Both ship untranspiled Flow and fail to parse on import, which takes out any test that
|
|
// mounts a menu surface.
|
|
{
|
|
find: /^react-native-safe-area-context$/,
|
|
replacement: path.resolve(__dirname, "test-stubs/react-native-safe-area-context.ts"),
|
|
},
|
|
{
|
|
find: /^@gorhom\/bottom-sheet$/,
|
|
replacement: path.resolve(__dirname, "test-stubs/gorhom-bottom-sheet.ts"),
|
|
},
|
|
{
|
|
find: /^react-native-reanimated\/scripts\/validate-worklets-version$/,
|
|
replacement: path.resolve(__dirname, "test-stubs/reanimated-validate-worklets-version.ts"),
|
|
},
|
|
{
|
|
find: /^expo-linking$/,
|
|
replacement: path.resolve(__dirname, "test-stubs/expo-linking.ts"),
|
|
},
|
|
// No Node implementation: every call on the real module rejects, so a test
|
|
// touching a persisted store drowns in unhandled rejections.
|
|
{
|
|
find: /^@react-native-async-storage\/async-storage$/,
|
|
replacement: path.resolve(__dirname, "test-stubs/async-storage.ts"),
|
|
},
|
|
{
|
|
find: /^lucide-react-native$/,
|
|
replacement: path.resolve(__dirname, "test-stubs/lucide-react-native.ts"),
|
|
},
|
|
],
|
|
},
|
|
});
|