Skip to content

Commit 9061894

Browse files
chargomeandreiborza
authored andcommitted
feat(nextjs): Prepare for next 16 bundler default (getsentry#17868)
Next.js will switch the default bundler starting with Next.js v16 - Updated detection logic for turbopack vs webpack - Updated generic tests (app dir + pages dir) to only run on webpack (we'll need to update these as soon as next16 is released) (there are tests that won't pass on turbopack and keeping this in sync for both bundlers will become unmaintainable) - Add a bunch of unit tests - Disabled `next dev --webpack` tests for now as instrumentation breaks – tracked in [linear](https://linear.app/getsentry/issue/FE-618/webpack-breaks-instrumentation-for-dev-mode-in-next-16) - Middleware tests failing likely due to missing [Proxy support ](getsentry#17894), will split this up in a follow up pr
1 parent f2ebdf0 commit 9061894

File tree

15 files changed

+576
-54
lines changed

15 files changed

+576
-54
lines changed

dev-packages/e2e-tests/test-applications/nextjs-app-dir/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
"private": true,
55
"scripts": {
66
"build": "next build > .tmp_build_stdout 2> .tmp_build_stderr || (cat .tmp_build_stdout && cat .tmp_build_stderr && exit 1)",
7+
"build:webpack": "next build --webpack > .tmp_build_stdout 2> .tmp_build_stderr || (cat .tmp_build_stdout && cat .tmp_build_stderr && exit 1)",
78
"clean": "npx rimraf node_modules pnpm-lock.yaml",
89
"test:prod": "TEST_ENV=production playwright test",
910
"test:dev": "TEST_ENV=development playwright test",
11+
"test:dev-webpack": "TEST_ENV=development-webpack playwright test",
1012
"test:build": "pnpm install && pnpm build",
1113
"test:test-build": "pnpm ts-node --script-mode assert-build.ts",
12-
"test:build-canary": "pnpm install && pnpm add next@canary && pnpm add react@beta && pnpm add react-dom@beta && pnpm build",
14+
"test:build-canary": "pnpm install && pnpm add next@canary && pnpm add react@latest && pnpm add react-dom@latest && pnpm build:webpack",
1315
"test:build-latest": "pnpm install && pnpm add next@latest && pnpm build",
1416
"test:build-13": "pnpm install && pnpm add next@13.5.11 && pnpm build",
1517
"test:assert": "pnpm test:test-build && pnpm test:prod && pnpm test:dev"
@@ -43,7 +45,8 @@
4345
"optionalVariants": [
4446
{
4547
"build-command": "pnpm test:build-canary",
46-
"label": "nextjs-app-dir (canary)"
48+
"label": "nextjs-app-dir (canary, webpack opt-in)",
49+
"assert-command": "pnpm test:prod"
4750
},
4851
{
4952
"build-command": "pnpm test:build-latest",

dev-packages/e2e-tests/test-applications/nextjs-app-dir/playwright.config.mjs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@ if (!testEnv) {
55
throw new Error('No test env defined');
66
}
77

8+
const getStartCommand = () => {
9+
if (testEnv === 'development-webpack') {
10+
return 'pnpm next dev -p 3030 --webpack';
11+
}
12+
13+
return testEnv === 'development' ? 'pnpm next dev -p 3030' : 'pnpm next start -p 3030';
14+
};
15+
816
const config = getPlaywrightConfig({
9-
startCommand: testEnv === 'development' ? 'pnpm next dev -p 3030' : 'pnpm next start -p 3030',
17+
startCommand: getStartCommand(),
1018
port: 3030,
1119
});
1220

dev-packages/e2e-tests/test-applications/nextjs-app-dir/tests/client-errors.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { expect, test } from '@playwright/test';
22
import { waitForError } from '@sentry-internal/test-utils';
3+
import { isDevMode } from './isDevMode';
34

45
const packageJson = require('../package.json');
56

67
test('Sends a client-side exception to Sentry', async ({ page }) => {
78
const nextjsVersion = packageJson.dependencies.next;
89
const nextjsMajor = Number(nextjsVersion.split('.')[0]);
9-
const isDevMode = process.env.TEST_ENV === 'development';
1010

1111
await page.goto('/');
1212

dev-packages/e2e-tests/test-applications/nextjs-app-dir/tests/devErrorSymbolification.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { expect, test } from '@playwright/test';
22
import { waitForError } from '@sentry-internal/test-utils';
3+
import { isDevMode } from './isDevMode';
34

45
test('should have symbolicated dev errors', async ({ page }) => {
5-
test.skip(process.env.TEST_ENV !== 'development', 'should be skipped for non-dev mode');
6+
test.skip(!isDevMode, 'should be skipped for non-dev mode');
67

78
await page.goto('/');
89

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const isDevMode = !!process.env.TEST_ENV && process.env.TEST_ENV.includes('development');

dev-packages/e2e-tests/test-applications/nextjs-app-dir/tests/transactions.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { expect, test } from '@playwright/test';
22
import { waitForError, waitForTransaction } from '@sentry-internal/test-utils';
3+
import { isDevMode } from './isDevMode';
34

45
const packageJson = require('../package.json');
56

67
test('Sends a pageload transaction', async ({ page }) => {
78
const nextjsVersion = packageJson.dependencies.next;
89
const nextjsMajor = Number(nextjsVersion.split('.')[0]);
9-
const isDevMode = process.env.TEST_ENV === 'development';
1010

1111
const pageloadTransactionEventPromise = waitForTransaction('nextjs-app-dir', transactionEvent => {
1212
return transactionEvent?.contexts?.trace?.op === 'pageload' && transactionEvent?.transaction === '/';
@@ -78,8 +78,9 @@ test('Should send a transaction for instrumented server actions', async ({ page
7878
test('Should send a wrapped server action as a child of a nextjs transaction', async ({ page }) => {
7979
const nextjsVersion = packageJson.dependencies.next;
8080
const nextjsMajor = Number(nextjsVersion.split('.')[0]);
81+
8182
test.skip(!isNaN(nextjsMajor) && nextjsMajor < 14, 'only applies to nextjs apps >= version 14');
82-
test.skip(process.env.TEST_ENV === 'development', 'this magically only works in production');
83+
test.skip(isDevMode, 'this magically only works in production');
8384

8485
const nextjsPostTransactionPromise = waitForTransaction('nextjs-app-dir', async transactionEvent => {
8586
return (

dev-packages/e2e-tests/test-applications/nextjs-pages-dir/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
"private": true,
55
"scripts": {
66
"build": "next build > .tmp_build_stdout 2> .tmp_build_stderr || (cat .tmp_build_stdout && cat .tmp_build_stderr && exit 1)",
7+
"build:webpack": "next build --webpack > .tmp_build_stdout 2> .tmp_build_stderr || (cat .tmp_build_stdout && cat .tmp_build_stderr && exit 1)",
78
"clean": "npx rimraf node_modules pnpm-lock.yaml",
89
"test:prod": "TEST_ENV=production playwright test",
910
"test:dev": "TEST_ENV=development playwright test",
11+
"test:dev-webpack": "TEST_ENV=development-webpack playwright test",
1012
"test:build": "pnpm install && pnpm build",
1113
"test:test-build": "pnpm ts-node --script-mode assert-build.ts",
12-
"test:build-canary": "pnpm install && pnpm add next@canary && pnpm add react@beta && pnpm add react-dom@beta && pnpm build",
14+
"test:build-canary": "pnpm install && pnpm add next@canary && pnpm add react@latest && pnpm add react-dom@latest && pnpm build:webpack",
1315
"test:build-latest": "pnpm install && pnpm add next@latest && pnpm add react@latest && pnpm add react-dom@latest && pnpm build",
1416
"test:build-13": "pnpm install && pnpm add next@13.5.11 && pnpm build",
1517
"test:assert": "pnpm test:test-build && pnpm test:prod && pnpm test:dev"
@@ -43,7 +45,8 @@
4345
"optionalVariants": [
4446
{
4547
"build-command": "pnpm test:build-canary",
46-
"label": "nextjs-pages-dir (canary)"
48+
"label": "nextjs-pages-dir (canary, webpack opt-in)",
49+
"assert-command": "pnpm test:prod"
4750
},
4851
{
4952
"build-command": "pnpm test:build-latest",

dev-packages/e2e-tests/test-applications/nextjs-pages-dir/playwright.config.mjs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@ if (!testEnv) {
55
throw new Error('No test env defined');
66
}
77

8+
const getStartCommand = () => {
9+
if (testEnv === 'development-webpack') {
10+
return 'pnpm next dev -p 3030 --webpack';
11+
}
12+
13+
return testEnv === 'development' ? 'pnpm next dev -p 3030' : 'pnpm next start -p 3030';
14+
};
15+
816
const config = getPlaywrightConfig({
9-
startCommand: testEnv === 'development' ? 'pnpm next dev -p 3030' : 'pnpm next start -p 3030',
17+
startCommand: getStartCommand(),
1018
port: 3030,
1119
});
1220

dev-packages/e2e-tests/test-applications/nextjs-pages-dir/tests/devErrorSymbolification.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect, test } from '@playwright/test';
22
import { waitForError } from '@sentry-internal/test-utils';
33

44
test('should have symbolicated dev errors', async ({ page }) => {
5-
test.skip(process.env.TEST_ENV !== 'development', 'should be skipped for non-dev mode');
5+
test.skip(!process.env.TEST_ENV?.includes('development'), 'should be skipped for non-dev mode');
66

77
await page.goto('/');
88

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const isDevMode = !!process.env.TEST_ENV && process.env.TEST_ENV.includes('development');

0 commit comments

Comments
 (0)