Skip to content

Commit d984d7a

Browse files
onurtemizkanlforst
andauthored
test(nextjs): Refactor server-side integration tests (#6909)
Co-authored-by: Luca Forstner <[email protected]>
1 parent d737b15 commit d984d7a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+804
-1115
lines changed

packages/nextjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"test:integration": "./test/run-integration-tests.sh && yarn test:types",
7171
"test:integration:clean": "(cd test/integration && rimraf .cache node_modules build)",
7272
"test:integration:client": "yarn playwright test test/integration/test/client/",
73-
"test:integration:server": "export NODE_OPTIONS='--stack-trace-limit=25' && jest --config=test/integration/jest.config.js test/integration/test/server/",
73+
"test:integration:server": "(cd test/integration && yarn test:server)",
7474
"test:types": "cd test/types && yarn test",
7575
"test:watch": "jest --watch",
7676
"vercel:branch": "source vercel/set-up-branch-for-test-app-use.sh",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
collectCoverage: false,
12+
};
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/next12.config.template

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
const { withSentryConfig } = require('@sentry/nextjs');
22

3-
// NOTE: This will be used by integration tests to distinguish between Webpack 4 and Webpack 5
43
const moduleExports = {
5-
webpack5: %RUN_WEBPACK_5%,
64
eslint: {
75
ignoreDuringBuilds: true,
86
},
@@ -11,10 +9,7 @@ const moduleExports = {
119
// Suppress the warning message from `handleSourcemapHidingOptionWarning` in `src/config/webpack.ts`
1210
// TODO (v8): This can come out in v8, because this option will get a default value
1311
hideSourceMaps: false,
14-
excludeServerRoutes: [
15-
'/api/excludedEndpoints/excludedWithString',
16-
/\/api\/excludedEndpoints\/excludedWithRegExp/,
17-
],
12+
excludeServerRoutes: ['/api/excludedEndpoints/excludedWithString', /\/api\/excludedEndpoints\/excludedWithRegExp/],
1813
},
1914
};
2015

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const { withSentryConfig } = require('@sentry/nextjs');
2+
3+
const moduleExports = {
4+
eslint: {
5+
ignoreDuringBuilds: true,
6+
},
7+
experimental: {
8+
appDir: Number(process.env.NODE_MAJOR) >= 16, // experimental.appDir requires Node v16.8.0 or later.
9+
},
10+
pageExtensions: ['jsx', 'js', 'tsx', 'ts', 'page.tsx'],
11+
sentry: {
12+
// Suppress the warning message from `handleSourcemapHidingOptionWarning` in `src/config/webpack.ts`
13+
// TODO (v8): This can come out in v8, because this option will get a default value
14+
hideSourceMaps: false,
15+
excludeServerRoutes: ['/api/excludedEndpoints/excludedWithString', /\/api\/excludedEndpoints\/excludedWithRegExp/],
16+
},
17+
};
18+
19+
const SentryWebpackPluginOptions = {
20+
dryRun: true,
21+
silent: true,
22+
};
23+
24+
module.exports = withSentryConfig(moduleExports, SentryWebpackPluginOptions);
25+
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
const { withSentryConfig } = require('@sentry/nextjs');
22

3-
// NOTE: This will be used by integration tests to distinguish between Webpack 4 and Webpack 5
43
const moduleExports = {
5-
webpack5: %RUN_WEBPACK_5%,
64
eslint: {
75
ignoreDuringBuilds: true,
86
},
9-
experimental: {
10-
appDir: Number(process.env.NODE_MAJOR) >= 16, // experimental.appDir requires Node v16.8.0 or later.
11-
},
127
pageExtensions: ['jsx', 'js', 'tsx', 'ts', 'page.tsx'],
138
sentry: {
149
// Suppress the warning message from `handleSourcemapHidingOptionWarning` in `src/config/webpack.ts`
1510
// TODO (v8): This can come out in v8, because this option will get a default value
1611
hideSourceMaps: false,
17-
excludeServerRoutes: [
18-
'/api/excludedEndpoints/excludedWithString',
19-
/\/api\/excludedEndpoints\/excludedWithRegExp/,
20-
],
12+
excludeServerRoutes: ['/api/excludedEndpoints/excludedWithString', /\/api\/excludedEndpoints\/excludedWithRegExp/],
2113
},
2214
};
2315

@@ -27,3 +19,4 @@ const SentryWebpackPluginOptions = {
2719
};
2820

2921
module.exports = withSentryConfig(moduleExports, SentryWebpackPluginOptions);
22+

packages/nextjs/test/integration/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"predebug": "source ../integration_test_utils.sh && link_monorepo_packages '../../..' && yarn build",
88
"start": "next start",
99
"pretest": "yarn build",
10-
"test": "playwright test"
10+
"test:client": "playwright test",
11+
"test:server": "jest --detectOpenHandles --forceExit --runInBand"
1112
},
1213
"dependencies": {
1314
"@sentry/nextjs": "file:../../",

packages/nextjs/test/integration/test/client/appDirTracingPageloadClientcomponent.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { test, expect } from '@playwright/test';
44
test('should create a pageload transaction when the `app` directory is used with a client component.', async ({
55
page,
66
}) => {
7-
if (Number(process.env.NEXTJS_VERSION) < 13 || Number(process.env.NODE_MAJOR) < 16) {
8-
// Next.js versions < 13 don't support the app directory and the app dir requires Node v16.8.0 or later.
7+
if (process.env.USE_APPDIR !== 'true') {
98
return;
109
}
1110

packages/nextjs/test/integration/test/client/appDirTracingPageloadServercomponent.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { test, expect } from '@playwright/test';
44
test('should create a pageload transaction when the `app` directory is used with a server component.', async ({
55
page,
66
}) => {
7-
if (Number(process.env.NEXTJS_VERSION) < 13 || Number(process.env.NODE_MAJOR) < 16) {
8-
// Next.js versions < 13 don't support the app directory and the app dir requires Node v16.8.0 or later.
7+
if (process.env.USE_APPDIR !== 'true') {
98
return;
109
}
1110

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.

0 commit comments

Comments
 (0)