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: use native fetch with mock server #702

Merged
merged 14 commits into from
Jul 10, 2024
Merged

Conversation

Uzlopak
Copy link
Contributor

@Uzlopak Uzlopak commented Jun 27, 2024

needs #700

Copy link

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@wolfy1339 wolfy1339 added the Type: Maintenance Any dependency, housekeeping, and clean up Issue or PR label Jun 27, 2024
@Uzlopak Uzlopak changed the title WIP: Improve tests Improve tests Jul 5, 2024
@Uzlopak Uzlopak marked this pull request as ready for review July 5, 2024 09:41
@Uzlopak
Copy link
Contributor Author

Uzlopak commented Jul 8, 2024

@gr2m
@wolfy1339

ready for review ;)

@wolfy1339
Copy link
Member

Can you explain what this PR does? How is it improving tests?

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Jul 8, 2024

It uses tests, which use the native fetch implementation, thus avoiding that our tests are pure mocks and giving use confidence, that native fetch really works with our implementation.I could actually implement it differently and we could test e.g. node-fetch@v2 too.

@gr2m
Copy link
Contributor

gr2m commented Jul 10, 2024

we could test e.g. node-fetch@v2 too

let's not do that 😅

Copy link
Contributor

@gr2m gr2m left a comment

Choose a reason for hiding this comment

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

I like it 👍🏼 just a few nits

Copy link
Contributor

Choose a reason for hiding this comment

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

can you stick to the dash filename convention?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ofc :)

Comment on lines 56 to 72
it("should error when globalThis.fetch is undefined", async () => {
expect.assertions(1);

const originalFetch = globalThis.fetch;
// @ts-expect-error force undefined to mimic older node version
globalThis.fetch = undefined;

try {
await request("GET /orgs/me");
} catch (error) {
expect(error.message).toEqual(
"fetch is not set. Please pass a fetch implementation as new Octokit({ request: { fetch }}). Learn more at https://github.com/octokit/octokit.js/#fetch-missing",
);
} finally {
globalThis.fetch = originalFetch;
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

is vitest running tests in parallel? This one needs to run alone to avoid side effects

Copy link
Contributor Author

Choose a reason for hiding this comment

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

extracted test to separate file to ensure it is run alone ;)

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Jul 10, 2024

@gr2m

Done :)

@gr2m gr2m changed the title Improve tests test: use native fetch with mock server Jul 10, 2024
Copy link
Contributor

@gr2m gr2m left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@wolfy1339 do you have any more questions/concerns?

@wolfy1339 wolfy1339 merged commit af8ef43 into octokit:main Jul 10, 2024
6 checks passed
Copy link

🎉 This issue has been resolved in version 9.1.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released Type: Maintenance Any dependency, housekeeping, and clean up Issue or PR
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants