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

fix: Allow prefixUrl to work #370

Merged
merged 3 commits into from
Jul 19, 2024
Merged

fix: Allow prefixUrl to work #370

merged 3 commits into from
Jul 19, 2024

Conversation

Mnkras
Copy link

@Mnkras Mnkras commented Aug 1, 2023

This is most certainly a hack, but I was trying to maintain the current behaviour.
#369

I can also port this to main

@@ -175,7 +180,7 @@ describe('fetch request', () => {

});

it.only("sends own content-type header", async () => {
it("sends own content-type header", async () => {
Copy link
Author

Choose a reason for hiding this comment

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

the only meant none of the other tests in this file ran

Copy link
Owner

Choose a reason for hiding this comment

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

🤦‍♂️ thanks for fixing this

@Mnkras Mnkras changed the title fix: Allow prefixUrl to work #369 fix: Allow prefixUrl to work Aug 1, 2023
Copy link
Owner

@alexghr alexghr 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. Thanks for the contribution!

I'm going to have a think about disabling the test that verifies merging query parameters because I think that functionality is really important to keep.

@@ -175,7 +180,7 @@ describe('fetch request', () => {

});

it.only("sends own content-type header", async () => {
it("sends own content-type header", async () => {
Copy link
Owner

Choose a reason for hiding this comment

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

🤦‍♂️ thanks for fixing this

src/lib/fetch.ts Outdated Show resolved Hide resolved
Comment on lines 51 to 57
it('merges query string parameters', async () => {
expect.assertions(1);
interceptor.intercept('/', 'get').query({ foo: '123', bar: '456' }).reply(200);

const fetch = createFetch(got.extend({ searchParams: { bar: '456' } }));
await assert200(fetch(url('/', { foo: '123' })));
});
Copy link
Owner

Choose a reason for hiding this comment

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

I think disabling this might be problematic because I'd expect people to use it to add access tokens/API keys as a base on their clients 🤔

Copy link
Owner

@alexghr alexghr left a comment

Choose a reason for hiding this comment

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

How about doing the URL parsing like below and restoring the code that sends searchParams as a separate entity, restoring the deleted test and adding an extra test for prefixUrl + search params merging:

it("merges query string parameters with a prefix URL", async () => {
  expect.assertions(1);
  interceptor
    .intercept("/", "get")
    .query({ foo: "123", bar: "456" })
    .reply(200);

  const fetch = createFetch(
    got.extend({
      prefixUrl: ORIGIN,
      searchParams: { bar: "456" },
    })
  );

  await assert200(fetch("/?foo=123"));
});

src/lib/fetch.ts Outdated Show resolved Hide resolved
Mnkras and others added 2 commits August 8, 2023 12:51
Co-authored-by: Alex Gherghisan <alexghr@users.noreply.github.com>
@Mnkras Mnkras requested a review from alexghr August 8, 2023 20:11
@Mnkras
Copy link
Author

Mnkras commented Aug 14, 2023

@alexghr Just wanted to check in on this

@Mnkras
Copy link
Author

Mnkras commented Sep 4, 2023

@alexghr checking in again, would love to get this merged

@alexghr alexghr merged commit c27a53a into alexghr:4.x Jul 19, 2024
github-actions bot pushed a commit that referenced this pull request Jul 19, 2024
## [4.0.5](v4.0.4...v4.0.5) (2024-07-19)

### Bug Fixes

* Allow prefixUrl to work ([#370](#370)) ([c27a53a](c27a53a))
Copy link

🎉 This PR is included in version 4.0.5 🎉

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants