-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: finish unit testing initialize and initializeWithOptions (#1631)
## PR Checklist - [x] Addresses an existing open issue: fixes #873 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CONTRIBUTING.md) were taken ## Overview As the issue suggested, this was a fair bit of setup. But I feel better now. Also swaps out a `0` that was just coincidentally the same as the proper `StatusCodes.Success`. 💖
- Loading branch information
1 parent
79773ac
commit 61e374f
Showing
3 changed files
with
254 additions
and
7 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
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,187 @@ | ||
import { describe, expect, it, vi } from "vitest"; | ||
|
||
import { GitHub } from "../shared/options/getGitHub.js"; | ||
import { Options } from "../shared/types.js"; | ||
import { initializeWithOptions } from "./initializeWithOptions.js"; | ||
|
||
vi.mock("../shared/cli/spinners.js", () => ({ | ||
async withSpinner(_label: string, task: () => Promise<void>) { | ||
await task(); | ||
}, | ||
withSpinners: vi.fn(), | ||
})); | ||
|
||
const mockAddOwnerAsAllContributor = vi.fn(); | ||
|
||
vi.mock("../steps/addOwnerAsAllContributor.js", () => ({ | ||
get addOwnerAsAllContributor() { | ||
return mockAddOwnerAsAllContributor; | ||
}, | ||
})); | ||
|
||
const mockClearChangelog = vi.fn(); | ||
|
||
vi.mock("../steps/clearChangelog.js", () => ({ | ||
get clearChangelog() { | ||
return mockClearChangelog; | ||
}, | ||
})); | ||
|
||
const mockInitializeGitHubRepository = vi.fn(); | ||
|
||
vi.mock("../steps/initializeGitHubRepository/index.js", () => ({ | ||
get initializeGitHubRepository() { | ||
return mockInitializeGitHubRepository; | ||
}, | ||
})); | ||
|
||
const mockRemoveSetupScripts = vi.fn(); | ||
|
||
vi.mock("../steps/removeSetupScripts.js", () => ({ | ||
get removeSetupScripts() { | ||
return mockRemoveSetupScripts; | ||
}, | ||
})); | ||
|
||
const mockResetGitTags = vi.fn(); | ||
|
||
vi.mock("../steps/resetGitTags.js", () => ({ | ||
get resetGitTags() { | ||
return mockResetGitTags; | ||
}, | ||
})); | ||
|
||
const mockRunCleanup = vi.fn(); | ||
|
||
vi.mock("../steps/runCleanup.js", () => ({ | ||
get runCleanup() { | ||
return mockRunCleanup; | ||
}, | ||
})); | ||
|
||
const mockUninstallPackages = vi.fn(); | ||
|
||
vi.mock("../steps/uninstallPackages.js", () => ({ | ||
get uninstallPackages() { | ||
return mockUninstallPackages; | ||
}, | ||
})); | ||
|
||
const optionsBase = {} as Options; | ||
|
||
describe("initializeWithOptions", () => { | ||
it("runs addOwnerAsAllContributor when excludeAllContributors is false", async () => { | ||
const options = { | ||
...optionsBase, | ||
excludeAllContributors: false, | ||
}; | ||
|
||
await initializeWithOptions({ | ||
github: undefined, | ||
options, | ||
}); | ||
|
||
expect(mockAddOwnerAsAllContributor).toHaveBeenCalledWith(options); | ||
}); | ||
|
||
it("does not run addOwnerAsAllContributor when excludeAllContributors is true", async () => { | ||
const options = { | ||
...optionsBase, | ||
excludeAllContributors: true, | ||
}; | ||
|
||
await initializeWithOptions({ | ||
github: undefined, | ||
options, | ||
}); | ||
|
||
expect(mockAddOwnerAsAllContributor).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("runs initializeGitHubRepository when github is truthy", async () => { | ||
const github = { | ||
octokit: {}, | ||
} as GitHub; | ||
|
||
await initializeWithOptions({ | ||
github, | ||
options: optionsBase, | ||
}); | ||
|
||
expect(mockInitializeGitHubRepository).toHaveBeenCalledWith( | ||
github.octokit, | ||
optionsBase, | ||
); | ||
}); | ||
|
||
it("does not run initializeGitHubRepository when github is falsy", async () => { | ||
const options = { | ||
...optionsBase, | ||
excludeAllContributors: true, | ||
}; | ||
|
||
await initializeWithOptions({ | ||
github: undefined, | ||
options, | ||
}); | ||
|
||
expect(mockInitializeGitHubRepository).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("runs removeSetupScripts when skipRemoval is false", async () => { | ||
const options = { | ||
...optionsBase, | ||
skipRemoval: false, | ||
}; | ||
|
||
await initializeWithOptions({ | ||
github: undefined, | ||
options, | ||
}); | ||
|
||
expect(mockRemoveSetupScripts).toHaveBeenCalled(); | ||
}); | ||
|
||
it("does not run removeSetupScripts when skipRemoval is true", async () => { | ||
const options = { | ||
...optionsBase, | ||
skipRemoval: true, | ||
}; | ||
|
||
await initializeWithOptions({ | ||
github: undefined, | ||
options, | ||
}); | ||
|
||
expect(mockRemoveSetupScripts).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("runs uninstallPackages when skipUninstall is false", async () => { | ||
const options = { | ||
...optionsBase, | ||
offline: true, | ||
skipUninstall: false, | ||
}; | ||
|
||
await initializeWithOptions({ | ||
github: undefined, | ||
options, | ||
}); | ||
|
||
expect(mockUninstallPackages).toHaveBeenCalledWith(options.offline); | ||
}); | ||
|
||
it("does not run uninstallPackages when skipUninstall is true", async () => { | ||
const options = { | ||
...optionsBase, | ||
skipUninstall: true, | ||
}; | ||
|
||
await initializeWithOptions({ | ||
github: undefined, | ||
options, | ||
}); | ||
|
||
expect(mockUninstallPackages).not.toHaveBeenCalled(); | ||
}); | ||
}); |
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