Skip to content

Commit

Permalink
add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lobsterkatie committed Nov 15, 2022
1 parent c7b7c30 commit e90999f
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/nextjs/test/integration/next.config.js
Expand Up @@ -9,6 +9,7 @@ const moduleExports = {
// Suppress the warning message from `handleSourcemapHidingOptionWarning` in `src/config/webpack.ts`
// TODO (v8): This can come out in v8, because this option will get a default value
hideSourceMaps: false,
excludeServerRoutes: ['/api/excludedEndpoints/excludedWithString', /\/api\/excludedEndpoints\/excludedWithRegExp/],
},
};
const SentryWebpackPluginOptions = {
Expand Down
4 changes: 4 additions & 0 deletions packages/nextjs/test/integration/next10.config.template
Expand Up @@ -10,6 +10,10 @@ const moduleExports = {
// Suppress the warning message from `handleSourcemapHidingOptionWarning` in `src/config/webpack.ts`
// TODO (v8): This can come out in v8, because this option will get a default value
hideSourceMaps: false,
excludeServerRoutes: [
'/api/excludedEndpoints/excludedWithString',
/\/api\/excludedEndpoints\/excludedWithRegExp/,
],
},
};

Expand Down
4 changes: 4 additions & 0 deletions packages/nextjs/test/integration/next11.config.template
Expand Up @@ -11,6 +11,10 @@ const moduleExports = {
// Suppress the warning message from `handleSourcemapHidingOptionWarning` in `src/config/webpack.ts`
// TODO (v8): This can come out in v8, because this option will get a default value
hideSourceMaps: false,
excludeServerRoutes: [
'/api/excludedEndpoints/excludedWithString',
/\/api\/excludedEndpoints\/excludedWithRegExp/,
],
},
};

Expand Down
@@ -0,0 +1,6 @@
// This file will test the `excludeServerRoutes` option when a route is provided as a RegExp.
const handler = async (): Promise<void> => {
throw new Error('API Error');
};

export default handler;
@@ -0,0 +1,6 @@
// This file will test the `excludeServerRoutes` option when a route is provided as a string.
const handler = async (): Promise<void> => {
throw new Error('API Error');
};

export default handler;
@@ -0,0 +1,67 @@
const assert = require('assert');

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

module.exports = async ({ url: urlBase, argv }) => {
const regExpUrl = `${urlBase}/api/excludedEndpoints/excludedWithRegExp`;
const stringUrl = `${urlBase}/api/excludedEndpoints/excludedWithString`;

const capturedRegExpErrorRequest = interceptEventRequest(
{
exception: {
values: [
{
type: 'Error',
value: 'API Error',
},
],
},
tags: {
runtime: 'node',
},
request: {
url: regExpUrl,
method: 'GET',
},
transaction: 'GET /api/excludedEndpoints/excludedWithRegExp',
},
argv,
'excluded API endpoint via RegExp',
);

const capturedStringErrorRequest = interceptEventRequest(
{
exception: {
values: [
{
type: 'Error',
value: 'API Error',
},
],
},
tags: {
runtime: 'node',
},
request: {
url: regExpUrl,
method: 'GET',
},
transaction: 'GET /api/excludedEndpoints/excludedWithString',
},
argv,
'excluded API endpoint via String',
);

await Promise.all([getAsync(regExpUrl), getAsync(stringUrl)]);
await sleep(250);

assert.ok(
!capturedRegExpErrorRequest.isDone(),
'Did intercept error request even though route should be excluded (RegExp)',
);
assert.ok(
!capturedStringErrorRequest.isDone(),
'Did intercept error request even though route should be excluded (String)',
);
};

0 comments on commit e90999f

Please sign in to comment.