mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
Jest can run different suites in parallel, but tests within the same suite must run sequentially in the same worker. You don't want suites that are too small, because each suite requires relatively expensive repository setup, but you also don't want suites that are too large because it inhibits parallelism. This is a big problem for arewerspackyet, where many of these test cases are currently failing. Each test can take up to 4 minutes to time out, so we easily time out the entire 90 minute long test runner job. ## Test plan Tested by running all these tests in parallel with: ``` NEXT_TEST_MODE=dev HEADLESS=true node_modules/.bin/jest test/development/pages-dir/client-navigation ``` It completes in about 2m40s minutes on my machine.
99 lines
3.3 KiB
TypeScript
99 lines
3.3 KiB
TypeScript
/* eslint-env jest */
|
|
|
|
import path from 'path'
|
|
import { nextTestSetup } from 'e2e-utils'
|
|
import { retry } from 'next-test-utils'
|
|
|
|
describe('Client navigation with onClick action', () => {
|
|
const { next } = nextTestSetup({
|
|
files: path.join(__dirname, 'fixture'),
|
|
env: {
|
|
TEST_STRICT_NEXT_HEAD: String(true),
|
|
},
|
|
})
|
|
|
|
it('should reload the page and perform additional action', async () => {
|
|
const browser = await next.browser('/nav/on-click')
|
|
const defaultCountQuery = await browser.elementByCss('#query-count').text()
|
|
const defaultCountState = await browser.elementByCss('#state-count').text()
|
|
expect(defaultCountQuery).toBe('QUERY COUNT: 0')
|
|
expect(defaultCountState).toBe('STATE COUNT: 0')
|
|
|
|
await browser.elementByCss('#on-click-link').click()
|
|
|
|
await retry(async () => {
|
|
const countQueryAfterClicked = await browser
|
|
.elementByCss('#query-count')
|
|
.text()
|
|
const countStateAfterClicked = await browser
|
|
.elementByCss('#state-count')
|
|
.text()
|
|
expect(countQueryAfterClicked).toBe('QUERY COUNT: 1')
|
|
expect(countStateAfterClicked).toBe('STATE COUNT: 1')
|
|
})
|
|
})
|
|
|
|
it('should not reload if default was prevented', async () => {
|
|
const browser = await next.browser('/nav/on-click')
|
|
const defaultCountQuery = await browser.elementByCss('#query-count').text()
|
|
const defaultCountState = await browser.elementByCss('#state-count').text()
|
|
expect(defaultCountQuery).toBe('QUERY COUNT: 0')
|
|
expect(defaultCountState).toBe('STATE COUNT: 0')
|
|
|
|
await browser.elementByCss('#on-click-link-prevent-default').click()
|
|
|
|
await retry(async () => {
|
|
const countQueryAfterClicked = await browser
|
|
.elementByCss('#query-count')
|
|
.text()
|
|
const countStateAfterClicked = await browser
|
|
.elementByCss('#state-count')
|
|
.text()
|
|
expect(countQueryAfterClicked).toBe('QUERY COUNT: 0')
|
|
expect(countStateAfterClicked).toBe('STATE COUNT: 1')
|
|
})
|
|
|
|
await browser.elementByCss('#on-click-link').click()
|
|
|
|
await retry(async () => {
|
|
const countQueryAfterClickedAgain = await browser
|
|
.elementByCss('#query-count')
|
|
.text()
|
|
const countStateAfterClickedAgain = await browser
|
|
.elementByCss('#state-count')
|
|
.text()
|
|
expect(countQueryAfterClickedAgain).toBe('QUERY COUNT: 1')
|
|
expect(countStateAfterClickedAgain).toBe('STATE COUNT: 2')
|
|
})
|
|
})
|
|
|
|
it('should always replace the state and perform additional action', async () => {
|
|
const browser = await next.browser('/nav')
|
|
|
|
await browser.elementByCss('#on-click-link').click()
|
|
|
|
await retry(async () => {
|
|
const defaultCountQuery = await browser
|
|
.elementByCss('#query-count')
|
|
.text()
|
|
expect(defaultCountQuery).toBe('QUERY COUNT: 1')
|
|
})
|
|
|
|
await browser.elementByCss('#on-click-link').click()
|
|
|
|
await retry(async () => {
|
|
const countQueryAfterClicked = await browser
|
|
.elementByCss('#query-count')
|
|
.text()
|
|
const countStateAfterClicked = await browser
|
|
.elementByCss('#state-count')
|
|
.text()
|
|
expect(countQueryAfterClicked).toBe('QUERY COUNT: 2')
|
|
expect(countStateAfterClicked).toBe('STATE COUNT: 1')
|
|
})
|
|
|
|
// Since we replace the state, back button would simply go us back to /nav
|
|
await browser.back().waitForElementByCss('.nav-home')
|
|
})
|
|
})
|