Skip to content

Commit 76ece75

Browse files
authored
chore: improve c3 tests (#6734)
1 parent e4fe35c commit 76ece75

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

packages/create-cloudflare/e2e-tests/frameworks.test.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -660,20 +660,13 @@ const verifyBuildCfTypesScript = async (
660660
const outputFileContentPost = readFile(join(projectPath, outputFile));
661661
const outputFileContentPostLines = outputFileContentPost.split("\n");
662662

663+
// the file doesn't contain the "Generated by Wrangler" comment anymore
664+
expect(outputFileContentPostLines).not.toContain("// Generated by Wrangler");
665+
663666
// the file still contains the env interface
664667
expect(outputFileContentPostLines).toContain(
665668
`interface ${envInterfaceName} {`,
666669
);
667-
668-
// the file doesn't contain the "Generated by Wrangler" comment without a timestamp anymore
669-
expect(outputFileContentPostLines).not.toContain("// Generated by Wrangler");
670-
671-
// but it contains the "Generated by Wrangler" comment now with a timestamp
672-
expect(
673-
/\/\/ Generated by Wrangler on [a-zA-Z]*? [a-zA-Z]*? \d{2} \d{4} \d{2}:\d{2}:\d{2}/.test(
674-
outputFileContentPost,
675-
),
676-
).toBeTruthy();
677670
};
678671

679672
const verifyBuildScript = async (

packages/create-cloudflare/src/__tests__/deploy.test.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { crash } from "@cloudflare/cli";
2-
import { processArgument } from "@cloudflare/cli/args";
2+
import { inputPrompt } from "@cloudflare/cli/interactive";
33
import { mockPackageManager, mockSpinner } from "helpers/__tests__/mocks";
44
import { runCommand } from "helpers/command";
55
import { readFile } from "helpers/files";
@@ -10,7 +10,6 @@ import { createTestContext } from "./helpers";
1010

1111
vi.mock("helpers/command");
1212
vi.mock("../wrangler/accounts");
13-
vi.mock("@cloudflare/cli/args");
1413
vi.mock("@cloudflare/cli/interactive");
1514
vi.mock("which-pm-runs");
1615
vi.mock("@cloudflare/cli");
@@ -33,16 +32,24 @@ const mockInsideGitRepo = (isInside = true) => {
3332
describe("deploy helpers", async () => {
3433
beforeEach(() => {
3534
mockPackageManager("npm");
36-
3735
mockSpinner();
36+
vi.mocked(inputPrompt).mockImplementation(async (options) => {
37+
if (options.acceptDefault) {
38+
return options.defaultValue;
39+
}
40+
41+
throw new Error(
42+
"If you don't want to accept the default, you must mock this function.",
43+
);
44+
});
3845
});
3946

4047
describe("offerToDeploy", async () => {
4148
test("user selects yes and succeeds", async () => {
4249
const ctx = createTestContext();
4350
ctx.template.platform = "pages";
4451
// mock the user selecting yes when asked to deploy
45-
vi.mocked(processArgument).mockResolvedValueOnce(true);
52+
vi.mocked(inputPrompt).mockResolvedValueOnce(true);
4653
// mock a successful wrangler login
4754
vi.mocked(wranglerLogin).mockResolvedValueOnce(true);
4855

@@ -55,7 +62,7 @@ describe("deploy helpers", async () => {
5562
vi.mocked(readFile).mockReturnValue(`binding = "MY_QUEUE"`);
5663

5764
await expect(offerToDeploy(ctx)).resolves.toBe(false);
58-
expect(processArgument).toHaveBeenCalledOnce();
65+
expect(inputPrompt).toHaveBeenCalledOnce();
5966
expect(ctx.args.deploy).toBe(false);
6067
expect(wranglerLogin).not.toHaveBeenCalled();
6168
});
@@ -72,7 +79,7 @@ describe("deploy helpers", async () => {
7279
`);
7380

7481
await expect(offerToDeploy(ctx)).resolves.toBe(false);
75-
expect(processArgument).toHaveBeenCalledOnce();
82+
expect(inputPrompt).toHaveBeenCalledOnce();
7683
expect(ctx.args.deploy).toBe(false);
7784
expect(wranglerLogin).not.toHaveBeenCalled();
7885
});
@@ -83,13 +90,13 @@ describe("deploy helpers", async () => {
8390
experimental_assets = { directory = "./dist", binding = "ASSETS" }
8491
`);
8592
// mock the user selecting yes when asked to deploy
86-
vi.mocked(processArgument).mockResolvedValueOnce(true);
93+
vi.mocked(inputPrompt).mockResolvedValueOnce(true);
8794
// mock a successful wrangler login
8895
vi.mocked(wranglerLogin).mockResolvedValueOnce(true);
8996

9097
await expect(offerToDeploy(ctx)).resolves.toBe(true);
91-
expect(processArgument).toHaveBeenCalledOnce();
92-
expect(ctx.args.deploy).toBe(false);
98+
expect(inputPrompt).toHaveBeenCalledOnce();
99+
expect(ctx.args.deploy).toBe(true);
93100
expect(wranglerLogin).toHaveBeenCalled();
94101
});
95102

@@ -99,15 +106,15 @@ describe("deploy helpers", async () => {
99106
ctx.template.platform = "pages";
100107

101108
await expect(offerToDeploy(ctx)).resolves.toBe(false);
102-
expect(processArgument).toHaveBeenCalledOnce();
109+
expect(inputPrompt).toHaveBeenCalledOnce();
103110
expect(ctx.args.deploy).toBe(false);
104111
expect(wranglerLogin).not.toHaveBeenCalled();
105112
});
106113

107114
test("wrangler login failure", async () => {
108115
const ctx = createTestContext();
109116
ctx.template.platform = "pages";
110-
vi.mocked(processArgument).mockResolvedValueOnce(true);
117+
vi.mocked(inputPrompt).mockResolvedValueOnce(true);
111118
vi.mocked(wranglerLogin).mockResolvedValueOnce(false);
112119

113120
await expect(offerToDeploy(ctx)).resolves.toBe(false);

0 commit comments

Comments
 (0)