Skip to content

Commit

Permalink
test(e2e): Update create-next-app test app
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Jun 5, 2024
1 parent 5229217 commit 136e30e
Show file tree
Hide file tree
Showing 16 changed files with 246 additions and 321 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
interface Window {
recordedTransactions?: string[];
capturedExceptionId?: string;
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,13 @@
import * as Sentry from '@sentry/nextjs';

declare global {
namespace globalThis {
var transactionIds: string[];
}
}

export function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: process.env.NEXT_PUBLIC_E2E_TEST_DSN,
// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1.0,
integrations: [Sentry.localVariablesIntegration()],
});

Sentry.addEventProcessor(event => {
global.transactionIds = global.transactionIds || [];

if (event.type === 'transaction') {
const eventId = event.event_id;

if (eventId) {
global.transactionIds.push(eventId);
}
}

return event;
tunnel: 'http://localhost:3031',
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"typescript": "4.9.5"
},
"devDependencies": {
"@playwright/test": "^1.44.1"
"@playwright/test": "^1.44.1",
"@sentry-internal/test-utils": "link:../../../test-utils"
},
"volta": {
"extends": "../../package.json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import * as Sentry from '@sentry/nextjs';
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from 'next';

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const exceptionId = Sentry.captureException(new Error('This is an error'));

await Sentry.flush(2000);

res.status(200).json({ exceptionId });
throw new Error('I am a server error!');
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {

Sentry.flush().then(() => {
res.status(200).json({
transactionIds: global.transactionIds,
transactionIds: [],
});
});
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as Sentry from '@sentry/nextjs';
import Head from 'next/head';
import Link from 'next/link';

Expand All @@ -17,8 +16,7 @@ export default function Home() {
value="Capture Exception"
id="exception-button"
onClick={() => {
const eventId = Sentry.captureException(new Error('I am an error!'));
window.capturedExceptionId = eventId;
throw new Error('I am an error!');
}}
/>
<Link href="/user/5" id="navigation">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { getPlaywrightConfig } from '@sentry-internal/test-utils';

const testEnv = process.env.TEST_ENV;

if (!testEnv) {
throw new Error('No test env defined');
}

const config = getPlaywrightConfig({
startCommand: testEnv === 'development' ? `pnpm next dev -p 3030` : `pnpm next start -p 3030`,
});

export default config;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,8 @@ import * as Sentry from '@sentry/nextjs';
Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: process.env.NEXT_PUBLIC_E2E_TEST_DSN,
// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1.0,

// ...
// Note: if you want to override the automatic release value, do not set a
// `release` value here - use the environment variable `SENTRY_RELEASE`, so
// that it will also get attached to your source maps
});

Sentry.addEventProcessor(event => {
if (
event.type === 'transaction' &&
(event.contexts?.trace?.op === 'pageload' || event.contexts?.trace?.op === 'navigation')
) {
const eventId = event.event_id;
if (eventId) {
window.recordedTransactions = window.recordedTransactions || [];
window.recordedTransactions.push(eventId);
}
}
tracesSampleRate: 1.0,

return event;
tunnel: 'http://localhost:3031',
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { startEventProxyServer } from '@sentry-internal/test-utils';

startEventProxyServer({
port: 3031,
proxyServerName: 'create-next-app',
});

This file was deleted.

Loading

0 comments on commit 136e30e

Please sign in to comment.