Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
129 lines
3.7 KiB
TypeScript
129 lines
3.7 KiB
TypeScript
/* eslint-env jest */
|
|
|
|
// These tests are defined here and used in `app-dir.test.ts` and
|
|
// `pages-dir.test.ts` so that both test suites can be run in parallel.
|
|
|
|
import type { Playwright } from 'next-webdriver'
|
|
|
|
import cheerio from 'cheerio'
|
|
import type { NextInstance } from 'e2e-utils'
|
|
|
|
export function testShouldRedirect(
|
|
next: NextInstance,
|
|
expectations: [string, string][]
|
|
) {
|
|
it.each(expectations)(
|
|
'%s should redirect to %s',
|
|
async (route, expectedLocation) => {
|
|
const res = await next.fetch(route, { redirect: 'manual' })
|
|
expect(res.status).toBe(308)
|
|
const { pathname } = new URL(res.headers.get('location'))
|
|
expect(pathname).toBe(expectedLocation)
|
|
}
|
|
)
|
|
}
|
|
|
|
export function testShouldResolve(
|
|
next: NextInstance,
|
|
expectations: [string, string, string][]
|
|
) {
|
|
it.each(expectations)(
|
|
'%s should resolve to %s, with router path %s',
|
|
async (route, expectedPage, expectedRouterPath) => {
|
|
const res = await next.fetch(route, { redirect: 'error' })
|
|
expect(res.status).toBe(200)
|
|
const $ = cheerio.load(await res.text())
|
|
expect($('#page-marker').text()).toBe(expectedPage)
|
|
expect($('#router-pathname').text()).toBe(expectedRouterPath)
|
|
}
|
|
)
|
|
|
|
it.each(expectations)(
|
|
'%s should client side render %s, with router path %s',
|
|
async (route, expectedPage, expectedRouterPath) => {
|
|
let browser: Playwright | undefined
|
|
try {
|
|
browser = await next.browser(route)
|
|
|
|
await browser.waitForElementByCss('#hydration-marker', {
|
|
state: 'attached',
|
|
})
|
|
const text = await browser.elementByCss('#page-marker').text()
|
|
expect(text).toBe(expectedPage)
|
|
const routerPathname = await browser
|
|
.elementByCss('#router-pathname')
|
|
.text()
|
|
expect(routerPathname).toBe(expectedRouterPath)
|
|
} finally {
|
|
if (browser) await browser.close()
|
|
}
|
|
}
|
|
)
|
|
}
|
|
|
|
export function testExternalLinkShouldRewriteTo(
|
|
next: NextInstance,
|
|
expectations: [string, string][]
|
|
) {
|
|
it.each(expectations)(
|
|
'%s should have href %s',
|
|
async (linkPage, expectedHref) => {
|
|
const $ = await next.render$(linkPage)
|
|
expect($('#link').attr('href')).toBe(expectedHref)
|
|
}
|
|
)
|
|
}
|
|
|
|
export function testLinkShouldRewriteTo(
|
|
next: NextInstance,
|
|
expectations: [string, string][]
|
|
) {
|
|
it.each(expectations)(
|
|
'%s should have href %s',
|
|
async (linkPage, expectedHref) => {
|
|
const $ = await next.render$(linkPage)
|
|
expect($('#link').attr('href')).toBe(expectedHref)
|
|
}
|
|
)
|
|
|
|
it.each(expectations)(
|
|
'%s should navigate to %s',
|
|
async (linkPage, expectedHref) => {
|
|
let browser: Playwright | undefined
|
|
try {
|
|
browser = await next.browser(linkPage)
|
|
await browser.elementByCss('#link').click()
|
|
|
|
await browser.waitForElementByCss('#hydration-marker', {
|
|
state: 'attached',
|
|
})
|
|
const url = new URL(await browser.eval('window.location.href'))
|
|
const pathname = url.href.slice(url.origin.length)
|
|
expect(pathname).toBe(expectedHref)
|
|
} finally {
|
|
if (browser) await browser.close()
|
|
}
|
|
}
|
|
)
|
|
|
|
it.each(expectations)(
|
|
'%s should push route to %s',
|
|
async (linkPage, expectedHref) => {
|
|
let browser: Playwright | undefined
|
|
try {
|
|
browser = await next.browser(linkPage)
|
|
await browser.elementByCss('#route-pusher').click()
|
|
|
|
await browser.waitForElementByCss('#hydration-marker', {
|
|
state: 'attached',
|
|
})
|
|
const url = new URL(await browser.eval('window.location.href'))
|
|
const pathname = url.href.slice(url.origin.length)
|
|
expect(pathname).toBe(expectedHref)
|
|
} finally {
|
|
if (browser) await browser.close()
|
|
}
|
|
}
|
|
)
|
|
}
|