Skip to content

Commit 1e198f4

Browse files
committed
test(mobile): simplify checkout occupancy regression
1 parent 0ec081c commit 1e198f4

2 files changed

Lines changed: 27 additions & 58 deletions

File tree

Lines changed: 26 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import * as NodeChildProcess from "node:child_process";
2-
import * as NodeFS from "node:fs";
3-
import * as NodeOS from "node:os";
4-
import * as NodePath from "node:path";
5-
import type { ReactNode } from "react";
6-
import { renderToStaticMarkup } from "react-dom/server";
1+
import { act, type ReactNode } from "react";
2+
import { createRoot } from "react-dom/client";
73
import { expect, it, vi } from "vite-plus/test";
84

95
const checkout = vi.hoisted(() => ({
@@ -59,60 +55,32 @@ vi.mock("../../../state/vcs", () => ({ vcsEnvironment: { status: () => null } })
5955
import { GitBranchesSheet } from "./GitBranchesSheet";
6056

6157
it("recognizes both the main checkout and a linked worktree as this thread's checkout", () => {
62-
const directory = NodeFS.realpathSync(
63-
NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "branch-occupancy-")),
64-
);
65-
const git = (...args: string[]) =>
66-
NodeChildProcess.execFileSync("git", ["-c", "commit.gpgsign=false", ...args], {
67-
cwd: directory,
68-
encoding: "utf8",
69-
stdio: "pipe",
70-
});
71-
try {
72-
git("init", "--initial-branch=main");
73-
git(
74-
"-c",
75-
"user.name=Test",
76-
"-c",
77-
78-
"commit",
79-
"--allow-empty",
80-
"-m",
81-
"initial",
82-
);
83-
const linked = NodePath.join(directory, "linked");
84-
git("worktree", "add", "-b", "feature/linked", linked);
85-
git("branch", "feature/available");
86-
checkout.projectRoot = directory;
87-
checkout.branches = git(
88-
"for-each-ref",
89-
"--format=%(refname:short)%00%(worktreepath)",
90-
"refs/heads",
91-
)
92-
.trimEnd()
93-
.split("\n")
94-
.map((line) => {
95-
const [name = "", worktreePath] = line.split("\0");
96-
return { name, worktreePath: worktreePath || null };
97-
});
98-
99-
const rows = () => {
100-
const html = renderToStaticMarkup(
58+
const directory = "/repo";
59+
const linked = "/repo-linked";
60+
checkout.projectRoot = directory;
61+
checkout.branches = [
62+
{ name: "feature/available", worktreePath: null },
63+
{ name: "feature/linked", worktreePath: linked },
64+
{ name: "main", worktreePath: directory },
65+
];
66+
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
67+
const container = document.createElement("div");
68+
const root = createRoot(container);
69+
const rows = () => {
70+
act(() => {
71+
root.render(
10172
<GitBranchesSheet
102-
route={{
103-
params: { environmentId: "environment-1", threadId: "thread-1" },
104-
}}
73+
route={{ params: { environmentId: "environment-1", threadId: "thread-1" } }}
10574
/>,
10675
);
107-
return [
108-
...html.matchAll(/<button([^>]*)><span>(.*?)<\/span><span>(.*?)<\/span><\/button>/g),
109-
].map(([, attributes, name, subtitle]) => ({
110-
name,
111-
subtitle,
112-
disabled: attributes?.includes("disabled"),
113-
}));
114-
};
115-
76+
});
77+
return [...container.querySelectorAll("button")].map((button) => ({
78+
name: button.querySelectorAll("span")[0]?.textContent,
79+
subtitle: button.querySelectorAll("span")[1]?.textContent,
80+
disabled: button.disabled,
81+
}));
82+
};
83+
try {
11684
checkout.worktreePath = null;
11785
expect(rows()).toEqual([
11886
{ name: "feature/available", subtitle: "Local branch", disabled: false },
@@ -127,6 +95,6 @@ it("recognizes both the main checkout and a linked worktree as this thread's che
12795
{ name: "main", subtitle: "Checked out in another worktree", disabled: true },
12896
]);
12997
} finally {
130-
NodeFS.rmSync(directory, { recursive: true, force: true });
98+
act(() => root.unmount());
13199
}
132100
});

‎apps/mobile/vite.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { defineConfig, normalizePath } from "vite-plus";
44
import "vite-plus/test/config";
55

66
const reactTests = [
7+
"src/features/threads/git/GitBranchesSheet.occupancy.test.tsx",
78
"src/lib/useMediaVideoPlayback.test.tsx",
89
"src/features/pull-requests/usePullRequestEnvironmentFallback.test.tsx",
910
"src/lib/filePreview.test.ts",

0 commit comments

Comments
 (0)