Skip to content

Commit 2ac2838

Browse files
committed
move more tests to URL from url.parse
1 parent 1ce0a7f commit 2ac2838

File tree

10 files changed

+208
-202
lines changed

10 files changed

+208
-202
lines changed

test/e2e/basepath.test.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import url from 'url'
21
import { join } from 'path'
32
import assert from 'assert'
43
import cheerio from 'cheerio'
@@ -347,7 +346,7 @@ describe('basePath', () => {
347346
redirect: 'manual',
348347
}
349348
)
350-
const { pathname } = url.parse(res.headers.get('location') || '')
349+
const { pathname } = new URL(res.headers.get('location'), 'http://n')
351350
expect(pathname).toBe(`${basePath}/somewhere-else`)
352351
expect(res.status).toBe(307)
353352
const text = await res.text()
@@ -379,7 +378,7 @@ describe('basePath', () => {
379378
redirect: 'manual',
380379
}
381380
)
382-
const { pathname } = url.parse(res.headers.get('location') || '')
381+
const { pathname } = new URL(res.headers.get('location'), 'http://n')
383382
expect(pathname).toBe('/another-destination')
384383
expect(res.status).toBe(307)
385384
const text = await res.text()
@@ -584,7 +583,7 @@ describe('basePath', () => {
584583
{ redirect: 'manual' }
585584
)
586585
expect(res.status).toBe(308)
587-
const { pathname } = new URL(res.headers.get('location'))
586+
const { pathname } = new URL(res.headers.get('location'), 'http://n')
588587
expect(pathname).toBe(`${basePath}/hello`)
589588
const text = await res.text()
590589
expect(text).toContain(`${basePath}/hello`)
@@ -598,7 +597,7 @@ describe('basePath', () => {
598597
{ redirect: 'manual' }
599598
)
600599
expect(res.status).toBe(308)
601-
const { pathname } = new URL(res.headers.get('location'))
600+
const { pathname } = new URL(res.headers.get('location'), 'http://n')
602601
expect(pathname).toBe(`${basePath}`)
603602
const text = await res.text()
604603
expect(text).toContain(`${basePath}`)
@@ -756,14 +755,14 @@ describe('basePath', () => {
756755
it('should have correct href for a link', async () => {
757756
const browser = await webdriver(next.url, `${basePath}/hello`)
758757
const href = await browser.elementByCss('a').getAttribute('href')
759-
const { pathname } = url.parse(href)
758+
const { pathname } = new URL(href, 'http://n')
760759
expect(pathname).toBe(`${basePath}/other-page`)
761760
})
762761

763762
it('should have correct href for a link to /', async () => {
764763
const browser = await webdriver(next.url, `${basePath}/link-to-root`)
765764
const href = await browser.elementByCss('#link-back').getAttribute('href')
766-
const { pathname } = url.parse(href)
765+
const { pathname } = new URL(href, 'http://n')
767766
expect(pathname).toBe(`${basePath}`)
768767
})
769768

test/integration/custom-routes-i18n-index-redirect/test/index.test.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* eslint-env jest */
22

3-
import url from 'url'
43
import http from 'http'
54
import { join } from 'path'
65
import {
@@ -34,13 +33,9 @@ const runTests = () => {
3433
if (dest) {
3534
const text = await res.text()
3635
expect(text).toEqual(dest)
37-
if (dest.startsWith('/')) {
38-
const parsed = url.parse(res.headers.get('location'))
39-
expect(parsed.pathname).toBe(dest)
40-
expect(parsed.query).toBe(null)
41-
} else {
42-
expect(res.headers.get('location')).toBe(dest)
43-
}
36+
const parsed = new URL(res.headers.get('location'), 'http://n')
37+
expect(parsed.pathname).toBe(dest)
38+
expect(Object.fromEntries(parsed.searchParams)).toEqual({})
4439
}
4540
}
4641
})

test/integration/custom-routes-i18n/test/index.test.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* eslint-env jest */
22

3-
import url from 'url'
43
import http from 'http'
54
import { join } from 'path'
65
import cheerio from 'cheerio'
@@ -41,13 +40,9 @@ const runTests = () => {
4140
if (dest) {
4241
const text = await res.text()
4342
expect(text).toEqual(dest)
44-
if (dest.startsWith('/')) {
45-
const parsed = url.parse(res.headers.get('location'))
46-
expect(parsed.pathname).toBe(dest)
47-
expect(parsed.query).toBe(null)
48-
} else {
49-
expect(res.headers.get('location')).toBe(dest)
50-
}
43+
const parsed = new URL(res.headers.get('location'), 'http://n')
44+
expect(parsed.pathname).toBe(dest)
45+
expect(Object.fromEntries(parsed.searchParams)).toEqual({})
5146
}
5247
}
5348
})

0 commit comments

Comments
 (0)