-
Notifications
You must be signed in to change notification settings - Fork 338
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: remove deprecated usage of parse #1959
Conversation
@@ -42,11 +42,11 @@ describe('User Http Client', () => { | |||
jest.spyOn(client, 'request'); | |||
}); | |||
|
|||
afterAll(() => jest.clearAllMocks()); |
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.
why was this moved into the inner scopes?
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.
I thought that previous mock's call history should be cleared before each describe
started .
If second describe
pass, the third one always pass because both have same test
body.
describe('when calling a method with overridden url', () => {
beforeAll(() => client.get('/pet', { baseUrl: 'https://www.google.it' }));
afterAll(() => jest.clearAllMocks());
test('should call the mocker with the replaced full url', () => {
expect(mock.default).toBeCalledWith({ // <-- same body
resource: expect.anything(),
input: expect.objectContaining({
data: expect.objectContaining({
url: expect.objectContaining({
baseUrl: 'https://www.google.it',
path: '/pet',
}),
}),
}),
config: expect.anything(),
});
});
});
describe('when calling a method with a full url', () => {
beforeAll(() => client.get('https://www.google.it/pet'));
afterAll(() => jest.clearAllMocks());
test('should call the mocker with the replaced full url', () => {
expect(mock.default).toBeCalledWith({ // <-- same body
resource: expect.anything(),
input: expect.objectContaining({
data: expect.objectContaining({
url: expect.objectContaining({
baseUrl: 'https://www.google.it',
path: '/pet',
}),
}),
}),
config: expect.anything(),
});
});
});
})
packages/http/src/client.ts
Outdated
path: parsedUrl.pathname, | ||
query: parseQueryString(parsedUrl.query || '') as IHttpNameValues, | ||
query: parseQueryString(parsedUrl.search.substring(1)) as IHttpNameValues, |
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.
is search
guaranteed not to be undefined?
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.
Yes, I found that it is always string even though there are no query string in URL.
but I think it is better to make code more defensive 😄
@@ -4,11 +4,12 @@ import { assertResolvesRight, assertResolvesLeft } from '@stoplight/prism-core/s | |||
import { keyBy, mapValues } from 'lodash'; | |||
import { hopByHopHeaders } from '../resources'; | |||
import { DiagnosticSeverity, Dictionary } from '@stoplight/types'; | |||
import { format } from 'url'; |
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.
i'm not seeing any functional changes here
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.
It is my mistake :)
packages/http/src/forwarder/index.ts
Outdated
const url = format({ | ||
...partialUrl, | ||
host: partialUrl.host, |
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.
why include this if is already spread in from line 46?
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.
Since partialUrl.host
is a getter not property. It is not copied properly.
Come to think of it, it would be better to use Object.assign
instead of spread. :)
b2e91f8
to
978d10d
Compare
1980973
to
53a45ae
Compare
The code looks good! Can you resolve the docs conflicts? We'll be good to go then! |
bb0363e
to
3fbc964
Compare
Summary
Replace depreacted parse function to WHATWG URL.
Checklist