File size: 1,344 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
import { nextTestSetup } from 'e2e-utils'
import fs from 'fs-extra'
import { assertNoRedbox } from 'next-test-utils'
import path from 'path'

describe('repeated-dev-edits', () => {
  const { next } = nextTestSetup({
    files: __dirname,
  })
  // Recommended for tests that check HTML. Cheerio is a HTML parser that has a jQuery like API.
  it('should not break the hydration ', async () => {
    const browser = await next.browser('/')
    expect(await browser.elementByCss('p').text()).toBe('version-1')

    const pagePath = 'pages/index.tsx'
    const pageContent = String(
      await fs.readFile(path.join(__dirname, pagePath))
    )

    await next.patchFile(
      pagePath,
      pageContent.replaceAll('version-1', 'version-2')
    )
    await browser.waitForElementByCss('#version-2')
    expect(await browser.elementByCss('p').text()).toBe('version-2')

    // Verify no hydration mismatch:
    await assertNoRedbox(browser)

    await next.patchFile(
      pagePath,
      pageContent.replaceAll('version-1', 'version-3')
    )
    await browser.waitForElementByCss('#version-3')
    expect(await browser.elementByCss('p').text()).toBe('version-3')

    // Verify no hydration mismatch:
    await assertNoRedbox(browser)

    await browser.refresh()

    // Verify no hydration mismatch:
    await assertNoRedbox(browser)
  })
})