@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

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