Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(nextjs): Handle CJS API route exports (#5865)
- Loading branch information
Showing
4 changed files
with
90 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/nextjs/test/integration/pages/api/withSentryAPI/unwrapped/cjsExport.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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({ success: true }); | ||
}; | ||
|
||
module.exports = handler; |
7 changes: 7 additions & 0 deletions
7
packages/nextjs/test/integration/pages/api/withSentryAPI/wrapped/cjsExport.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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({ success: true }); | ||
}; | ||
|
||
module.exports = handler; |
55 changes: 55 additions & 0 deletions
55
packages/nextjs/test/integration/test/server/cjsApiEndpoints.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const assert = require('assert'); | ||
|
||
const { sleep } = require('../utils/common'); | ||
const { getAsync, interceptTracingRequest } = require('../utils/server'); | ||
|
||
module.exports = async ({ url: urlBase, argv }) => { | ||
const unwrappedRoute = '/api/withSentryAPI/unwrapped/cjsExport'; | ||
const interceptedUnwrappedRequest = interceptTracingRequest( | ||
{ | ||
contexts: { | ||
trace: { | ||
op: 'http.server', | ||
status: 'ok', | ||
tags: { 'http.status_code': '200' }, | ||
}, | ||
}, | ||
transaction: `GET ${unwrappedRoute}`, | ||
type: 'transaction', | ||
request: { | ||
url: `${urlBase}${unwrappedRoute}`, | ||
}, | ||
}, | ||
argv, | ||
'unwrapped CJS route', | ||
); | ||
const responseUnwrapped = await getAsync(`${urlBase}${unwrappedRoute}`); | ||
assert.equal(responseUnwrapped, '{"success":true}'); | ||
|
||
const wrappedRoute = '/api/withSentryAPI/wrapped/cjsExport'; | ||
const interceptedWrappedRequest = interceptTracingRequest( | ||
{ | ||
contexts: { | ||
trace: { | ||
op: 'http.server', | ||
status: 'ok', | ||
tags: { 'http.status_code': '200' }, | ||
}, | ||
}, | ||
transaction: `GET ${wrappedRoute}`, | ||
type: 'transaction', | ||
request: { | ||
url: `${urlBase}${wrappedRoute}`, | ||
}, | ||
}, | ||
argv, | ||
'wrapped CJS route', | ||
); | ||
const responseWrapped = await getAsync(`${urlBase}${wrappedRoute}`); | ||
assert.equal(responseWrapped, '{"success":true}'); | ||
|
||
await sleep(250); | ||
|
||
assert.ok(interceptedUnwrappedRequest.isDone(), 'Did not intercept unwrapped request'); | ||
assert.ok(interceptedWrappedRequest.isDone(), 'Did not intercept wrapped request'); | ||
}; |