Files
LeahandGitHub 60f0837b67 refactor(tests): make chain more "correct" (#51728)
### Why?

I really dislike the way `.chain` works right now, it shouldn't mutate
the `BrowserInterface`, this PR changes it so it's just a pure chain
without weird side effects.

One example with the current version (before this PR):
```
const el = browser.elementByCss('#version-2')
await el.text()
// throws
await el.text()
```

### Additional Changes

- removes selenium (which is completely unused)
- updates playwright
- makes the playwright tracing not error all the time
2024-02-14 20:14:24 +01:00

49 lines
1.4 KiB
TypeScript

import { createNextDescribe } from 'e2e-utils'
import fs from 'fs-extra'
import { hasRedbox } from 'next-test-utils'
import path from 'path'
createNextDescribe(
'repeated-dev-edits',
{
files: __dirname,
},
({ next }) => {
// 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:
expect(await hasRedbox(browser)).toBeFalse()
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:
expect(await hasRedbox(browser)).toBeFalse()
await browser.refresh()
// Verify no hydration mismatch:
expect(await hasRedbox(browser)).toBeFalse()
})
}
)