-
-
Notifications
You must be signed in to change notification settings - Fork 916
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
Normalize the URL in the baseUrl
option
#579
Changes from 4 commits
7c4478a
294ee69
f2278b6
1af5cde
f074094
fbf4174
2e17859
ca78716
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 |
---|---|---|
|
@@ -22,6 +22,10 @@ test.before('setup', async () => { | |
response.end(request.url); | ||
}); | ||
|
||
s.on('/test/foobar', (request, response) => { | ||
response.end(request.url); | ||
}); | ||
|
||
s.on('/?test=it’s+ok', (request, response) => { | ||
response.end(request.url); | ||
}); | ||
|
@@ -194,6 +198,30 @@ test('allows extra keys in `hooks`', async t => { | |
await t.notThrowsAsync(() => got(`${s.url}/test`, {hooks: {extra: {}}})); | ||
}); | ||
|
||
test('baseUrl works', async t => { | ||
const instanceA = got.extend({baseUrl: `${s.url}/test`}); | ||
const {body} = await instanceA('/foobar'); | ||
t.is(body, `/test/foobar`); | ||
}); | ||
|
||
test('accepts WHATWG URL as the baseUrl option', async t => { | ||
const instanceA = got.extend({baseUrl: new URL(`${s.url}/test`)}); | ||
const {body} = await instanceA('/foobar'); | ||
t.is(body, `/test/foobar`); | ||
}); | ||
|
||
test('backslash in the end of `baseUrl` is optional', async t => { | ||
const instanceA = got.extend({baseUrl: `${s.url}/test/`}); | ||
const {body} = await instanceA('/foobar'); | ||
t.is(body, `/test/foobar`); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also add a test with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And a couple of tests where the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup |
||
|
||
test('backslash in the beginning of `url` is optional when using baseUrl', async t => { | ||
const instanceA = got.extend({baseUrl: `${s.url}/test`}); | ||
const {body} = await instanceA('foobar'); | ||
t.is(body, `/test/foobar`); | ||
}); | ||
|
||
test('throws when trying to modify baseUrl after options got normalized', async t => { | ||
const instanceA = got.create({ | ||
methods: [], | ||
|
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've split
normalize-argument.js
into two parts:preNormalize
handles all the stuff which is related with static options likebaseUrl
,followRedirect
,hooks
etc.It is used in
got.create()
to normalizedefaults.options
.normalize
doespreNormalize
+ handles all the stuff related with dynamic options likeurl
,headers
,body
etc.