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