Skip to content

Commit

Permalink
Fixing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jculvey committed Jul 18, 2023
1 parent c13d1b5 commit 6409c90
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions packages/create-cloudflare/src/helpers/__tests__/command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ describe("Command Helpers", () => {
const expectSpawnWith = (cmd: string) => {
const [command, ...args] = cmd.split(" ");

expect(spawn).toHaveBeenCalledWith(command, args, {
stdio: "inherit",
env: process.env,
});
};

const expectSilentSpawnWith = (cmd: string) => {
const [command, ...args] = cmd.split(" ");

expect(spawn).toHaveBeenCalledWith(command, args, {
stdio: "pipe",
env: process.env,
Expand All @@ -81,12 +90,13 @@ describe("Command Helpers", () => {

test("installWrangler", async () => {
await installWrangler();
expectSpawnWith("npm install --save-dev wrangler");

expectSilentSpawnWith("npm install --save-dev wrangler");
});

test("npmInstall", async () => {
await npmInstall();
expectSpawnWith("npm install");
expectSilentSpawnWith("npm install");
});

test("npmInstall from pnpm", async () => {
Expand All @@ -96,12 +106,12 @@ describe("Command Helpers", () => {
});

await npmInstall();
expectSpawnWith("pnpm install");
expectSilentSpawnWith("pnpm install");
});

test("installPackages", async () => {
await installPackages(["foo", "bar", "baz"], { dev: true });
expectSpawnWith("npm install --save-dev foo bar baz");
expectSilentSpawnWith("npm install --save-dev foo bar baz");
});

describe("detectPackageManager", async () => {
Expand Down Expand Up @@ -167,29 +177,29 @@ describe("Command Helpers", () => {
test("normal flow", async () => {
spawnStdout = "2.20250110.5";
const date = await getWorkerdCompatibilityDate();
expectSpawnWith("npm info workerd dist-tags.latest");
expectSilentSpawnWith("npm info workerd dist-tags.latest");
expect(date).toBe("2025-01-10");
});

test("empty result", async () => {
spawnStdout = "";
const date = await getWorkerdCompatibilityDate();
expectSpawnWith("npm info workerd dist-tags.latest");
expectSilentSpawnWith("npm info workerd dist-tags.latest");
expect(date).toBe("2023-05-18");
});

test("verbose output (e.g. yarn or debug mode)", async () => {
spawnStdout =
"Debugger attached.\nyarn info v1.22.19\n2.20250110.5\n✨ Done in 0.83s.";
const date = await getWorkerdCompatibilityDate();
expectSpawnWith("npm info workerd dist-tags.latest");
expectSilentSpawnWith("npm info workerd dist-tags.latest");
expect(date).toBe("2025-01-10");
});

test("command failed", async () => {
spawnResultCode = 1;
const date = await getWorkerdCompatibilityDate();
expectSpawnWith("npm info workerd dist-tags.latest");
expectSilentSpawnWith("npm info workerd dist-tags.latest");
expect(date).toBe("2023-05-18");
});
});
Expand Down

0 comments on commit 6409c90

Please sign in to comment.