Unverified Commit d654ccfc authored by Hendrik Liebau's avatar Hendrik Liebau Committed by GitHub

Migrate `withRouter` from an integration to an e2e test (#67721)

There's apparently some interference with other tests when running the
`withRouter` integration test in the CI, which leads to [frequent test
failures](https://app.datadoghq.com/ci/test-runs?query=test_level%3Atest%20env%3Aci%20%40git.repository.id%3Agithub.com%2Fvercel%2Fnext.js%20%40test.service%3Anextjs%20%40test.suite%3A%2AwithRouter%2A%20%40test.status%3Afail&agg_m=count&agg_m_source=base&agg_t=count&currentTab=overview&eventStack=&fromUser=false&index=citest&start=1713009743249&end=1720785743249&paused=true).

In lieu of identifying the interference source, we can refactor the test
to an e2e test. This should also fix the flakiness.

closes
[NDX-64](https://linear.app/vercel/issue/NDX-64/investigate-flakiness-of-testintegrationwith-router)
closes #67706
parent 720c2214
/* eslint-env jest */
import {
assertHasRedbox,
findPort,
getRedboxHeader,
killApp,
launchApp,
nextBuild,
nextStart,
} from 'next-test-utils'
import webdriver from 'next-webdriver'
import { join } from 'path'
import { nextTestSetup } from 'e2e-utils'
import { assertHasRedbox, getRedboxHeader } from 'next-test-utils'
describe('withRouter', () => {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
const { next, isTurbopack, isNextDev } = nextTestSetup({
files: __dirname,
})
;(isTurbopack && isNextDev ? describe.skip : describe)(
'production mode',
() => {
const appDir = join(__dirname, '../')
let appPort
let app
beforeAll(async () => {
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))
it('allows observation of navigation events using withRouter', async () => {
const browser = await webdriver(appPort, '/a')
const browser = await next.browser('/a')
await browser.waitForElementByCss('#page-a')
let activePage = await browser.elementByCss('.active').text()
......@@ -40,12 +21,10 @@ describe('withRouter', () => {
activePage = await browser.elementByCss('.active').text()
expect(activePage).toBe('Bar')
await browser.close()
})
it('allows observation of navigation events using top level Router', async () => {
const browser = await webdriver(appPort, '/a')
const browser = await next.browser('/a')
await browser.waitForElementByCss('#page-a')
let activePage = await browser
......@@ -60,12 +39,10 @@ describe('withRouter', () => {
.elementByCss('.active-top-level-router')
.text()
expect(activePage).toBe('Bar')
await browser.close()
})
it('allows observation of navigation events using top level Router deprecated behavior', async () => {
const browser = await webdriver(appPort, '/a')
const browser = await next.browser('/a')
await browser.waitForElementByCss('#page-a')
let activePage = await browser
......@@ -80,33 +57,19 @@ describe('withRouter', () => {
.elementByCss('.active-top-level-router-deprecated-behavior')
.text()
expect(activePage).toBe('Bar')
await browser.close()
})
}
)
})
describe('withRouter SSR', () => {
let server
let port
beforeAll(async () => {
port = await findPort()
server = await launchApp(join(__dirname, '..'), port, {
env: { __NEXT_TEST_WITH_DEVTOOL: 1 },
if (isNextDev) {
describe('SSR', () => {
it('should show an error when trying to use router methods during SSR', async () => {
const browser = await next.browser('/router-method-ssr')
await assertHasRedbox(browser)
expect(await getRedboxHeader(browser)).toMatch(
`No router instance found. you should only use "next/router" inside the client side of your app. https://`
)
})
})
})
afterAll(async () => {
await killApp(server)
})
it('should show an error when trying to use router methods during SSR', async () => {
const browser = await webdriver(port, '/router-method-ssr')
await assertHasRedbox(browser)
expect(await getRedboxHeader(browser)).toMatch(
`No router instance found. you should only use "next/router" inside the client side of your app. https://`
)
await browser.close()
})
}
})
......@@ -15257,18 +15257,6 @@
"flakey": [],
"runtimeError": false
},
"test/integration/with-router/test/index.test.js": {
"passed": [
"withRouter SSR should show an error when trying to use router methods during SSR",
"withRouter production mode allows observation of navigation events using top level Router",
"withRouter production mode allows observation of navigation events using top level Router deprecated behavior",
"withRouter production mode allows observation of navigation events using withRouter"
],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/integration/worker-webpack5/test/index.test.js": {
"passed": [],
"failed": [],
......@@ -17308,19 +17308,6 @@
"flakey": [],
"runtimeError": false
},
"test/integration/with-router/test/index.test.js": {
"passed": [
"withRouter SSR should show an error when trying to use router methods during SSR"
],
"failed": [],
"pending": [
"withRouter production mode allows observation of navigation events using top level Router",
"withRouter production mode allows observation of navigation events using top level Router deprecated behavior",
"withRouter production mode allows observation of navigation events using withRouter"
],
"flakey": [],
"runtimeError": false
},
"test/integration/worker-webpack5/test/index.test.js": {
"passed": [],
"failed": [],
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment