Open History to see the last commit
1import * as NodeModule from "node:module";
2import * as NodeURL from "node:url";
3import { defineConfig, normalizePath } from "vite-plus";
4import "vite-plus/test/config";
5
6const reactTests = [
7 "src/features/threads/ThreadGuestShareSheet.test.tsx",
8 "src/features/threads/useSubmitAfterNativeImages.test.tsx",
9 "src/features/threads/git/GitBranchesSheet.test.tsx",
10 "src/features/threads/new-task-flow-provider.test.tsx",
11 "src/features/threads/NewTaskRouteScreen.test.tsx",
12 "src/features/layout/workspace/workspace-tabs-state.test.ts",
13 "src/state/use-thread-pr.demand.test.tsx",
14 "src/features/threads/git/GitBranchesSheet.occupancy.test.tsx",
15 "src/features/files/useFileTreeEntries.test.tsx",
16 "src/features/files/thread-file-navigator-pane.test.tsx",
17 "src/features/files/source-file-document.test.ts",
18 "src/features/projects/AddProjectScreen.test.ts",
19 "src/lib/useMediaVideoPlayback.test.tsx",
20 "src/features/pull-requests/usePullRequestEnvironmentFallback.test.tsx",
21 "src/lib/filePreview.test.ts",
22 "src/features/threads/thread-inspector-navigation.test.tsx",
23 "src/features/diffs/nativeReviewDiffSurface.test.tsx",
24 "src/features/pull-requests/usePullRequestDiff.test.tsx",
25 "src/components/ProjectFavicon.test.tsx",
26 "src/components/ui/Dialog.android.test.tsx",
27 "src/features/pull-requests/usePullRequestList.test.tsx",
28 "src/components/ui/AppBar.android.test.tsx",
29 "src/features/files/ZipArchiveView.test.tsx",
30 "src/features/pull-requests/guide/useReviewGuide.test.tsx",
31 "src/features/settings/SettingsServerControlsRouteScreen.test.tsx",
32 "src/features/settings/SettingsScheduledTasksRouteScreen.test.tsx",
33 "src/features/settings/components/BranchNamingSettings.test.tsx",
34 "src/features/settings/components/SettingsDragHandle.test.tsx",
35 "src/features/threads/ThreadMarkdownImage.test.tsx",
36 "src/components/ui/FilePreviewSession.test.tsx",
37 "src/features/threads/UsageLimitRecoveryCard.test.tsx",
38 "src/features/threads/PendingUserInputCard.test.tsx",
39 "src/features/threads/NewTaskDraftRouteScreen.test.tsx",
40 "src/native/NativeHeaderToolbar.test.tsx",
41 "src/components/ComposerEditor.ios.test.tsx",
42 "src/native/V5StackHeader.ios.test.tsx",
43 "src/native/createV5StackNavigator.ios.test.tsx",
44 "src/native/useRetryingImageSource.test.tsx",
45 "src/state/queries.debounce.test.tsx",
46 "src/state/use-selected-thread-git-state.test.tsx",
47 "src/features/terminal/useTerminalExitNavigation.test.tsx",
48 "src/features/threads/use-thread-list-now.test.tsx",
49 "src/features/threads/use-composer-command-menu.select.test.tsx",
50 "src/features/threads/useThreadListV2.test.tsx",
51 "src/features/home/home-list-options.test.tsx",
52 "src/features/home/home-route-visibility.test.tsx",
53 "src/features/layout/workspace/useSearchScrollRestoration.test.tsx",
54 "src/features/connection/useRetryEnvironment.test.tsx",
55 "src/features/connection/ConnectionsNewRouteScreen.test.tsx",
56 "src/features/connection/LinkedEnvironmentsSection.test.tsx",
57 "src/features/devices/device-stream.browser.test.ts",
58 "src/features/keyboard/keyboardControllerState.test.tsx",
59];
60
61const sourceRoot = `${normalizePath(NodeURL.fileURLToPath(new URL("./src", import.meta.url)))}/`;
62const require = NodeModule.createRequire(import.meta.url);
63const babel: {
64 transformAsync: (
65 code: string,
66 options: Record<string, unknown>,
67 ) => Promise<{ code?: string | null; map?: object | null } | null>;
68} = require("@babel/core");
69const babelConfig = require("./babel.config.js")({ cache: () => {} });
70const testPlatform = process.env.T3_MOBILE_TEST_PLATFORM === "android" ? "android" : "ios";
71
72// gt-react-native loads react-native and its hooks need <GTProvider>; tests get GT's core set up the way gt-react's initializeGTSPA does, which renders English without a provider.
73const gtTestModule = "\0gt-react-native";
74const gtReactNativeEntry = require.resolve("gt-react-native");
75const gtTestConfig = JSON.stringify({ defaultLocale: require("./gt.config.json").defaultLocale });
76const gtTestModuleCode = `
77import { I18nStore, ReactI18nCache, initializeI18nConfig, setI18nStore, setReactI18nCache } from "@generaltranslation/react-core/pure";
78import { ReadonlyConditionStore, createConditionStoreSingleton } from "gt-i18n/internal";
79const config = ${gtTestConfig};
80initializeI18nConfig(config, "SPA");
81setReactI18nCache(new ReactI18nCache(config));
82createConditionStoreSingleton().setConditionStore(new ReadonlyConditionStore({ locale: config.defaultLocale }));
83setI18nStore(new I18nStore());
84export * from "@generaltranslation/react-core/components";
85export * from "@generaltranslation/react-core/hooks";
86export * from "@generaltranslation/react-core/pure";
87export const initializeGT = () => {};
88export const GTProvider = (props) => props.children;
89`;
90
91export default defineConfig({
92 plugins: [
93 {
94 name: "gt-react-native-test",
95 enforce: "pre",
96 resolveId(source, importer) {
97 if (source === "gt-react-native") return gtTestModule;
98 if (importer === gtTestModule) {
99 return this.resolve(source, gtReactNativeEntry, { skipSelf: true });
100 }
101 },
102 load(id) {
103 if (id === gtTestModule) return gtTestModuleCode;
104 },
105 },
106 ],
107 test: {
108 hookTimeout: 60_000,
109 testTimeout: 60_000,
110 projects: [
111 {
112 extends: true,
113 test: {
114 name: "unit",
115 include: ["**/*.test.{ts,tsx,mjs}"],
116 exclude: ["**/node_modules/**", ...reactTests],
117 setupFiles: [
118 "../../packages/shared/src/testing/longTempDir.ts",
119 "../../packages/shared/src/testing/providerEnv.ts",
120 "../../packages/shared/src/testing/gitEnv.ts",
121 ],
122 },
123 },
124 {
125 extends: true,
126 plugins: [
127 {
128 name: `mobile-release-react-compiler-${testPlatform}`,
129 enforce: "pre",
130 async transform(code, id) {
131 if (
132 !normalizePath(id).startsWith(sourceRoot) ||
133 !/\.tsx?$/.test(id) ||
134 /\.test\.tsx?$/.test(id)
135 ) {
136 return;
137 }
138 const result = await babel.transformAsync(code, {
139 ...babelConfig,
140 presets: babelConfig.presets.map(([name, options]: [string, object]) => [
141 require.resolve(name),
142 // Vite runs in Node; inline Babel helpers instead of Metro runtime imports.
143 { ...options, enableBabelRuntime: false },
144 ]),
145 filename: id,
146 babelrc: false,
147 configFile: false,
148 sourceMaps: true,
149 caller: {
150 name: "metro",
151 bundler: "metro",
152 platform: testPlatform,
153 isDev: false,
154 isServer: false,
155 isNodeModule: false,
156 supportsStaticESM: true,
157 supportsReactCompiler: true,
158 },
159 });
160 if (result?.code) return { code: result.code, map: result.map };
161 },
162 },
163 ],
164 test: {
165 name: "react",
166 include: reactTests,
167 // Native components mock React Native and render through react-dom in these tests.
168 environment: "jsdom",
169 setupFiles: [
170 "../../packages/shared/src/testing/providerEnv.ts",
171 "../../packages/shared/src/testing/gitEnv.ts",
172 ],
173 },
174 },
175 ],
176 },
177});