From e1dbf7c98a490d9e1bfc071f3459c0d654426970 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Tue, 20 Sep 2022 21:43:12 -0700 Subject: [PATCH] add integration tests --- .../api/withSentryAPI/unwrapped/[animal].ts | 7 +++ .../api/withSentryAPI/unwrapped/noParams.ts | 7 +++ .../api/withSentryAPI/wrapped/[animal].ts | 8 ++++ .../api/withSentryAPI/wrapped/noParams.ts | 8 ++++ .../test/server/tracingWithSentryAPI.js | 45 +++++++++++++++++++ 5 files changed, 75 insertions(+) create mode 100644 packages/nextjs/test/integration/pages/api/withSentryAPI/unwrapped/[animal].ts create mode 100644 packages/nextjs/test/integration/pages/api/withSentryAPI/unwrapped/noParams.ts create mode 100644 packages/nextjs/test/integration/pages/api/withSentryAPI/wrapped/[animal].ts create mode 100644 packages/nextjs/test/integration/pages/api/withSentryAPI/wrapped/noParams.ts create mode 100644 packages/nextjs/test/integration/test/server/tracingWithSentryAPI.js diff --git a/packages/nextjs/test/integration/pages/api/withSentryAPI/unwrapped/[animal].ts b/packages/nextjs/test/integration/pages/api/withSentryAPI/unwrapped/[animal].ts new file mode 100644 index 000000000000..3307b12037d5 --- /dev/null +++ b/packages/nextjs/test/integration/pages/api/withSentryAPI/unwrapped/[animal].ts @@ -0,0 +1,7 @@ +import { NextApiRequest, NextApiResponse } from 'next'; + +const handler = async (_req: NextApiRequest, res: NextApiResponse): Promise => { + res.status(200).json({}); +}; + +export default handler; diff --git a/packages/nextjs/test/integration/pages/api/withSentryAPI/unwrapped/noParams.ts b/packages/nextjs/test/integration/pages/api/withSentryAPI/unwrapped/noParams.ts new file mode 100644 index 000000000000..3307b12037d5 --- /dev/null +++ b/packages/nextjs/test/integration/pages/api/withSentryAPI/unwrapped/noParams.ts @@ -0,0 +1,7 @@ +import { NextApiRequest, NextApiResponse } from 'next'; + +const handler = async (_req: NextApiRequest, res: NextApiResponse): Promise => { + res.status(200).json({}); +}; + +export default handler; diff --git a/packages/nextjs/test/integration/pages/api/withSentryAPI/wrapped/[animal].ts b/packages/nextjs/test/integration/pages/api/withSentryAPI/wrapped/[animal].ts new file mode 100644 index 000000000000..e048d9d27c0f --- /dev/null +++ b/packages/nextjs/test/integration/pages/api/withSentryAPI/wrapped/[animal].ts @@ -0,0 +1,8 @@ +import { withSentry } from '@sentry/nextjs'; +import { NextApiRequest, NextApiResponse } from 'next'; + +const handler = async (_req: NextApiRequest, res: NextApiResponse): Promise => { + res.status(200).json({}); +}; + +export default withSentry(handler); diff --git a/packages/nextjs/test/integration/pages/api/withSentryAPI/wrapped/noParams.ts b/packages/nextjs/test/integration/pages/api/withSentryAPI/wrapped/noParams.ts new file mode 100644 index 000000000000..e048d9d27c0f --- /dev/null +++ b/packages/nextjs/test/integration/pages/api/withSentryAPI/wrapped/noParams.ts @@ -0,0 +1,8 @@ +import { withSentry } from '@sentry/nextjs'; +import { NextApiRequest, NextApiResponse } from 'next'; + +const handler = async (_req: NextApiRequest, res: NextApiResponse): Promise => { + res.status(200).json({}); +}; + +export default withSentry(handler); diff --git a/packages/nextjs/test/integration/test/server/tracingWithSentryAPI.js b/packages/nextjs/test/integration/test/server/tracingWithSentryAPI.js new file mode 100644 index 000000000000..7348b1bcdfc0 --- /dev/null +++ b/packages/nextjs/test/integration/test/server/tracingWithSentryAPI.js @@ -0,0 +1,45 @@ +const assert = require('assert'); + +const { sleep } = require('../utils/common'); +const { getAsync, 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, + ); + }); + + // Wait until all four requests have completed + await Promise.all(Object.values(urls).map(url => getAsync(`${urlBase}${url}`))); + + await sleep(250); + + Object.entries(interceptedRequests).forEach(([testName, request]) => + assert.ok(request.isDone(), `Did not intercept transaction request for ${testName}`), + ); +};