-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test(nextjs): Extract pages routes tests from nextjs-app-dir
e2e tests
#17175
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
47420c0
split tests
chargome 6a9d230
Merge branch 'develop' into cg-split-nextjs-app-dir-test
chargome 0422996
use latest react versions
chargome d715a45
rename apps
chargome edc525c
.
chargome 9b8ab32
not needed
chargome e65434b
try this
chargome f61630e
no
chargome 1d81176
?
chargome bf8485a
explain
chargome File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
dev-packages/e2e-tests/test-applications/nextjs-app-dir/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "create-next-app", | ||
"name": "nextjs-app-dir", | ||
"version": "0.1.0", | ||
"private": true, | ||
"scripts": { | ||
|
46 changes: 46 additions & 0 deletions
46
dev-packages/e2e-tests/test-applications/nextjs-pages-dir/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
.pnpm-debug.log* | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts | ||
|
||
!*.d.ts | ||
|
||
# Sentry | ||
.sentryclirc | ||
|
||
.vscode | ||
|
||
test-results | ||
event-dumps |
2 changes: 2 additions & 0 deletions
2
dev-packages/e2e-tests/test-applications/nextjs-pages-dir/.npmrc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@sentry:registry=http://127.0.0.1:4873 | ||
@sentry-internal:registry=http://127.0.0.1:4873 |
1 change: 1 addition & 0 deletions
1
dev-packages/e2e-tests/test-applications/nextjs-pages-dir/app/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// Without this file (or better said without the app directory), we run into a otel dependency issue on the edge runtime |
44 changes: 44 additions & 0 deletions
44
dev-packages/e2e-tests/test-applications/nextjs-pages-dir/assert-build.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import * as assert from 'assert/strict'; | ||
|
||
const packageJson = require('./package.json'); | ||
const nextjsVersion = packageJson.dependencies.next; | ||
|
||
const buildStdout = fs.readFileSync('.tmp_build_stdout', 'utf-8'); | ||
const buildStderr = fs.readFileSync('.tmp_build_stderr', 'utf-8'); | ||
|
||
const getLatestNextVersion = async () => { | ||
try { | ||
const response = await fetch('https://registry.npmjs.org/next/latest'); | ||
const data = await response.json(); | ||
return data.version as string; | ||
} catch { | ||
return '0.0.0'; | ||
} | ||
}; | ||
|
||
(async () => { | ||
// Assert that there was no funky build time warning when we are on a stable (pinned) version | ||
if ( | ||
!nextjsVersion.includes('-canary') && | ||
!nextjsVersion.includes('-rc') && | ||
// If we install latest we cannot assert on "latest" because the package json will contain the actual version number | ||
nextjsVersion !== (await getLatestNextVersion()) | ||
) { | ||
assert.doesNotMatch( | ||
buildStderr, | ||
/Import trace for requested module/, // This is Next.js/Webpack speech for "something is off" | ||
`The E2E tests detected a build warning in the Next.js build output:\n\n--------------\n\n${buildStderr}\n\n--------------\n\n`, | ||
); | ||
} | ||
|
||
// Read the contents of the directory | ||
const files = fs.readdirSync(path.join(process.cwd(), '.next', 'static')); | ||
const mapFiles = files.filter(file => path.extname(file) === '.map'); | ||
if (mapFiles.length > 0) { | ||
throw new Error( | ||
'Client bundle .map files found even though `sourcemaps.deleteSourcemapsAfterUpload` option is set!', | ||
); | ||
} | ||
})(); |
124 changes: 124 additions & 0 deletions
124
...ages/e2e-tests/test-applications/nextjs-pages-dir/components/client-error-debug-tools.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
'use client'; | ||
|
||
import { captureException } from '@sentry/nextjs'; | ||
import { useContext, useState } from 'react'; | ||
import { SpanContext } from './span-context'; | ||
|
||
export function ClientErrorDebugTools() { | ||
const spanContextValue = useContext(SpanContext); | ||
const [spanName, setSpanName] = useState<string>(''); | ||
|
||
const [isFetchingAPIRoute, setIsFetchingAPIRoute] = useState<boolean>(); | ||
const [isFetchingEdgeAPIRoute, setIsFetchingEdgeAPIRoute] = useState<boolean>(); | ||
const [isFetchingExternalAPIRoute, setIsFetchingExternalAPIRoute] = useState<boolean>(); | ||
const [renderError, setRenderError] = useState<boolean>(); | ||
|
||
if (renderError) { | ||
throw new Error('Render Error'); | ||
} | ||
|
||
return ( | ||
<div> | ||
{spanContextValue.spanActive ? ( | ||
<button | ||
onClick={() => { | ||
spanContextValue.stop(); | ||
setSpanName(''); | ||
}} | ||
> | ||
Stop span | ||
</button> | ||
) : ( | ||
<> | ||
<input | ||
type="text" | ||
placeholder="Span name" | ||
value={spanName} | ||
onChange={e => { | ||
setSpanName(e.target.value); | ||
}} | ||
/> | ||
<button | ||
onClick={() => { | ||
spanContextValue.start(spanName); | ||
}} | ||
> | ||
Start span | ||
</button> | ||
</> | ||
)} | ||
<br /> | ||
<br /> | ||
<button | ||
onClick={() => { | ||
throw new Error('Click Error'); | ||
}} | ||
> | ||
Throw error | ||
</button> | ||
<br /> | ||
<button | ||
onClick={() => { | ||
return Promise.reject('Promise Click Error'); | ||
}} | ||
> | ||
Throw promise rejection | ||
</button> | ||
<br /> | ||
<button | ||
onClick={() => { | ||
setRenderError(true); | ||
}} | ||
> | ||
Cause render error | ||
</button> | ||
<br /> | ||
<br /> | ||
<button | ||
onClick={async () => { | ||
setIsFetchingAPIRoute(true); | ||
try { | ||
await fetch('/api/endpoint'); | ||
} catch (e) { | ||
captureException(e); | ||
} | ||
setIsFetchingAPIRoute(false); | ||
}} | ||
disabled={isFetchingAPIRoute} | ||
> | ||
Send request to Next.js API route | ||
</button> | ||
<br /> | ||
<button | ||
onClick={async () => { | ||
setIsFetchingEdgeAPIRoute(true); | ||
try { | ||
await fetch('/api/edge-endpoint'); | ||
} catch (e) { | ||
captureException(e); | ||
} | ||
setIsFetchingEdgeAPIRoute(false); | ||
}} | ||
disabled={isFetchingEdgeAPIRoute} | ||
> | ||
Send request to Next.js Edge API route | ||
</button> | ||
<br /> | ||
<button | ||
onClick={async () => { | ||
setIsFetchingExternalAPIRoute(true); | ||
try { | ||
await fetch('https://example.com/', { mode: 'no-cors' }); | ||
} catch (e) { | ||
captureException(e); | ||
} | ||
setIsFetchingExternalAPIRoute(false); | ||
}} | ||
disabled={isFetchingExternalAPIRoute} | ||
> | ||
Send request to external API route | ||
</button> | ||
<br /> | ||
</div> | ||
); | ||
} |
39 changes: 39 additions & 0 deletions
39
dev-packages/e2e-tests/test-applications/nextjs-pages-dir/components/span-context.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use client'; | ||
|
||
import { startInactiveSpan, Span } from '@sentry/nextjs'; | ||
import { PropsWithChildren, createContext, useState } from 'react'; | ||
|
||
export const SpanContext = createContext< | ||
{ spanActive: false; start: (spanName: string) => void } | { spanActive: true; stop: () => void } | ||
>({ | ||
spanActive: false, | ||
start: () => undefined, | ||
}); | ||
|
||
export function SpanContextProvider({ children }: PropsWithChildren) { | ||
const [span, setSpan] = useState<Span | undefined>(undefined); | ||
|
||
return ( | ||
<SpanContext.Provider | ||
value={ | ||
span | ||
? { | ||
spanActive: true, | ||
stop: () => { | ||
span.end(); | ||
setSpan(undefined); | ||
}, | ||
} | ||
: { | ||
spanActive: false, | ||
start: (spanName: string) => { | ||
const span = startInactiveSpan({ name: spanName }); | ||
setSpan(span); | ||
}, | ||
} | ||
} | ||
> | ||
{children} | ||
</SpanContext.Provider> | ||
); | ||
} |
4 changes: 4 additions & 0 deletions
4
dev-packages/e2e-tests/test-applications/nextjs-pages-dir/globals.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
interface Window { | ||
recordedTransactions?: string[]; | ||
capturedExceptionId?: string; | ||
} |
11 changes: 11 additions & 0 deletions
11
dev-packages/e2e-tests/test-applications/nextjs-pages-dir/instrumentation-client.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import * as Sentry from '@sentry/nextjs'; | ||
|
||
Sentry.init({ | ||
environment: 'qa', // dynamic sampling bias to keep transactions | ||
dsn: process.env.NEXT_PUBLIC_E2E_TEST_DSN, | ||
tunnel: `http://localhost:3031/`, // proxy server | ||
tracesSampleRate: 1.0, | ||
sendDefaultPii: true, | ||
}); | ||
|
||
export const onRouterTransitionStart = Sentry.captureRouterTransitionStart; |
19 changes: 19 additions & 0 deletions
19
dev-packages/e2e-tests/test-applications/nextjs-pages-dir/instrumentation.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import * as Sentry from '@sentry/nextjs'; | ||
|
||
export function register() { | ||
if (process.env.NEXT_RUNTIME === 'nodejs' || process.env.NEXT_RUNTIME === 'edge') { | ||
Sentry.init({ | ||
environment: 'qa', // dynamic sampling bias to keep transactions | ||
dsn: process.env.NEXT_PUBLIC_E2E_TEST_DSN, | ||
tunnel: `http://localhost:3031/`, // proxy server | ||
tracesSampleRate: 1.0, | ||
sendDefaultPii: true, | ||
transportOptions: { | ||
// We are doing a lot of events at once in this test | ||
bufferSize: 1000, | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
export const onRequestError = Sentry.captureRequestError; |
24 changes: 24 additions & 0 deletions
24
dev-packages/e2e-tests/test-applications/nextjs-pages-dir/middleware.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { getDefaultIsolationScope } from '@sentry/core'; | ||
import * as Sentry from '@sentry/nextjs'; | ||
import { NextResponse } from 'next/server'; | ||
import type { NextRequest } from 'next/server'; | ||
|
||
export async function middleware(request: NextRequest) { | ||
Sentry.setTag('my-isolated-tag', true); | ||
Sentry.setTag('my-global-scope-isolated-tag', getDefaultIsolationScope().getScopeData().tags['my-isolated-tag']); // We set this tag to be able to assert that the previously set tag has not leaked into the global isolation scope | ||
|
||
if (request.headers.has('x-should-throw')) { | ||
throw new Error('Middleware Error'); | ||
} | ||
|
||
if (request.headers.has('x-should-make-request')) { | ||
await fetch('http://localhost:3030/'); | ||
} | ||
|
||
return NextResponse.next(); | ||
} | ||
|
||
// See "Matching Paths" below to learn more | ||
export const config = { | ||
matcher: ['/api/endpoint-behind-middleware', '/api/endpoint-behind-faulty-middleware'], | ||
}; |
6 changes: 6 additions & 0 deletions
6
dev-packages/e2e-tests/test-applications/nextjs-pages-dir/next-env.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
/// <reference types="next/navigation-types/compat/navigation" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information. |
15 changes: 15 additions & 0 deletions
15
dev-packages/e2e-tests/test-applications/nextjs-pages-dir/next.config.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const { withSentryConfig } = require('@sentry/nextjs'); | ||
|
||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
experimental: { | ||
serverActions: true, | ||
}, | ||
}; | ||
|
||
module.exports = withSentryConfig(nextConfig, { | ||
debug: true, | ||
sourcemaps: { | ||
deleteSourcemapsAfterUpload: true, | ||
}, | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.