Skip to content

Commit 39a5c57

Browse files
committed
test(nextjs): New server-side integration tests.
1 parent 1476a1f commit 39a5c57

37 files changed

+776
-984
lines changed

packages/nextjs/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ module.exports = {
44
...baseConfig,
55
// This prevents the build tests from running when unit tests run. (If they do, they fail, because the build being
66
// tested hasn't necessarily run yet.)
7-
testPathIgnorePatterns: ['<rootDir>/test/buildProcess/', '<rootDir>/test/integration/'],
7+
testPathIgnorePatterns: ['<rootDir>/test/buildProcess/'],
88
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const baseConfig = require('../../jest.config.js');
2+
3+
module.exports = {
4+
...baseConfig,
5+
testMatch: [`${__dirname}/test/server/**/*.test.ts`],
6+
testPathIgnorePatterns: [`${__dirname}/test/client`],
7+
detectOpenHandles: true,
8+
forceExit: true,
9+
testTimeout: 30000,
10+
setupFilesAfterEnv: [`${__dirname}/jest.setup.js`],
11+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
global.console = {
2+
...console,
3+
log: jest.fn(),
4+
info: jest.fn(),
5+
warn: jest.fn(),
6+
error: jest.fn(),
7+
// console.debug is available
8+
};

packages/nextjs/test/integration/test/runner.js

Lines changed: 0 additions & 130 deletions
This file was deleted.

packages/nextjs/test/integration/test/server.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

packages/nextjs/test/integration/test/server/cjsApiEndpoints.js

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { NextTestEnv } from '../utils/server';
2+
3+
describe('CommonJS API Endpoints', () => {
4+
it('should not intercept unwrapped request', async () => {
5+
const env = await NextTestEnv.init();
6+
const unwrappedRoute = '/api/wrapApiHandlerWithSentry/unwrapped/cjsExport';
7+
const url = `${env.url}${unwrappedRoute}`;
8+
9+
const unwrappedEnvelope = await env.getEnvelopeRequest({
10+
url,
11+
envelopeType: 'transaction',
12+
endServer: false,
13+
});
14+
15+
expect(unwrappedEnvelope[2]).toMatchObject({
16+
contexts: {
17+
trace: {
18+
op: 'http.server',
19+
status: 'ok',
20+
tags: { 'http.status_code': '200' },
21+
},
22+
},
23+
transaction: `GET ${unwrappedRoute}`,
24+
type: 'transaction',
25+
request: {
26+
url,
27+
},
28+
});
29+
30+
const response = await env.getAPIResponse(url);
31+
32+
expect(response).toMatchObject({
33+
success: true,
34+
});
35+
});
36+
37+
it('should intercept wrapped request', async () => {
38+
const env = await NextTestEnv.init();
39+
const wrappedRoute = '/api/wrapApiHandlerWithSentry/wrapped/cjsExport';
40+
const url = `${env.url}${wrappedRoute}`;
41+
42+
const wrappedEnvelope = await env.getEnvelopeRequest({
43+
url,
44+
envelopeType: 'transaction',
45+
endServer: false,
46+
});
47+
48+
expect(wrappedEnvelope[2]).toMatchObject({
49+
contexts: {
50+
trace: {
51+
op: 'http.server',
52+
status: 'ok',
53+
tags: { 'http.status_code': '200' },
54+
},
55+
},
56+
transaction: `GET ${wrappedRoute}`,
57+
type: 'transaction',
58+
request: {
59+
url,
60+
},
61+
});
62+
63+
const response = await env.getAPIResponse(url);
64+
65+
expect(response).toMatchObject({
66+
success: true,
67+
});
68+
});
69+
});

packages/nextjs/test/integration/test/server/doubleEndMethodOnVercel.js

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { NextTestEnv } from '../utils/server';
2+
3+
// This test asserts that our wrapping of `res.end` doesn't break API routes on Vercel if people call `res.json` or
4+
// `res.send` multiple times in one request handler.
5+
// https://github.com/getsentry/sentry-javascript/issues/6670
6+
it.skip('should not break API routes on Vercel if people call res.json or res.send multiple times in one request handler', async () => {
7+
if (process.env.NODE_MAJOR === '10') {
8+
console.log('not running doubleEndMethodOnVercel test on Node 10');
9+
return;
10+
}
11+
const env = await NextTestEnv.init();
12+
const url = `${env.url}/api/doubleEndMethodOnVercel`;
13+
const response = await env.getAPIResponse(url);
14+
15+
expect(response).toMatchObject({
16+
success: true,
17+
});
18+
});

packages/nextjs/test/integration/test/server/errorApiEndpoint.js

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)