Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate withRouter from an integration to an e2e test #67721

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,35 +1,16 @@
/* 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()
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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()
})
}
})
12 changes: 0 additions & 12 deletions test/turbopack-build-tests-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down
13 changes: 0 additions & 13 deletions test/turbopack-dev-tests-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down
Loading