Skip to content

test(nextjs): Refactor server-side integration tests #6909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"test:integration": "./test/run-integration-tests.sh && yarn test:types",
"test:integration:clean": "(cd test/integration && rimraf .cache node_modules build)",
"test:integration:client": "yarn playwright test test/integration/test/client/",
"test:integration:server": "export NODE_OPTIONS='--stack-trace-limit=25' && jest --config=test/integration/jest.config.js test/integration/test/server/",
"test:integration:server": "(cd test/integration && yarn test:server)",
"test:types": "cd test/types && yarn test",
"test:watch": "jest --watch",
"vercel:branch": "source vercel/set-up-branch-for-test-app-use.sh",
Expand Down
12 changes: 12 additions & 0 deletions packages/nextjs/test/integration/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const baseConfig = require('../../jest.config.js');

module.exports = {
...baseConfig,
testMatch: [`${__dirname}/test/server/**/*.test.ts`],
testPathIgnorePatterns: [`${__dirname}/test/client`],
detectOpenHandles: true,
forceExit: true,
testTimeout: 30000,
setupFilesAfterEnv: [`${__dirname}/jest.setup.js`],
collectCoverage: false,
};
8 changes: 8 additions & 0 deletions packages/nextjs/test/integration/jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
global.console = {
...console,
log: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
// console.debug is available
};
7 changes: 1 addition & 6 deletions packages/nextjs/test/integration/next12.config.template
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const { withSentryConfig } = require('@sentry/nextjs');

// NOTE: This will be used by integration tests to distinguish between Webpack 4 and Webpack 5
const moduleExports = {
webpack5: %RUN_WEBPACK_5%,
eslint: {
ignoreDuringBuilds: true,
},
Expand All @@ -11,10 +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/,
],
excludeServerRoutes: ['/api/excludedEndpoints/excludedWithString', /\/api\/excludedEndpoints\/excludedWithRegExp/],
},
};

Expand Down
25 changes: 25 additions & 0 deletions packages/nextjs/test/integration/next13.appdir.config.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const { withSentryConfig } = require('@sentry/nextjs');

const moduleExports = {
eslint: {
ignoreDuringBuilds: true,
},
experimental: {
appDir: Number(process.env.NODE_MAJOR) >= 16, // experimental.appDir requires Node v16.8.0 or later.
},
pageExtensions: ['jsx', 'js', 'tsx', 'ts', 'page.tsx'],
sentry: {
// 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 = {
dryRun: true,
silent: true,
};

module.exports = withSentryConfig(moduleExports, SentryWebpackPluginOptions);

11 changes: 2 additions & 9 deletions packages/nextjs/test/integration/next13.config.template
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
const { withSentryConfig } = require('@sentry/nextjs');

// NOTE: This will be used by integration tests to distinguish between Webpack 4 and Webpack 5
const moduleExports = {
webpack5: %RUN_WEBPACK_5%,
eslint: {
ignoreDuringBuilds: true,
},
experimental: {
appDir: Number(process.env.NODE_MAJOR) >= 16, // experimental.appDir requires Node v16.8.0 or later.
},
pageExtensions: ['jsx', 'js', 'tsx', 'ts', 'page.tsx'],
sentry: {
// 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/,
],
excludeServerRoutes: ['/api/excludedEndpoints/excludedWithString', /\/api\/excludedEndpoints\/excludedWithRegExp/],
},
};

Expand All @@ -27,3 +19,4 @@ const SentryWebpackPluginOptions = {
};

module.exports = withSentryConfig(moduleExports, SentryWebpackPluginOptions);

3 changes: 2 additions & 1 deletion packages/nextjs/test/integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"predebug": "source ../integration_test_utils.sh && link_monorepo_packages '../../..' && yarn build",
"start": "next start",
"pretest": "yarn build",
"test": "playwright test"
"test:client": "playwright test",
"test:server": "jest --detectOpenHandles --forceExit --runInBand"
},
"dependencies": {
"@sentry/nextjs": "file:../../",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { test, expect } from '@playwright/test';
test('should create a pageload transaction when the `app` directory is used with a client component.', async ({
page,
}) => {
if (Number(process.env.NEXTJS_VERSION) < 13 || Number(process.env.NODE_MAJOR) < 16) {
// Next.js versions < 13 don't support the app directory and the app dir requires Node v16.8.0 or later.
if (process.env.USE_APPDIR !== 'true') {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { test, expect } from '@playwright/test';
test('should create a pageload transaction when the `app` directory is used with a server component.', async ({
page,
}) => {
if (Number(process.env.NEXTJS_VERSION) < 13 || Number(process.env.NODE_MAJOR) < 16) {
// Next.js versions < 13 don't support the app directory and the app dir requires Node v16.8.0 or later.
if (process.env.USE_APPDIR !== 'true') {
return;
}

Expand Down
130 changes: 0 additions & 130 deletions packages/nextjs/test/integration/test/runner.js

This file was deleted.

18 changes: 0 additions & 18 deletions packages/nextjs/test/integration/test/server.js

This file was deleted.

55 changes: 0 additions & 55 deletions packages/nextjs/test/integration/test/server/cjsApiEndpoints.js

This file was deleted.

Loading