File size: 1,698 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
import { join } from 'path'
import { nextTestSetup } from 'e2e-utils'
import { check, retry } from 'next-test-utils'

describe('asset-prefix', () => {
  const { next } = nextTestSetup({
    files: join(__dirname, 'fixture'),
  })

  it('should load the app properly without reloading', async () => {
    const browser = await next.browser('/')
    await browser.eval(`window.__v = 1`)

    expect(await browser.elementByCss('#text').text()).toBe('Hello World')

    await check(async () => {
      const logs = await browser.log()
      const hasError = logs.some((log) =>
        log.message.includes('Failed to fetch')
      )
      return hasError ? 'error' : 'success'
    }, 'success')

    expect(await browser.eval(`window.__v`)).toBe(1)
  })

  it('should navigate to another page without hard navigating', async () => {
    const browser = await next.browser('/')
    await browser.eval(`window.__v = 1`)
    await browser.elementByCss('[href="/page2"]').click()
    await retry(async () => {
      expect(await browser.elementByCss('div').text()).toBe('Page 2')
    })
    expect(await browser.eval(`window.__v`)).toBe(1)
  })

  describe('rewrites', () => {
    it('rewrites that do not start with assetPrefix should still work', async () => {
      const res = await next.fetch('/not-custom-asset-prefix/api/test-json', {})
      expect(res.status).toBe(200)
      expect(await res.text()).toBe('{"message":"test"}')
    })

    it('should respect rewrites that start with assetPrefix', async () => {
      const res = await next.fetch('/custom-asset-prefix/api/test-json', {})
      expect(res.status).toBe(200)
      expect(await res.text()).toBe('{"message":"test"}')
    })
  })
})