Skip to content
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

test(cli): improve test coverage in cli api handling #1408

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

spirulence
Copy link
Contributor

@spirulence spirulence commented Dec 10, 2024

📚 Description

This PR improves the unit test coverage of the cli application. New tests for apps/cli/src/api.ts are included.

Previous code coverage report (commit f3fc6be ) npx vitest --coverage
CleanShot 2024-12-10 at 15 20 51

New coverage report
CleanShot 2024-12-10 at 15 20 23

🔗 Linked Issue

Makes progress on #1407

🧪 Test Plan

Test only change. New tests attached. Axios and Octokit dependencies mocked where applicable.

Line 23 in api.ts appears to have an unreachable branch which could be addressed in a follow-on effort.

📄 Documentation to Update

No documentation identified.

Copy link

vercel bot commented Dec 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
codemod ⬜️ Ignored (Inspect) Visit Preview Dec 11, 2024 5:15pm

Copy link

vercel bot commented Dec 10, 2024

@spirulence is attempting to deploy a commit to the Codemod Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

pkg-pr-new bot commented Dec 10, 2024

Open in Stackblitz

npm i https://pkg.pr.new/codemod@1408

commit: 4b4d523

Copy link
Contributor Author

@spirulence spirulence left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some self-review

vi.clearAllMocks();

// Reset process.env
process.env.BACKEND_URL = "http://api.example.com";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably need to find another solution for this.

({
request: mockRequestMethod,
// biome-ignore lint/suspicious/noExplicitAny: This is a mock implementation
}) as any,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this. But a concise way to bring in the rest of the Octokit implementation eluded me today

() =>
({
request: mockRequestMethod,
// biome-ignore lint/suspicious/noExplicitAny: This is a mock implementation
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same complaint here about Octokit mocking

() =>
({
request: mockRequestMethod,
// biome-ignore lint/suspicious/noExplicitAny: This is a mock implementation
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same complaint about octokit mocking

() =>
({
request: mockRequestMethod,
// biome-ignore lint/suspicious/noExplicitAny: This is a mock implementation
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same complaint about Octokit mocking

Copy link
Member

@mohebifar mohebifar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks! 🎉 Just one comment.

apps/cli/test/api.test.ts Outdated Show resolved Hide resolved
@spirulence
Copy link
Contributor Author

@mohab-sameh I got caught off-guard here by the fact that pnpm lint-staged did not catch my unused variables in testing! nice catch. may be room for improvement there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants