File size: 1,918 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import webdriver from 'next-webdriver'
import { check } from 'next-test-utils'
import { nextTestSetup } from 'e2e-utils'

describe('basePath query/hash handling', () => {
  const basePath = '/docs'
  const { next } = nextTestSetup({
    files: __dirname,
    nextConfig: {
      basePath,
      onDemandEntries: {
        // Make sure entries are not getting disposed.
        maxInactiveAge: 1000 * 60 * 60,
      },
    },
  })

  it.each([
    { hash: '#hello?' },
    { hash: '#?' },
    { hash: '##' },
    { hash: '##?' },
    { hash: '##hello?' },
    { hash: '##hello' },
    { hash: '#hello?world' },
    { search: '?hello=world', hash: '#a', query: { hello: 'world' } },
    { search: '?hello', hash: '#a', query: { hello: '' } },
    { search: '?hello=', hash: '#a', query: { hello: '' } },
  ])(
    'is correct during query updating $hash $search',
    async ({ hash, search, query }) => {
      const browser = await webdriver(
        next.url,
        `${basePath}${search || ''}${hash || ''}`
      )

      await check(
        () =>
          browser.eval('window.next.router.isReady ? "ready" : "not ready"'),
        'ready'
      )
      expect(await browser.eval('window.location.pathname')).toBe(basePath)
      expect(await browser.eval('window.location.search')).toBe(search || '')
      expect(await browser.eval('window.location.hash')).toBe(hash || '')
      expect(await browser.eval('next.router.pathname')).toBe('/')
      expect(
        JSON.parse(await browser.eval('JSON.stringify(next.router.query)'))
      ).toEqual(query || {})
    }
  )

  it('should work with hash links', async () => {
    const browser = await webdriver(next.url, `${basePath}/hello`)
    await browser.elementByCss('#hashlink').click()
    const url = new URL(await browser.eval(() => window.location.href))
    expect(url.pathname).toBe(`${basePath}/hello`)
    expect(url.hash).toBe('#hashlink')
  })
})