Skip to content

Commit 08d4c47

Browse files
committed
add integration tests
1 parent 3f5e303 commit 08d4c47

File tree

5 files changed

+74
-0
lines changed

5 files changed

+74
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { NextApiRequest, NextApiResponse } from 'next';
2+
3+
const handler = async (_req: NextApiRequest, res: NextApiResponse): Promise<void> => {
4+
res.status(200).json({});
5+
};
6+
7+
export default handler;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { NextApiRequest, NextApiResponse } from 'next';
2+
3+
const handler = async (_req: NextApiRequest, res: NextApiResponse): Promise<void> => {
4+
res.status(200).json({});
5+
};
6+
7+
export default handler;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { withSentry } from '@sentry/nextjs';
2+
import { NextApiRequest, NextApiResponse } from 'next';
3+
4+
const handler = async (_req: NextApiRequest, res: NextApiResponse): Promise<void> => {
5+
res.status(200).json({});
6+
};
7+
8+
export default withSentry(handler);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { withSentry } from '@sentry/nextjs';
2+
import { NextApiRequest, NextApiResponse } from 'next';
3+
4+
const handler = async (_req: NextApiRequest, res: NextApiResponse): Promise<void> => {
5+
res.status(200).json({});
6+
};
7+
8+
export default withSentry(handler);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const assert = require('assert');
2+
3+
const { sleep } = require('../utils/common');
4+
const { getAsync, interceptEventRequest, interceptTracingRequest } = require('../utils/server');
5+
6+
module.exports = async ({ url: urlBase, argv }) => {
7+
const urls = {
8+
unwrappedNoParamURL: `/api/withSentryAPI/unwrapped/noParams`,
9+
wrappedNoParamURL: `/api/withSentryAPI/wrapped/noParams`,
10+
unwrappedDynamicURL: `/api/withSentryAPI/unwrapped/dog`,
11+
wrappedDynamicURL: `/api/withSentryAPI/wrapped/dog`,
12+
};
13+
14+
const interceptedRequests = {};
15+
16+
Object.entries(urls).forEach(([testName, url]) => {
17+
interceptedRequests[testName] = interceptTracingRequest(
18+
{
19+
contexts: {
20+
trace: {
21+
op: 'http.server',
22+
status: 'ok',
23+
tags: { 'http.status_code': '200' },
24+
},
25+
},
26+
transaction: `GET ${url.replace('dog', '[animal]')}`,
27+
type: 'transaction',
28+
request: {
29+
url: `${urlBase}${url}`,
30+
},
31+
},
32+
argv,
33+
testName,
34+
);
35+
});
36+
37+
Object.values(urls).forEach(async url => await getAsync(`${urlBase}${url}`));
38+
39+
await sleep(500);
40+
41+
Object.entries(interceptedRequests).forEach(([testName, request]) =>
42+
assert.ok(request.isDone(), `Did not intercept transaction request for ${testName}`),
43+
);
44+
};

0 commit comments

Comments
 (0)