generated from JoshuaKGoldberg/create-typescript-app
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #178 from JoshuaKGoldberg/test-cli
test: add coverage for cli.ts
- Loading branch information
Showing
4 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { describe, expect, it, vi } from "vitest"; | ||
|
||
import { shouldSemanticReleaseCLI } from "./cli.js"; | ||
import { shouldSemanticRelease } from "./shouldSemanticRelease.js"; | ||
|
||
vi.mock("./shouldSemanticRelease"); | ||
|
||
describe("cli", () => { | ||
it("calls shouldSemanticRelease without verbose when --verbose is not provided", async () => { | ||
await shouldSemanticReleaseCLI([]); | ||
|
||
expect(shouldSemanticRelease).toHaveBeenCalledWith({ verbose: false }); | ||
}); | ||
|
||
it("calls shouldSemanticRelease with verbose when --verbose is provided", async () => { | ||
await shouldSemanticReleaseCLI(["--verbose"]); | ||
|
||
expect(shouldSemanticRelease).toHaveBeenCalledWith({ verbose: true }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { describe, expect, it, vi } from "vitest"; | ||
|
||
import { execOrThrow } from "./utils.js"; | ||
|
||
const mockExec = vi.fn(); | ||
|
||
vi.mock("node:child_process", () => ({ | ||
default: { | ||
get exec() { | ||
return mockExec; | ||
}, | ||
}, | ||
})); | ||
|
||
describe("execOrThrow", () => { | ||
it("throws an error when exec prints to stderr", async () => { | ||
mockExec.mockImplementation((command, callback) => { | ||
callback(null, { stderr: "Oh no!" }); | ||
}); | ||
|
||
await expect( | ||
async () => await execOrThrow("ls"), | ||
).rejects.toMatchInlineSnapshot(`[Error: Oh no!]`); | ||
}); | ||
|
||
it("returns stdout when exec doesn't print to stderr", async () => { | ||
const stdout = "abc123"; | ||
|
||
mockExec.mockImplementation((command, callback) => { | ||
callback(null, { stdout }); | ||
}); | ||
|
||
const actual = await execOrThrow("ls"); | ||
|
||
expect(actual).toEqual(stdout); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters