Files
next.js/test/e2e/opentelemetry/instrumentation-pages-app-only.test.ts
JJ KasperandGitHub eaa7606de1 Fix instrumentation with only pages (#62622)
This ensures we properly transpile `instrumentation.ts` when only
`pages` is being used as previously we were relying on the `app`
specific loaders which aren't configured when an `app` directory isn't
present. We regressed on this in
https://github.com/vercel/next.js/pull/60984 as it was working as
expected prior to this commit

x-ref: [slack
thread](https://vercel.slack.com/archives/C011GK1JUBA/p1709075846401649?thread_ts=1706643408.233909&cid=C011GK1JUBA)

Closes NEXT-2632
2024-02-28 11:38:39 +01:00

68 lines
1.7 KiB
TypeScript

import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
for (const { app, src, pathname, text } of [
{
pages: true,
src: false,
pathname: '/pages/param/getServerSideProps',
text: 'Page',
},
{
pages: true,
src: true,
pathname: '/pages/param/getServerSideProps',
text: 'Page',
},
{
app: true,
src: false,
pathname: '/app/param/rsc-fetch',
text: 'Page',
},
{
app: true,
src: true,
pathname: '/app/param/rsc-fetch',
text: 'Page',
},
]) {
describe(`instrumentation ${app ? 'app' : 'pages'}${
src ? ' src/' : ''
}`, () => {
const curDir = app ? 'app' : 'pages'
const oppositeDir = app ? 'pages' : 'app'
const { next } = nextTestSetup({
files: __dirname,
env: {
NEXT_PUBLIC_SIMPLE_INSTRUMENT: '1',
},
skipDeployment: true,
packageJson: {
scripts: {
'setup-dir': `mv instrumentation-minimal.ts instrumentation.ts; rm -rf ${oppositeDir}${
src
? `; mkdir src; mv ${curDir} src/; mv instrumentation.ts src/`
: ''
}`,
dev: 'pnpm setup-dir && next dev',
build: 'pnpm setup-dir && next build',
start: 'next start',
},
},
startCommand: `pnpm ${(global as any).isNextDev ? 'dev' : 'start'}`,
buildCommand: `pnpm build`,
dependencies: require('./package.json').dependencies,
})
it('should start and serve correctly', async () => {
const html = await next.render(pathname)
expect(html).toContain(text)
retry(() => {
expect(next.cliOutput).toContain('instrumentation log')
})
})
})
}