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