Skip to content

Commit 4d9ce8c

Browse files
committed
test: Fix basePath cases
1 parent 9d741d0 commit 4d9ce8c

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

packages/e2e/next/cypress/e2e/persist-across-navigation.cy.js packages/e2e/next/cypress/e2e/persist-across-navigation.cy.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
/// <reference types="cypress" />
1+
import { expectPathname } from 'e2e-shared/lib/assertions'
22

33
it('Persists search params across navigation using a generated Link href', () => {
44
cy.visit('/app/persist-across-navigation/a')
55
cy.contains('#hydration-marker', 'hydrated').should('be.hidden')
66
cy.get('input[type=text]').type('foo', { delay: 0 })
77
cy.get('input[type=checkbox]').check()
88
cy.get('a').click()
9-
cy.location('pathname').should(
10-
'eq',
11-
`${Cypress.env('basePath')}/app/persist-across-navigation/b`
12-
)
9+
expectPathname('/app/persist-across-navigation/b')
1310
cy.location('search').should('eq', '?q=foo&checked=true')
1411
cy.get('input[type=text]').should('have.value', 'foo')
1512
cy.get('input[type=checkbox]').should('be.checked')

packages/e2e/next/cypress/e2e/routing-tour.cy.js packages/e2e/next/cypress/e2e/routing-tour.cy.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
/// <reference types="cypress" />
1+
import { expectPathname } from 'e2e-shared/lib/assertions'
22

33
function waitForHydration() {
44
cy.contains('#hydration-marker', 'hydrated').should('be.hidden')
55
cy.wait(50)
66
}
77

8-
function expectPathname(pathname) {
9-
cy.location('pathname').should('eq', Cypress.env('basePath') + pathname)
10-
}
11-
128
describe('routing-tour', () => {
139
it('server -> a', () => {
1410
cy.visit('/app/routing-tour/start/server')

packages/e2e/shared/lib/assertions.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export function expectPathname(pathname: string) {
2+
const basePath = Cypress.env('basePath')
3+
const expected = basePath === undefined ? pathname : basePath + pathname
4+
cy.location('pathname').should('eq', expected)
5+
}

packages/e2e/shared/specs/flush-after-navigate.cy.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createTest } from '../create-test'
2+
import { expectPathname } from '../lib/assertions'
23
import { getUrl } from './flush-after-navigate.defs'
34

45
export const testFlushAfterNavigate = createTest(
@@ -9,7 +10,7 @@ export const testFlushAfterNavigate = createTest(
910
cy.contains('#hydration-marker', 'hydrated').should('be.hidden')
1011
cy.get('#test').click()
1112
cy.get('a').click()
12-
cy.location('pathname').should('eq', path + '/end')
13+
expectPathname(path + '/end')
1314
cy.get('#client-state').should('have.text', 'pass')
1415
cy.location('search').should('be.empty')
1516
cy.location('search').should('eq', '?test=pass') // Then it flushes
@@ -19,7 +20,7 @@ export const testFlushAfterNavigate = createTest(
1920
cy.contains('#hydration-marker', 'hydrated').should('be.hidden')
2021
cy.get('#test').click()
2122
cy.get('a').click()
22-
cy.location('pathname').should('eq', path + '/end')
23+
expectPathname(path + '/end')
2324
cy.get('#client-state').should('have.text', 'pass')
2425
cy.location('search').should('eq', '?test=nav')
2526
cy.location('search').should('eq', '?test=pass') // Then it flushes
@@ -30,7 +31,7 @@ export const testFlushAfterNavigate = createTest(
3031
cy.get('#preflush').click() // Trigger an immediate flush to enable the throttling queue
3132
cy.get('#test').click() // Queue the change
3233
cy.get('a').click() // Navigate
33-
cy.location('pathname').should('eq', path + '/end')
34+
expectPathname(path + '/end')
3435
cy.get('#client-state').should('have.text', 'pass')
3536
cy.location('search').should('be.empty')
3637
cy.location('search').should('eq', '?test=pass') // Then it flushes again
@@ -41,7 +42,7 @@ export const testFlushAfterNavigate = createTest(
4142
cy.get('#preflush').click() // Trigger an immediate flush to enable the throttling queue
4243
cy.get('#test').click() // Queue the change
4344
cy.get('a').click() // Navigate
44-
cy.location('pathname').should('eq', path + '/end')
45+
expectPathname(path + '/end')
4546
cy.get('#client-state').should('have.text', 'pass')
4647
cy.location('search').should('eq', '?test=nav')
4748
cy.location('search').should('eq', '?test=pass') // Then it flushes again

0 commit comments

Comments
 (0)