Skip to content

Commit

Permalink
add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lobsterkatie committed Sep 21, 2022
1 parent 3f5e303 commit 08d4c47
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { NextApiRequest, NextApiResponse } from 'next';

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

export default handler;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { NextApiRequest, NextApiResponse } from 'next';

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

export default handler;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { withSentry } from '@sentry/nextjs';
import { NextApiRequest, NextApiResponse } from 'next';

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

export default withSentry(handler);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { withSentry } from '@sentry/nextjs';
import { NextApiRequest, NextApiResponse } from 'next';

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

export default withSentry(handler);
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const assert = require('assert');

const { sleep } = require('../utils/common');
const { getAsync, interceptEventRequest, interceptTracingRequest } = require('../utils/server');

module.exports = async ({ url: urlBase, argv }) => {
const urls = {
unwrappedNoParamURL: `/api/withSentryAPI/unwrapped/noParams`,
wrappedNoParamURL: `/api/withSentryAPI/wrapped/noParams`,
unwrappedDynamicURL: `/api/withSentryAPI/unwrapped/dog`,
wrappedDynamicURL: `/api/withSentryAPI/wrapped/dog`,
};

const interceptedRequests = {};

Object.entries(urls).forEach(([testName, url]) => {
interceptedRequests[testName] = interceptTracingRequest(
{
contexts: {
trace: {
op: 'http.server',
status: 'ok',
tags: { 'http.status_code': '200' },
},
},
transaction: `GET ${url.replace('dog', '[animal]')}`,
type: 'transaction',
request: {
url: `${urlBase}${url}`,
},
},
argv,
testName,
);
});

Object.values(urls).forEach(async url => await getAsync(`${urlBase}${url}`));

await sleep(500);

Object.entries(interceptedRequests).forEach(([testName, request]) =>
assert.ok(request.isDone(), `Did not intercept transaction request for ${testName}`),
);
};

0 comments on commit 08d4c47

Please sign in to comment.