Skip to content

Commit 8ed7ea5

Browse files
committed
add integration tests
1 parent 72704e0 commit 8ed7ea5

File tree

7 files changed

+99
-0
lines changed

7 files changed

+99
-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,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,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,54 @@
1+
const assert = require('assert');
2+
3+
const { sleep } = require('../utils/common');
4+
const { getAsync, interceptTracingRequest } = require('../utils/server');
5+
6+
module.exports = async ({ url: urlBase, argv }) => {
7+
const urls = {
8+
// testName: [url, route]
9+
unwrappedNoParamURL: [`/api/withSentryAPI/unwrapped/noParams`, '/api/withSentryAPI/unwrapped/noParams'],
10+
unwrappedDynamicURL: [`/api/withSentryAPI/unwrapped/dog`, '/api/withSentryAPI/unwrapped/[animal]'],
11+
unwrappedCatchAllURL: [`/api/withSentryAPI/unwrapped/dog/facts`, '/api/withSentryAPI/unwrapped/[...pathParts]'],
12+
wrappedNoParamURL: [`/api/withSentryAPI/wrapped/noParams`, '/api/withSentryAPI/wrapped/noParams'],
13+
wrappedDynamicURL: [`/api/withSentryAPI/wrapped/dog`, '/api/withSentryAPI/wrapped/[animal]'],
14+
wrappedCatchAllURL: [`/api/withSentryAPI/wrapped/dog/facts`, '/api/withSentryAPI/wrapped/[...pathParts]'],
15+
};
16+
17+
const interceptedRequests = {};
18+
19+
Object.entries(urls).forEach(([testName, [url, route]]) => {
20+
interceptedRequests[testName] = interceptTracingRequest(
21+
{
22+
contexts: {
23+
trace: {
24+
op: 'http.server',
25+
status: 'ok',
26+
tags: { 'http.status_code': '200' },
27+
},
28+
},
29+
transaction: `GET ${route}`,
30+
type: 'transaction',
31+
request: {
32+
url: `${urlBase}${url}`,
33+
},
34+
},
35+
argv,
36+
testName,
37+
);
38+
});
39+
40+
// Wait until all requests have completed
41+
await Promise.all(Object.values(urls).map(([url]) => getAsync(`${urlBase}${url}`)));
42+
43+
await sleep(250);
44+
45+
const failingTests = Object.entries(interceptedRequests).reduce(
46+
(failures, [testName, request]) => (!request.isDone() ? failures.concat(testName) : failures),
47+
[],
48+
);
49+
50+
assert.ok(
51+
failingTests.length === 0,
52+
`Did not intercept transaction request for the following tests: ${failingTests.join(', ')}.`,
53+
);
54+
};

0 commit comments

Comments
 (0)