77} from 'next-test-utils'
88import stripAnsi from 'strip-ansi'
99import { nextTestSetup } from 'e2e-utils'
10+ import e from 'next/dist/compiled/cookie'
1011
1112describe ( 'middleware - development errors' , ( ) => {
1213 const { next, isTurbopack } = nextTestSetup ( {
@@ -32,23 +33,22 @@ describe('middleware - development errors', () => {
3233
3334 it ( 'logs the error correctly' , async ( ) => {
3435 await next . fetch ( '/' )
35- const output = stripAnsi ( next . cliOutput )
36- await check ( ( ) => {
37- if ( isTurbopack ) {
38- expect ( stripAnsi ( next . cliOutput ) ) . toMatch (
39- / m i d d l e w a r e .j s \( \d + : \d + \) @ _ _ T U R B O P A C K _ _ d e f a u l t _ _ e x p o r t _ _ /
40- )
41- } else {
42- expect ( stripAnsi ( next . cliOutput ) ) . toMatch (
43- / m i d d l e w a r e .j s \( \d + : \d + \) @ d e f a u l t /
44- )
45- }
46-
47- expect ( stripAnsi ( next . cliOutput ) ) . toMatch ( / b o o m / )
48- return 'success'
49- } , 'success' )
50- expect ( output ) . not . toContain (
51- 'webpack-internal:///(middleware)/./middleware.js'
36+
37+ await retry ( ( ) => {
38+ expect ( stripAnsi ( next . cliOutput ) ) . toContain ( 'boom' )
39+ } )
40+ // TODO: assert on full, ignore-listed stack
41+ expect ( stripAnsi ( next . cliOutput ) ) . toContain (
42+ isTurbopack
43+ ? '\n ⨯ middleware.js (3:15) @ __TURBOPACK__default__export__' +
44+ '\n ⨯ Error: boom' +
45+ '\n at __TURBOPACK__default__export__ (./middleware.js:3:15)'
46+ : '\n ⨯ middleware.js (3:15) @ default' +
47+ '\n ⨯ boom' +
48+ '\n 1 |' +
49+ '\n 2 | export default function () {' +
50+ "\n> 3 | throw new Error('boom')" +
51+ '\n | ^'
5252 )
5353 } )
5454
@@ -80,13 +80,20 @@ describe('middleware - development errors', () => {
8080
8181 it ( 'logs the error correctly' , async ( ) => {
8282 await next . fetch ( '/' )
83- await check (
84- ( ) => stripAnsi ( next . cliOutput ) ,
85- new RegExp ( `unhandledRejection: Error: async boom!` , 'm' )
83+
84+ await retry ( ( ) => {
85+ expect ( stripAnsi ( next . cliOutput ) ) . toContain (
86+ 'unhandledRejection: Error: async boom!'
87+ )
88+ } )
89+ // TODO: assert on full, ignore-listed stack
90+ expect ( stripAnsi ( next . cliOutput ) ) . toContain (
91+ isTurbopack
92+ ? 'unhandledRejection: Error: async boom!\n at throwError ('
93+ : 'unhandledRejection: Error: async boom!' +
94+ '\n at throwError (webpack-internal:///(middleware)/./middleware.js:8:11)' +
95+ '\n at __WEBPACK_DEFAULT_EXPORT__ (webpack-internal:///(middleware)/./middleware.js:11:5)'
8696 )
87- // expect(output).not.toContain(
88- // 'webpack-internal:///(middleware)/./middleware.js'
89- // )
9097 } )
9198
9299 it ( 'does not render the error' , async ( ) => {
@@ -113,17 +120,37 @@ describe('middleware - development errors', () => {
113120
114121 it ( 'logs the error correctly' , async ( ) => {
115122 await next . fetch ( '/' )
116- // const output = stripAnsi(next.cliOutput)
117- await check ( ( ) => {
118- expect ( stripAnsi ( next . cliOutput ) ) . toMatch (
119- / m i d d l e w a r e .j s \( \d + : \d + \) @ e v a l /
123+
124+ await retry ( ( ) => {
125+ expect ( stripAnsi ( next . cliOutput ) ) . toContain ( 'Dynamic Code Evaluation' )
126+ } )
127+ // TODO: assert on full, ignore-listed stack
128+ if ( isTurbopack ) {
129+ // Locally, prefixes the "test is not defined".
130+ // In CI, it prefixes "Dynamic Code Evaluation".
131+ expect ( stripAnsi ( next . cliOutput ) ) . toContain (
132+ '\n ⚠ middleware.js (3:22) @ __TURBOPACK__default__export__' +
133+ '\n ⨯ middleware.js (4:9) @ eval'
120134 )
121- expect ( stripAnsi ( next . cliOutput ) ) . toMatch ( / t e s t i s n o t d e f i n e d / )
122- return 'success'
123- } , 'success' )
124- // expect(output).not.toContain(
125- // 'webpack-internal:///(middleware)/./middleware.js'
126- // )
135+ }
136+ expect ( stripAnsi ( next . cliOutput ) ) . toContain (
137+ isTurbopack
138+ ? '\n ⨯ Error: test is not defined' +
139+ '\n at eval (./middleware.js:4:9)' +
140+ '\n at <unknown> (./middleware.js:4:9'
141+ : '\n ⨯ Error [ReferenceError]: test is not defined' +
142+ '\n at eval (file://webpack-internal:///(middleware)/./middleware.js)' +
143+ '\n at eval (webpack://_N_E/middleware.js?3bcb:4:8)'
144+ )
145+ expect ( stripAnsi ( next . cliOutput ) ) . toContain (
146+ isTurbopack
147+ ? "\n ⚠ Error: Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime" +
148+ '\nLearn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation' +
149+ '\n at __TURBOPACK__default__export__ (./middleware.js:3:22)'
150+ : '\n ⚠ middleware.js (4:9) @ eval' +
151+ "\n ⚠ Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime" +
152+ '\nLearn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation'
153+ )
127154 } )
128155
129156 it ( 'renders the error correctly and recovers' , async ( ) => {
@@ -153,9 +180,9 @@ describe('middleware - development errors', () => {
153180 await next . fetch ( '/' )
154181
155182 await retry ( ( ) => {
156- expect ( next . cliOutput ) . toContain ( `Error: booooom!` )
183+ expect ( stripAnsi ( next . cliOutput ) ) . toContain ( `Error: booooom!` )
157184 } )
158-
185+ // TODO: assert on full, ignore-listed stack
159186 expect ( stripAnsi ( next . cliOutput ) ) . toContain (
160187 isTurbopack
161188 ? '\n ⨯ middleware.js (3:13) @ [project]/middleware.js [middleware] (ecmascript)' +
0 commit comments