File size: 2,128 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { nextTestSetup } from 'e2e-utils'
import { check } from 'next-test-utils'
import { join } from 'node:path'

describe('deployment-id-handling disabled', () => {
  const deploymentId = Date.now() + ''
  const { next } = nextTestSetup({
    files: join(__dirname, 'app'),
    env: {
      COOKIE_SKEW: '1',
      NEXT_DEPLOYMENT_ID: 'thankyounext',
    },
  })

  it('should set set-cookie header correctly', async () => {
    const res = await next.fetch('/')
    expect(res.headers.get('set-cookie')).toBe(
      '__vdpl=thankyounext; Path=/; HttpOnly'
    )
  })

  it.each([
    { urlPath: '/' },
    { urlPath: '/pages-edge' },
    { urlPath: '/from-app' },
    { urlPath: '/from-app/edge' },
  ])(
    'should not append dpl query to all assets for $urlPath',
    async ({ urlPath }) => {
      const $ = await next.render$(urlPath)

      expect($('#deploymentId').text()).not.toBe(deploymentId)

      const scripts = Array.from($('script'))
      expect(scripts.length).toBeGreaterThan(0)

      for (const script of scripts) {
        if (script.attribs.src) {
          expect(script.attribs.src).not.toContain('dpl=' + deploymentId)
        }
      }

      const links = Array.from($('link'))
      expect(links.length).toBeGreaterThan(0)

      for (const link of links) {
        if (link.attribs.href) {
          if (link.attribs.as === 'font') {
            expect(link.attribs.href).not.toContain('dpl=' + deploymentId)
          } else {
            expect(link.attribs.href).not.toContain('dpl=' + deploymentId)
          }
        }
      }

      const browser = await next.browser(urlPath)
      const requests = []

      browser.on('request', (req) => {
        requests.push(req.url())
      })

      await browser.elementByCss('#dynamic-import').click()

      await check(
        () => (requests.length > 0 ? 'success' : JSON.stringify(requests)),
        'success'
      )

      try {
        expect(
          requests.every((item) => !item.includes('dpl=' + deploymentId))
        ).toBe(true)
      } finally {
        require('console').error('requests', requests)
      }
    }
  )
})