-
-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import {URL} from 'url'; | ||
import fetch, {Headers} from 'node-fetch'; | ||
|
||
global.window = { | ||
fetch, | ||
Headers | ||
}; | ||
global.URL = URL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import test from 'ava'; | ||
import createTestServer from 'create-test-server'; | ||
import ky from '..'; | ||
|
||
test('prefixUrl option', async t => { | ||
const server = await createTestServer(); | ||
server.get('/', (request, response) => { | ||
if (request.query.page === '/https://cat.com/') { | ||
response.end('meow'); | ||
return; | ||
} | ||
response.end('zebra'); | ||
}); | ||
server.get('/api/unicorn', (request, response) => { | ||
response.end('rainbow'); | ||
}); | ||
|
||
t.is(await ky(`${server.url}/api/unicorn`, {prefixUrl: false}).text(), 'rainbow'); | ||
t.is(await ky(`${server.url}/api/unicorn`, {prefixUrl: ''}).text(), 'rainbow'); | ||
t.is(await ky('api/unicorn', {prefixUrl: server.url}).text(), 'rainbow'); | ||
t.is(await ky('unicorn', {prefixUrl: `${server.url}/api`}).text(), 'rainbow'); | ||
t.is(await ky('unicorn', {prefixUrl: `${server.url}/api/`}).text(), 'rainbow'); | ||
t.is(await ky('', {prefixUrl: server.url}).text(), 'zebra'); | ||
t.is(await ky('', {prefixUrl: `${server.url}/`}).text(), 'zebra'); | ||
t.is(await ky('https://cat.com/', {prefixUrl: new URL(`${server.url}/?page=`)}).text(), 'meow'); | ||
t.is(await ky(new URL('https://cat.com'), {prefixUrl: `${server.url}/?page=`}).text(), 'meow'); | ||
t.is(await ky(new URL('https://cat.com'), {prefixUrl: new URL(`${server.url}/?page=`)}).text(), 'meow'); | ||
|
||
t.throws(() => { | ||
ky('/unicorn', {prefixUrl: `${server.url}/api`}); | ||
}, '`input` must not begin with a slash when using `prefixUrl`'); | ||
|
||
await server.close(); | ||
}); |