-
Notifications
You must be signed in to change notification settings - Fork 663
test(utils): add fallback and error-handling tests for getGitHubToken #1438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,6 @@ | ||||||||||||||||||||
| import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"; | ||||||||||||||||||||
| import fs from "fs"; | ||||||||||||||||||||
| import path from "path"; | ||||||||||||||||||||
| import { | ||||||||||||||||||||
| getRepoRoot, | ||||||||||||||||||||
| getGitHubToken, | ||||||||||||||||||||
|
|
@@ -40,6 +42,30 @@ describe("utils", () => { | |||||||||||||||||||
| "GITHUB_TOKEN environment variable is required.", | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| it("should return token when GH_TOKEN is set as a fallback", () => { | ||||||||||||||||||||
| vi.stubEnv("GITHUB_TOKEN", ""); | ||||||||||||||||||||
| vi.stubEnv("GH_TOKEN", "fallback-token"); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const result = getGitHubToken(); | ||||||||||||||||||||
| expect(result).toBe("fallback-token"); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| it("should read token from .env file if environment variables are not set", () => { | ||||||||||||||||||||
| vi.stubEnv("GITHUB_TOKEN", ""); | ||||||||||||||||||||
| vi.stubEnv("GH_TOKEN", ""); | ||||||||||||||||||||
| const envPath = path.join(process.cwd(), ".env"); | ||||||||||||||||||||
| fs.writeFileSync(envPath, "GITHUB_TOKEN=env-file-token"); | ||||||||||||||||||||
| const result = getGitHubToken(); | ||||||||||||||||||||
| expect(result).toBe("env-file-token"); | ||||||||||||||||||||
| fs.unlinkSync(envPath); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
Comment on lines
+54
to
+63
|
||||||||||||||||||||
| it("should read token from .env file if environment variables are not set", () => { | |
| vi.stubEnv("GITHUB_TOKEN", ""); | |
| vi.stubEnv("GH_TOKEN", ""); | |
| const envPath = path.join(process.cwd(), ".env"); | |
| fs.writeFileSync(envPath, "GITHUB_TOKEN=env-file-token"); | |
| const result = getGitHubToken(); | |
| expect(result).toBe("env-file-token"); | |
| fs.unlinkSync(envPath); | |
| }); |
Copilot
AI
Nov 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test expects a detailed error message matching the regex /Missing GitHub authentication token/, but the actual implementation throws "GITHUB_TOKEN environment variable is required.". This test will fail. Update the expected error message to match the actual implementation, or update the implementation to throw the expected message.
| expect(() => getGitHubToken()).toThrow(/Missing GitHub authentication token/); | |
| expect(() => getGitHubToken()).toThrow("GITHUB_TOKEN environment variable is required."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test expects
GH_TOKENfallback behavior, but the current implementation ofgetGitHubToken()only checksprocess.env.GITHUB_TOKEN. The implementation doesn't have any fallback logic to checkGH_TOKEN. Either update the implementation to support this fallback, or remove this test.