Skip to content

Commit

Permalink
fix: preserve params when using baseURL
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Dec 12, 2020
1 parent 7d7c9ba commit c3a63e2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"devDependencies": {
"@nuxt/h2": "^0.0.14",
"@nuxt/ufo": "^0.1.3",
"@nuxt/ufo": "^0.1.4",
"@nuxtjs/eslint-config-typescript": "latest",
"@types/flat": "latest",
"@types/jest": "latest",
Expand Down
20 changes: 12 additions & 8 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,30 @@ describe('ohmyfetch', () => {
let listener: Listener

it('setup', async () => {
const app = createApp().use('/api', req => (getParams(req.url || '')))
const app = createApp()
.use('/ok', () => 'ok')
.use('/params', req => (getParams(req.url || '')))
.use('/url', req => req.url)
listener = await listen(app)
})

afterAll(async () => {
await listener.close()
})

it('api', async () => {
expect(await $fetch('api', {
baseURL: listener.url,
params: { api: 1 }
})).toMatchObject({ api: '1' })
it('ok', async () => {
expect(await $fetch(listener.getURL('ok'))).toBe('ok')
})

it('baseURL', async () => {
expect(await $fetch('/x?foo=123', { baseURL: listener.getURL('url') })).toBe('/x?foo=123')
})

it('404', async () => {
const err: FetchError = await $fetch('404', { baseURL: listener.url }).catch(err => err)
const err: FetchError = await $fetch(listener.getURL('404'), { baseURL: listener.url }).catch(err => err)
expect(err.stack).toMatch('404 Not Found')
expect(err.data).toMatch('Not Found (404)')
expect(err.response?.data).toBe(err.data)
expect(err.request).toBe('http://localhost:3000/404')
expect(err.request).toBe(listener.getURL('404'))
})
})
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -513,10 +513,10 @@
resolved "https://registry.yarnpkg.com/@nuxt/ufo/-/ufo-0.0.3.tgz#7673a54b81c020e7aea3a9e01e09a58c494a1eca"
integrity sha512-LQkuVafVNB9+ggRF7443AX1V1rEWRs32Frk7F2qnRLf8j/SzRzxEZ99jiZqxVho72zU7NcWQ6Jy62m4fkZC6Wg==

"@nuxt/ufo@^0.1.3":
version "0.1.3"
resolved "https://registry.yarnpkg.com/@nuxt/ufo/-/ufo-0.1.3.tgz#bd6403623f441de599f52cf5bdf4ccc99476e0b9"
integrity sha512-z62gwk1m0SX7N+GWkJo8VLQiIieT0NRttz2giExUhel1iL3b773653YvFGhfTURCdOmU5rlCPsQmVgZjH5XqAg==
"@nuxt/ufo@^0.1.4":
version "0.1.4"
resolved "https://registry.yarnpkg.com/@nuxt/ufo/-/ufo-0.1.4.tgz#41967f00333821c8760f8ee71c50e37c534b7ac6"
integrity sha512-uEfXbPROYZcRbnkVS2NK2vklDpcfZOAjGaniuC4pKJAgHTx0A4f8uMC1R5BSTA8zNZAoweDc7pW6tqvu/JyIhQ==

"@nuxtjs/eslint-config-typescript@latest":
version "5.0.0"
Expand Down

0 comments on commit c3a63e2

Please sign in to comment.