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
159 lines
4.8 KiB
TypeScript
159 lines
4.8 KiB
TypeScript
import { nextTestSetup } from 'e2e-utils'
|
|
import { retry } from 'next-test-utils'
|
|
import path from 'path'
|
|
|
|
describe('Instrumentation Client Hook', () => {
|
|
const testCases = [
|
|
{
|
|
name: 'With src folder',
|
|
appDir: 'app-with-src',
|
|
shouldLog: false,
|
|
},
|
|
{
|
|
name: 'App Router',
|
|
appDir: 'app-router',
|
|
shouldLog: true,
|
|
},
|
|
{
|
|
name: 'Pages Router',
|
|
appDir: 'pages-router',
|
|
shouldLog: false,
|
|
},
|
|
]
|
|
|
|
testCases.forEach(({ name, appDir, shouldLog }) => {
|
|
describe(name, () => {
|
|
const { next, isNextDev } = nextTestSetup({
|
|
files: path.join(__dirname, appDir),
|
|
})
|
|
|
|
it(`should execute instrumentation-client from ${name.toLowerCase()} before hydration`, async () => {
|
|
const browser = await next.browser('/')
|
|
|
|
const instrumentationTime = await browser.eval(
|
|
`window.__INSTRUMENTATION_CLIENT_EXECUTED_AT`
|
|
)
|
|
const hydrationTime = await browser.eval(`window.__NEXT_HYDRATED_AT`)
|
|
|
|
expect(instrumentationTime).toBeDefined()
|
|
expect(hydrationTime).toBeDefined()
|
|
expect(instrumentationTime).toBeLessThan(hydrationTime)
|
|
expect(
|
|
(await browser.log()).some((log) =>
|
|
log.message.startsWith(
|
|
'[Client Instrumentation Hook] Slow execution detected'
|
|
)
|
|
)
|
|
).toBe(isNextDev && shouldLog)
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('onRouterTransitionStart', () => {
|
|
const { next } = nextTestSetup({
|
|
files: path.join(__dirname, 'app-router'),
|
|
})
|
|
|
|
function filterNavigationStartLogs(logs: Array<{ message: string }>) {
|
|
const result = []
|
|
for (const log of logs) {
|
|
if (log.message.startsWith('[Router Transition Start]')) {
|
|
result.push(log.message)
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
|
|
it('onRouterTransitionStart fires at the start of a navigation', async () => {
|
|
const browser = await next.browser('/')
|
|
|
|
const linkToSomePage = await browser.elementByCss('a[href="/some-page"]')
|
|
await linkToSomePage.click()
|
|
await browser.elementById('some-page')
|
|
|
|
const linkToHome = await browser.elementByCss('a[href="/"]')
|
|
await linkToHome.click()
|
|
await browser.elementById('home')
|
|
|
|
expect(filterNavigationStartLogs(await browser.log())).toEqual([
|
|
'[Router Transition Start] [push] /some-page',
|
|
'[Router Transition Start] [push] /',
|
|
])
|
|
})
|
|
|
|
it('onRouterTransitionStart fires at the start of a back/forward navigation', async () => {
|
|
const browser = await next.browser('/')
|
|
|
|
const linkToSomePage = await browser.elementByCss('a[href="/some-page"]')
|
|
await linkToSomePage.click()
|
|
await browser.elementById('some-page')
|
|
|
|
await browser.back()
|
|
await browser.elementById('home')
|
|
|
|
await browser.forward()
|
|
await browser.elementById('some-page')
|
|
|
|
expect(filterNavigationStartLogs(await browser.log())).toEqual([
|
|
'[Router Transition Start] [push] /some-page',
|
|
'[Router Transition Start] [traverse] /',
|
|
'[Router Transition Start] [traverse] /some-page',
|
|
])
|
|
})
|
|
})
|
|
|
|
describe('HMR in development mode', () => {
|
|
const { next, isNextDev } = nextTestSetup({
|
|
files: path.join(__dirname, 'app-router'),
|
|
})
|
|
|
|
if (isNextDev) {
|
|
it('should reload instrumentation-client when modified', async () => {
|
|
const browser = await next.browser('/')
|
|
const initialTime = await browser.eval(
|
|
`window.__INSTRUMENTATION_CLIENT_EXECUTED_AT`
|
|
)
|
|
expect(initialTime).toBeDefined()
|
|
|
|
// Modify the instrumentation-client.ts file
|
|
const instrumentationPath = 'instrumentation-client.ts'
|
|
|
|
const originalContent = await next.readFile(instrumentationPath)
|
|
|
|
await next.patchFile(
|
|
instrumentationPath,
|
|
`
|
|
window.__INSTRUMENTATION_CLIENT_EXECUTED_AT = Date.now();
|
|
window.__INSTRUMENTATION_CLIENT_UPDATED = true;
|
|
`
|
|
)
|
|
|
|
await retry(async () => {
|
|
// Check if the updated instrumentation client was executed
|
|
const updatedFlag = await browser.eval(
|
|
`window.__INSTRUMENTATION_CLIENT_UPDATED`
|
|
)
|
|
expect(updatedFlag).toBe(true)
|
|
|
|
// Verify new execution time
|
|
const newTime = await browser.eval(
|
|
`window.__INSTRUMENTATION_CLIENT_EXECUTED_AT`
|
|
)
|
|
expect(newTime).toBeDefined()
|
|
expect(newTime).toBeGreaterThan(initialTime)
|
|
})
|
|
|
|
// Restore the original file
|
|
await next.patchFile(instrumentationPath, originalContent)
|
|
})
|
|
} else {
|
|
// Add a dummy test when not in dev mode
|
|
it('skips tests in non-dev mode', () => {
|
|
console.log(
|
|
'Skipping instrumentation-client-hook tests in non-dev mode'
|
|
)
|
|
})
|
|
}
|
|
})
|
|
})
|