Skip to content

Commit 93ab4eb

Browse files
test(cli): Run the React Native patchNativeFiles tests as on macOS on every host
patchXcodeFiles asks whether to run `pod install` only on macOS, and the tests' @clack/prompts mock had no `select`, so they failed there. Mock `platform()` to "darwin" and answer the prompt with no, so the tests take the same path on macOS and Linux.
1 parent 1aa2925 commit 93ab4eb

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

‎packages/cli/test/lib/wizard/react-native/patch-native-files.test.ts‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,23 @@ import { addExpoEnvLocal } from "../../../../src/lib/wizard/react-native/expo-en
1313
import { patchNativeFiles } from "../../../../src/lib/wizard/react-native/react-native-wizard.js";
1414
import { Sentry } from "../../../../src/lib/wizard/telemetry.js";
1515

16-
const mocks = vi.hoisted(() => ({ info: vi.fn(), warn: vi.fn() }));
16+
const mocks = vi.hoisted(() => ({
17+
info: vi.fn(),
18+
warn: vi.fn(),
19+
select: vi.fn(),
20+
}));
21+
22+
// Run as on macOS on every host, so patchXcodeFiles asks whether to run
23+
// `pod install`; the mocked prompt answers no.
24+
vi.mock("node:os", async (importOriginal) => {
25+
const actual = await importOriginal<typeof import("node:os")>();
26+
return { ...actual, platform: () => "darwin" };
27+
});
1728

1829
vi.mock("@clack/prompts", () => ({
30+
select: mocks.select,
31+
isCancel: (value: unknown) => typeof value === "symbol",
32+
cancel: vi.fn(),
1933
log: {
2034
step: vi.fn(),
2135
info: mocks.info,
@@ -54,6 +68,7 @@ describe("patchNativeFiles", () => {
5468

5569
beforeEach(() => {
5670
vi.clearAllMocks();
71+
mocks.select.mockResolvedValue(false);
5772
vi.spyOn(Sentry, "setTag");
5873
dir = mkdtempSync(join(tmpdir(), "rn-wizard-native-"));
5974
process.chdir(dir);
@@ -89,6 +104,10 @@ describe("patchNativeFiles", () => {
89104
expect(read(".gitignore")).not.toContain(file);
90105
}
91106
expect(Sentry.setTag).toHaveBeenCalledWith("auth-token-location", DOT_ENV);
107+
expect(Sentry.setTag).toHaveBeenCalledWith(
108+
"continue-with-pod-install",
109+
false,
110+
);
92111
const info = messages(mocks.info).find((m) => m.includes(DOT_ENV));
93112
expect(info).toContain("gitignored");
94113
expect(info).toContain("SENTRY_AUTH_TOKEN");

0 commit comments

Comments
 (0)