mirror of
https://github.com/hanzoai/dev-desktop.git
synced 2026-11-20 01:07:23 +00:00
178 lines
7.4 KiB
TypeScript
178 lines
7.4 KiB
TypeScript
import * as NodeModule from "node:module";
|
|
import * as NodeURL from "node:url";
|
|
import { defineConfig, normalizePath } from "vite-plus";
|
|
import "vite-plus/test/config";
|
|
|
|
const reactTests = [
|
|
"src/features/threads/ThreadGuestShareSheet.test.tsx",
|
|
"src/features/threads/useSubmitAfterNativeImages.test.tsx",
|
|
"src/features/threads/git/GitBranchesSheet.test.tsx",
|
|
"src/features/threads/new-task-flow-provider.test.tsx",
|
|
"src/features/threads/NewTaskRouteScreen.test.tsx",
|
|
"src/features/layout/workspace/workspace-tabs-state.test.ts",
|
|
"src/state/use-thread-pr.demand.test.tsx",
|
|
"src/features/threads/git/GitBranchesSheet.occupancy.test.tsx",
|
|
"src/features/files/useFileTreeEntries.test.tsx",
|
|
"src/features/files/thread-file-navigator-pane.test.tsx",
|
|
"src/features/files/source-file-document.test.ts",
|
|
"src/features/projects/AddProjectScreen.test.ts",
|
|
"src/lib/useMediaVideoPlayback.test.tsx",
|
|
"src/features/pull-requests/usePullRequestEnvironmentFallback.test.tsx",
|
|
"src/lib/filePreview.test.ts",
|
|
"src/features/threads/thread-inspector-navigation.test.tsx",
|
|
"src/features/diffs/nativeReviewDiffSurface.test.tsx",
|
|
"src/features/pull-requests/usePullRequestDiff.test.tsx",
|
|
"src/components/ProjectFavicon.test.tsx",
|
|
"src/components/ui/Dialog.android.test.tsx",
|
|
"src/features/pull-requests/usePullRequestList.test.tsx",
|
|
"src/components/ui/AppBar.android.test.tsx",
|
|
"src/features/files/ZipArchiveView.test.tsx",
|
|
"src/features/pull-requests/guide/useReviewGuide.test.tsx",
|
|
"src/features/settings/SettingsServerControlsRouteScreen.test.tsx",
|
|
"src/features/settings/SettingsScheduledTasksRouteScreen.test.tsx",
|
|
"src/features/settings/components/BranchNamingSettings.test.tsx",
|
|
"src/features/settings/components/SettingsDragHandle.test.tsx",
|
|
"src/features/threads/ThreadMarkdownImage.test.tsx",
|
|
"src/components/ui/FilePreviewSession.test.tsx",
|
|
"src/features/threads/UsageLimitRecoveryCard.test.tsx",
|
|
"src/features/threads/PendingUserInputCard.test.tsx",
|
|
"src/features/threads/NewTaskDraftRouteScreen.test.tsx",
|
|
"src/native/NativeHeaderToolbar.test.tsx",
|
|
"src/components/ComposerEditor.ios.test.tsx",
|
|
"src/native/V5StackHeader.ios.test.tsx",
|
|
"src/native/createV5StackNavigator.ios.test.tsx",
|
|
"src/native/useRetryingImageSource.test.tsx",
|
|
"src/state/queries.debounce.test.tsx",
|
|
"src/state/use-selected-thread-git-state.test.tsx",
|
|
"src/features/terminal/useTerminalExitNavigation.test.tsx",
|
|
"src/features/threads/use-thread-list-now.test.tsx",
|
|
"src/features/threads/use-composer-command-menu.select.test.tsx",
|
|
"src/features/threads/useThreadListV2.test.tsx",
|
|
"src/features/home/home-list-options.test.tsx",
|
|
"src/features/home/home-route-visibility.test.tsx",
|
|
"src/features/layout/workspace/useSearchScrollRestoration.test.tsx",
|
|
"src/features/connection/useRetryEnvironment.test.tsx",
|
|
"src/features/connection/ConnectionsNewRouteScreen.test.tsx",
|
|
"src/features/connection/LinkedEnvironmentsSection.test.tsx",
|
|
"src/features/devices/device-stream.browser.test.ts",
|
|
"src/features/keyboard/keyboardControllerState.test.tsx",
|
|
];
|
|
|
|
const sourceRoot = `${normalizePath(NodeURL.fileURLToPath(new URL("./src", import.meta.url)))}/`;
|
|
const require = NodeModule.createRequire(import.meta.url);
|
|
const babel: {
|
|
transformAsync: (
|
|
code: string,
|
|
options: Record<string, unknown>,
|
|
) => Promise<{ code?: string | null; map?: object | null } | null>;
|
|
} = require("@babel/core");
|
|
const babelConfig = require("./babel.config.js")({ cache: () => {} });
|
|
const testPlatform = process.env.HANZO_MOBILE_TEST_PLATFORM === "android" ? "android" : "ios";
|
|
|
|
// 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.
|
|
const gtTestModule = "\0gt-react-native";
|
|
const gtReactNativeEntry = require.resolve("gt-react-native");
|
|
const gtTestConfig = JSON.stringify({ defaultLocale: require("./gt.config.json").defaultLocale });
|
|
const gtTestModuleCode = `
|
|
import { I18nStore, ReactI18nCache, initializeI18nConfig, setI18nStore, setReactI18nCache } from "@generaltranslation/react-core/pure";
|
|
import { ReadonlyConditionStore, createConditionStoreSingleton } from "gt-i18n/internal";
|
|
const config = ${gtTestConfig};
|
|
initializeI18nConfig(config, "SPA");
|
|
setReactI18nCache(new ReactI18nCache(config));
|
|
createConditionStoreSingleton().setConditionStore(new ReadonlyConditionStore({ locale: config.defaultLocale }));
|
|
setI18nStore(new I18nStore());
|
|
export * from "@generaltranslation/react-core/components";
|
|
export * from "@generaltranslation/react-core/hooks";
|
|
export * from "@generaltranslation/react-core/pure";
|
|
export const initializeGT = () => {};
|
|
export const GTProvider = (props) => props.children;
|
|
`;
|
|
|
|
export default defineConfig({
|
|
plugins: [
|
|
{
|
|
name: "gt-react-native-test",
|
|
enforce: "pre",
|
|
resolveId(source, importer) {
|
|
if (source === "gt-react-native") return gtTestModule;
|
|
if (importer === gtTestModule) {
|
|
return this.resolve(source, gtReactNativeEntry, { skipSelf: true });
|
|
}
|
|
},
|
|
load(id) {
|
|
if (id === gtTestModule) return gtTestModuleCode;
|
|
},
|
|
},
|
|
],
|
|
test: {
|
|
hookTimeout: 60_000,
|
|
testTimeout: 60_000,
|
|
projects: [
|
|
{
|
|
extends: true,
|
|
test: {
|
|
name: "unit",
|
|
include: ["**/*.test.{ts,tsx,mjs}"],
|
|
exclude: ["**/node_modules/**", ...reactTests],
|
|
setupFiles: [
|
|
"../../packages/shared/src/testing/longTempDir.ts",
|
|
"../../packages/shared/src/testing/providerEnv.ts",
|
|
"../../packages/shared/src/testing/gitEnv.ts",
|
|
],
|
|
},
|
|
},
|
|
{
|
|
extends: true,
|
|
plugins: [
|
|
{
|
|
name: `mobile-release-react-compiler-${testPlatform}`,
|
|
enforce: "pre",
|
|
async transform(code, id) {
|
|
if (
|
|
!normalizePath(id).startsWith(sourceRoot) ||
|
|
!/\.tsx?$/.test(id) ||
|
|
/\.test\.tsx?$/.test(id)
|
|
) {
|
|
return;
|
|
}
|
|
const result = await babel.transformAsync(code, {
|
|
...babelConfig,
|
|
presets: babelConfig.presets.map(([name, options]: [string, object]) => [
|
|
require.resolve(name),
|
|
// Vite runs in Node; inline Babel helpers instead of Metro runtime imports.
|
|
{ ...options, enableBabelRuntime: false },
|
|
]),
|
|
filename: id,
|
|
babelrc: false,
|
|
configFile: false,
|
|
sourceMaps: true,
|
|
caller: {
|
|
name: "metro",
|
|
bundler: "metro",
|
|
platform: testPlatform,
|
|
isDev: false,
|
|
isServer: false,
|
|
isNodeModule: false,
|
|
supportsStaticESM: true,
|
|
supportsReactCompiler: true,
|
|
},
|
|
});
|
|
if (result?.code) return { code: result.code, map: result.map };
|
|
},
|
|
},
|
|
],
|
|
test: {
|
|
name: "react",
|
|
include: reactTests,
|
|
// Native components mock React Native and render through react-dom in these tests.
|
|
environment: "jsdom",
|
|
setupFiles: [
|
|
"../../packages/shared/src/testing/providerEnv.ts",
|
|
"../../packages/shared/src/testing/gitEnv.ts",
|
|
],
|
|
},
|
|
},
|
|
],
|
|
},
|
|
});
|