Skip to content

Commit ec7441d

Browse files
committed
Add integration tests
1 parent be1e9f3 commit ec7441d

22 files changed

+207
-44
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function ({ children }: { children: React.ReactNode }) {
2+
return <>{children}</>;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use client';
2+
3+
export default function () {
4+
return <p>I am a client component!</p>;
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function ({ children }: { children: React.ReactNode }) {
2+
return <>{children}</>;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default async function () {
2+
return <p>I am a server component!</p>;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const { withSentryConfig } = require('@sentry/nextjs');
2+
3+
// NOTE: This will be used by integration tests to distinguish between Webpack 4 and Webpack 5
4+
const moduleExports = {
5+
webpack5: %RUN_WEBPACK_5%,
6+
eslint: {
7+
ignoreDuringBuilds: true,
8+
},
9+
pageExtensions: ['jsx', 'js', 'tsx', 'ts', 'page.tsx'],
10+
sentry: {
11+
// Suppress the warning message from `handleSourcemapHidingOptionWarning` in `src/config/webpack.ts`
12+
// TODO (v8): This can come out in v8, because this option will get a default value
13+
hideSourceMaps: false,
14+
excludeServerRoutes: [
15+
'/api/excludedEndpoints/excludedWithString',
16+
/\/api\/excludedEndpoints\/excludedWithRegExp/,
17+
],
18+
},
19+
};
20+
21+
const SentryWebpackPluginOptions = {
22+
dryRun: true,
23+
silent: true,
24+
};
25+
26+
module.exports = withSentryConfig(moduleExports, SentryWebpackPluginOptions);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const { withSentryConfig } = require('@sentry/nextjs');
2+
3+
// NOTE: This will be used by integration tests to distinguish between Webpack 4 and Webpack 5
4+
const moduleExports = {
5+
webpack5: %RUN_WEBPACK_5%,
6+
eslint: {
7+
ignoreDuringBuilds: true,
8+
},
9+
experimental: {
10+
appDir: Number(process.env.NODE_MAJOR) >= 16, // experimental.appDir requires Node v16.8.0 or later.
11+
},
12+
pageExtensions: ['jsx', 'js', 'tsx', 'ts', 'page.tsx'],
13+
sentry: {
14+
// Suppress the warning message from `handleSourcemapHidingOptionWarning` in `src/config/webpack.ts`
15+
// TODO (v8): This can come out in v8, because this option will get a default value
16+
hideSourceMaps: false,
17+
excludeServerRoutes: [
18+
'/api/excludedEndpoints/excludedWithString',
19+
/\/api\/excludedEndpoints\/excludedWithRegExp/,
20+
],
21+
},
22+
};
23+
24+
const SentryWebpackPluginOptions = {
25+
dryRun: true,
26+
silent: true,
27+
};
28+
29+
module.exports = withSentryConfig(moduleExports, SentryWebpackPluginOptions);

packages/nextjs/test/integration/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"dependencies": {
1111
"@sentry/nextjs": "file:../../",
12-
"next": "latest",
12+
"next": "10.x",
1313
"react": "^17.0.1",
1414
"react-dom": "^17.0.1"
1515
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "with-typescript",
3+
"license": "MIT",
4+
"scripts": {
5+
"dev": "next",
6+
"build": "next build",
7+
"predebug": "source ../integration_test_utils.sh && link_monorepo_packages '../../..' && yarn build",
8+
"start": "next start"
9+
},
10+
"dependencies": {
11+
"@sentry/nextjs": "file:../../",
12+
"next": "latest",
13+
"react": "^17.0.1",
14+
"react-dom": "^17.0.1"
15+
},
16+
"devDependencies": {
17+
"@types/node": "^15.3.1",
18+
"@types/puppeteer": "^5.4.3",
19+
"@types/react": "17.0.47",
20+
"@types/react-dom": "17.0.17",
21+
"nock": "^13.1.0",
22+
"puppeteer": "^9.1.1",
23+
"typescript": "^4.2.4",
24+
"yargs": "^16.2.0"
25+
},
26+
"resolutions": {
27+
"@sentry/browser": "file:../../../browser",
28+
"@sentry/core": "file:../../../core",
29+
"@sentry/integrations": "file:../../../integrations",
30+
"@sentry/node": "file:../../../node",
31+
"@sentry/react": "file:../../../react",
32+
"@sentry/replay": "file:../../../replay",
33+
"@sentry/tracing": "file:../../../tracing",
34+
"@sentry/types": "file:../../../types",
35+
"@sentry/utils": "file:../../../utils"
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { withSentry } from '@sentry/nextjs';
1+
import { wrapApiHandlerWithSentry } from '@sentry/nextjs';
22
import { NextApiRequest, NextApiResponse } from 'next';
33

44
const handler = async (_req: NextApiRequest, res: NextApiResponse): Promise<void> => {
55
res.status(500).json({ statusCode: 500, message: 'Something went wrong' });
66
};
77

8-
export default withSentry(handler);
8+
export default wrapApiHandlerWithSentry(handler, '/api/broken');
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { withSentry } from '@sentry/nextjs';
1+
import { wrapApiHandlerWithSentry } from '@sentry/nextjs';
22
import { NextApiRequest, NextApiResponse } from 'next';
33

44
const handler = async (_req: NextApiRequest, _res: NextApiResponse): Promise<void> => {
55
throw new Error('API Error');
66
};
77

8-
export default withSentry(handler);
8+
export default wrapApiHandlerWithSentry(handler, '/api/error');

packages/nextjs/test/integration/pages/api/http/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { withSentry } from '@sentry/nextjs';
1+
import { wrapApiHandlerWithSentry } from '@sentry/nextjs';
22
import { get } from 'http';
33
import { NextApiRequest, NextApiResponse } from 'next';
44

@@ -9,4 +9,4 @@ const handler = async (_req: NextApiRequest, res: NextApiResponse): Promise<void
99
res.status(200).json({});
1010
};
1111

12-
export default withSentry(handler);
12+
export default wrapApiHandlerWithSentry(handler, '/api/http');

packages/nextjs/test/integration/pages/api/users/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { withSentry } from '@sentry/nextjs';
1+
import { wrapApiHandlerWithSentry } from '@sentry/nextjs';
22
import { NextApiRequest, NextApiResponse } from 'next';
33

44
import { sampleUserData } from '../../../utils/sample-data';
@@ -15,4 +15,4 @@ const handler = async (_req: NextApiRequest, res: NextApiResponse): Promise<void
1515
}
1616
};
1717

18-
export default withSentry(handler);
18+
export default wrapApiHandlerWithSentry(handler, '/api/users');
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { withSentry } from '@sentry/nextjs';
1+
import { wrapApiHandlerWithSentry } from '@sentry/nextjs';
22
import { NextApiRequest, NextApiResponse } from 'next';
33

44
const handler = async (_req: NextApiRequest, res: NextApiResponse): Promise<void> => {
55
res.status(200).json({});
66
};
77

8-
export default withSentry(handler);
8+
export default wrapApiHandlerWithSentry(handler, '/api/wrapApiHandlerWithSentry/wrapped/[...pathParts]');
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { withSentry } from '@sentry/nextjs';
1+
import { wrapApiHandlerWithSentry } from '@sentry/nextjs';
22
import { NextApiRequest, NextApiResponse } from 'next';
33

44
const handler = async (_req: NextApiRequest, res: NextApiResponse): Promise<void> => {
55
res.status(200).json({});
66
};
77

8-
export default withSentry(handler);
8+
export default wrapApiHandlerWithSentry(handler, '/api/wrapApiHandlerWithSentry/wrapped/[animal]');
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { withSentry } from '@sentry/nextjs';
1+
import { wrapApiHandlerWithSentry } from '@sentry/nextjs';
22
import { NextApiRequest, NextApiResponse } from 'next';
33

44
const handler = async (_req: NextApiRequest, res: NextApiResponse): Promise<void> => {
55
res.status(200).json({});
66
};
77

8-
export default withSentry(handler);
8+
export default wrapApiHandlerWithSentry(handler, '/api/wrapApiHandlerWithSentry/wrapped/noParams');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as Sentry from '@sentry/nextjs';
2+
3+
Sentry.init({
4+
dsn: 'https://[email protected]/1337',
5+
tracesSampleRate: 1,
6+
debug: process.env.SDK_DEBUG,
7+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const { expectRequestCount, isTransactionRequest, expectTransaction } = require('../utils/client');
2+
3+
module.exports = async ({ page, url, requests }) => {
4+
if (Number(process.env.NEXTJS_VERSION) < 13 || Number(process.env.NODE_MAJOR) < 16) {
5+
// Next.js versions < 13 don't support the app directory and the app dir requires Node v16.8.0 or later.
6+
return;
7+
}
8+
9+
const requestPromise = page.waitForRequest(isTransactionRequest);
10+
await page.goto(`${url}/clientcomponent`);
11+
await requestPromise;
12+
13+
expectTransaction(requests.transactions[0], {
14+
contexts: {
15+
trace: {
16+
op: 'pageload',
17+
},
18+
},
19+
transaction: '/clientcomponent',
20+
});
21+
22+
await expectRequestCount(requests, { transactions: 1 });
23+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const { expectRequestCount, isTransactionRequest, expectTransaction } = require('../utils/client');
2+
3+
module.exports = async ({ page, url, requests }) => {
4+
if (Number(process.env.NEXTJS_VERSION) < 13 || Number(process.env.NODE_MAJOR) < 16) {
5+
// Next.js versions < 13 don't support the app directory and the app dir requires Node v16.8.0 or later.
6+
return;
7+
}
8+
9+
const requestPromise = page.waitForRequest(isTransactionRequest);
10+
await page.goto(`${url}/servercomponent`);
11+
await requestPromise;
12+
13+
expectTransaction(requests.transactions[0], {
14+
contexts: {
15+
trace: {
16+
op: 'pageload',
17+
},
18+
},
19+
transaction: '/servercomponent',
20+
});
21+
22+
await expectRequestCount(requests, { transactions: 1 });
23+
};
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
1-
const { waitForAll } = require('../utils/common');
2-
const { expectRequestCount, isSessionRequest, expectSession } = require('../utils/client');
1+
const { expectRequestCount, isSessionRequest, expectSession, extractEnvelopeFromRequest } = require('../utils/client');
32

43
module.exports = async ({ page, url, requests }) => {
5-
await waitForAll([
6-
page.goto(`${url}/crashed`),
7-
page.waitForRequest(isSessionRequest),
8-
page.waitForRequest(isSessionRequest),
9-
]);
10-
11-
expectSession(requests.sessions[0], {
12-
init: true,
13-
status: 'ok',
14-
errors: 0,
4+
const sessionRequestPromise1 = page.waitForRequest(request => {
5+
if (isSessionRequest(request)) {
6+
const { item } = extractEnvelopeFromRequest(request);
7+
return item.init === true && item.status === 'ok' && item.errors === 0;
8+
} else {
9+
return false;
10+
}
1511
});
1612

17-
expectSession(requests.sessions[1], {
18-
init: false,
19-
status: 'crashed',
20-
errors: 1,
13+
const sessionRequestPromise2 = page.waitForRequest(request => {
14+
if (isSessionRequest(request)) {
15+
const { item } = extractEnvelopeFromRequest(request);
16+
return item.init === false && item.status === 'crashed' && item.errors === 1;
17+
} else {
18+
return false;
19+
}
2120
});
2221

22+
await page.goto(`${url}/crashed`);
23+
await sessionRequestPromise1;
24+
await sessionRequestPromise2;
25+
2326
await expectRequestCount(requests, { sessions: 2 });
2427
};

packages/nextjs/test/integration/tsconfig.json

+9-12
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
"forceConsistentCasingInFileNames": true,
77
"isolatedModules": true,
88
"jsx": "preserve",
9-
"lib": [
10-
"dom",
11-
"es2017"
12-
],
9+
"lib": ["dom", "es2017"],
1310
"module": "esnext",
1411
"moduleResolution": "node",
1512
"noEmit": true,
@@ -20,13 +17,13 @@
2017
"skipLibCheck": true,
2118
"strict": true,
2219
"target": "esnext",
23-
"incremental": true
20+
"incremental": true,
21+
"plugins": [
22+
{
23+
"name": "next"
24+
}
25+
]
2426
},
25-
"exclude": [
26-
"node_modules"
27-
],
28-
"include": [
29-
"**/*.ts",
30-
"**/*.tsx"
31-
]
27+
"exclude": ["node_modules"],
28+
"include": ["**/*.ts", "**/*.tsx", ".next/types/**/*.ts"]
3229
}

packages/nextjs/test/run-integration-tests.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,12 @@ for NEXTJS_VERSION in 10 11 12 13; do
107107
# next 10 defaults to webpack 4 and next 11 defaults to webpack 5, but each can use either based on settings
108108
if [ "$NEXTJS_VERSION" -eq "10" ]; then
109109
sed "s/%RUN_WEBPACK_5%/$RUN_WEBPACK_5/g" <next10.config.template >next.config.js
110-
else
110+
elif [ "$NEXTJS_VERSION" -eq "11" ]; then
111111
sed "s/%RUN_WEBPACK_5%/$RUN_WEBPACK_5/g" <next11.config.template >next.config.js
112+
elif [ "$NEXTJS_VERSION" -eq "12" ]; then
113+
sed "s/%RUN_WEBPACK_5%/$RUN_WEBPACK_5/g" <next12.config.template >next.config.js
114+
elif [ "$NEXTJS_VERSION" -eq "13" ]; then
115+
sed "s/%RUN_WEBPACK_5%/$RUN_WEBPACK_5/g" <next13.config.template >next.config.js
112116
fi
113117

114118
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Building..."

0 commit comments

Comments
 (0)