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