-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## PR Checklist - [x] Addresses an existing open issue: fixes #878 - [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 Adds `--offline` flag that skips running scripts. That includes a timeout for `npm whoami`, as I've found that command to hang when I'm on an airplane. Also corrects a bit of the logic around adding the user as a contributor, while I'm in the area. And fixes up unit tests around that.
- Loading branch information
1 parent
7623d6a
commit 715e79d
Showing
20 changed files
with
295 additions
and
72 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
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,98 @@ | ||
import chalk from "chalk"; | ||
import { SpyInstance, beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
||
import { getGitHubUserAsAllContributor } from "./getGitHubUserAsAllContributor.js"; | ||
|
||
const mock$ = vi.fn(); | ||
|
||
vi.mock("execa", () => ({ | ||
get $() { | ||
return mock$; | ||
}, | ||
})); | ||
|
||
let mockConsoleWarn: SpyInstance; | ||
|
||
const owner = "TestOwner"; | ||
|
||
describe("getGitHubUserAsAllContributor", () => { | ||
beforeEach(() => { | ||
mockConsoleWarn = vi | ||
.spyOn(console, "warn") | ||
.mockImplementation(() => undefined); | ||
}); | ||
|
||
it("defaults to owner with a log when options.offline is true", async () => { | ||
const actual = await getGitHubUserAsAllContributor({ | ||
offline: true, | ||
owner, | ||
}); | ||
|
||
expect(actual).toEqual(owner); | ||
expect(mockConsoleWarn).toHaveBeenCalledWith( | ||
chalk.gray( | ||
`Skipping populating all-contributors contributions for TestOwner because in --offline mode.`, | ||
), | ||
); | ||
}); | ||
|
||
it("uses the user from gh api user when it succeeds", async () => { | ||
const login = "gh-api-user"; | ||
|
||
mock$.mockResolvedValueOnce({ | ||
stdout: JSON.stringify({ login }), | ||
}); | ||
|
||
await getGitHubUserAsAllContributor({ owner }); | ||
|
||
expect(mockConsoleWarn).not.toHaveBeenCalled(); | ||
expect(mock$.mock.calls).toMatchInlineSnapshot(` | ||
[ | ||
[ | ||
[ | ||
"gh api user", | ||
], | ||
], | ||
[ | ||
[ | ||
"npx -y [email protected] add ", | ||
" ", | ||
"", | ||
], | ||
"gh-api-user", | ||
"code,content,doc,ideas,infra,maintenance,projectManagement,tool", | ||
], | ||
] | ||
`); | ||
}); | ||
|
||
it("defaults the user to the owner when gh api user fails", async () => { | ||
mock$.mockRejectedValueOnce({}); | ||
|
||
await getGitHubUserAsAllContributor({ owner }); | ||
|
||
expect(mockConsoleWarn).toHaveBeenCalledWith( | ||
chalk.gray( | ||
`Couldn't authenticate GitHub user, falling back to the provided owner name '${owner}'.`, | ||
), | ||
); | ||
expect(mock$.mock.calls).toMatchInlineSnapshot(` | ||
[ | ||
[ | ||
[ | ||
"gh api user", | ||
], | ||
], | ||
[ | ||
[ | ||
"npx -y [email protected] add ", | ||
" ", | ||
"", | ||
], | ||
"TestOwner", | ||
"code,content,doc,ideas,infra,maintenance,projectManagement,tool", | ||
], | ||
] | ||
`); | ||
}); | ||
}); |
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
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
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
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
Oops, something went wrong.