33 assertNoRedbox ,
44 check ,
55 getRedboxSource ,
6+ retry ,
67} from 'next-test-utils'
78import stripAnsi from 'strip-ansi'
89import { nextTestSetup } from 'e2e-utils'
@@ -31,23 +32,22 @@ describe('middleware - development errors', () => {
3132
3233 it ( 'logs the error correctly' , async ( ) => {
3334 await next . fetch ( '/' )
34- const output = stripAnsi ( next . cliOutput )
35- await check ( ( ) => {
36- if ( isTurbopack ) {
37- expect ( stripAnsi ( next . cliOutput ) ) . toMatch (
38- / 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 _ _ /
39- )
40- } else {
41- expect ( stripAnsi ( next . cliOutput ) ) . toMatch (
42- / m i d d l e w a r e .j s \( \d + : \d + \) @ d e f a u l t /
43- )
44- }
45-
46- expect ( stripAnsi ( next . cliOutput ) ) . toMatch ( / b o o m / )
47- return 'success'
48- } , 'success' )
49- expect ( output ) . not . toContain (
50- 'webpack-internal:///(middleware)/./middleware.js'
35+
36+ await retry ( ( ) => {
37+ expect ( stripAnsi ( next . cliOutput ) ) . toContain ( 'boom' )
38+ } )
39+ // TODO: assert on full, ignore-listed stack
40+ expect ( stripAnsi ( next . cliOutput ) ) . toContain (
41+ isTurbopack
42+ ? '\n ⨯ middleware.js (3:15) @ __TURBOPACK__default__export__' +
43+ '\n ⨯ Error: boom' +
44+ '\n at __TURBOPACK__default__export__ (./middleware.js:3:15)'
45+ : '\n ⨯ middleware.js (3:15) @ default' +
46+ '\n ⨯ boom' +
47+ '\n 1 |' +
48+ '\n 2 | export default function () {' +
49+ "\n> 3 | throw new Error('boom')" +
50+ '\n | ^'
5151 )
5252 } )
5353
@@ -79,13 +79,20 @@ describe('middleware - development errors', () => {
7979
8080 it ( 'logs the error correctly' , async ( ) => {
8181 await next . fetch ( '/' )
82- await check (
83- ( ) => stripAnsi ( next . cliOutput ) ,
84- new RegExp ( `unhandledRejection: Error: async boom!` , 'm' )
82+
83+ await retry ( ( ) => {
84+ expect ( stripAnsi ( next . cliOutput ) ) . toContain (
85+ 'unhandledRejection: Error: async boom!'
86+ )
87+ } )
88+ // TODO: assert on full, ignore-listed stack
89+ expect ( stripAnsi ( next . cliOutput ) ) . toContain (
90+ isTurbopack
91+ ? 'unhandledRejection: Error: async boom!\n at throwError ('
92+ : 'unhandledRejection: Error: async boom!' +
93+ '\n at throwError (webpack-internal:///(middleware)/./middleware.js:8:11)' +
94+ '\n at __WEBPACK_DEFAULT_EXPORT__ (webpack-internal:///(middleware)/./middleware.js:11:5)'
8595 )
86- // expect(output).not.toContain(
87- // 'webpack-internal:///(middleware)/./middleware.js'
88- // )
8996 } )
9097
9198 it ( 'does not render the error' , async ( ) => {
@@ -112,17 +119,37 @@ describe('middleware - development errors', () => {
112119
113120 it ( 'logs the error correctly' , async ( ) => {
114121 await next . fetch ( '/' )
115- // const output = stripAnsi(next.cliOutput)
116- await check ( ( ) => {
117- expect ( stripAnsi ( next . cliOutput ) ) . toMatch (
118- / m i d d l e w a r e .j s \( \d + : \d + \) @ e v a l /
122+
123+ await retry ( ( ) => {
124+ expect ( stripAnsi ( next . cliOutput ) ) . toContain ( 'Dynamic Code Evaluation' )
125+ } )
126+ // TODO: assert on full, ignore-listed stack
127+ if ( isTurbopack ) {
128+ // Locally, prefixes the "test is not defined".
129+ // In CI, it prefixes "Dynamic Code Evaluation".
130+ expect ( stripAnsi ( next . cliOutput ) ) . toContain (
131+ '\n ⚠ middleware.js (3:22) @ __TURBOPACK__default__export__' +
132+ '\n ⨯ middleware.js (4:9) @ eval'
119133 )
120- expect ( stripAnsi ( next . cliOutput ) ) . toMatch ( / t e s t i s n o t d e f i n e d / )
121- return 'success'
122- } , 'success' )
123- // expect(output).not.toContain(
124- // 'webpack-internal:///(middleware)/./middleware.js'
125- // )
134+ }
135+ expect ( stripAnsi ( next . cliOutput ) ) . toContain (
136+ isTurbopack
137+ ? '\n ⨯ Error: test is not defined' +
138+ '\n at eval (./middleware.js:4:9)' +
139+ '\n at <unknown> (./middleware.js:4:9'
140+ : '\n ⨯ Error [ReferenceError]: test is not defined' +
141+ '\n at eval (file://webpack-internal:///(middleware)/./middleware.js)' +
142+ '\n at eval (webpack://_N_E/middleware.js?3bcb:4:8)'
143+ )
144+ expect ( stripAnsi ( next . cliOutput ) ) . toContain (
145+ isTurbopack
146+ ? "\n ⚠ Error: Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime" +
147+ '\nLearn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation' +
148+ '\n at __TURBOPACK__default__export__ (./middleware.js:3:22)'
149+ : '\n ⚠ middleware.js (4:9) @ eval' +
150+ "\n ⚠ Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime" +
151+ '\nLearn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation'
152+ )
126153 } )
127154
128155 it ( 'renders the error correctly and recovers' , async ( ) => {
@@ -150,22 +177,18 @@ describe('middleware - development errors', () => {
150177
151178 it ( 'logs the error correctly' , async ( ) => {
152179 await next . fetch ( '/' )
153- const output = stripAnsi ( next . cliOutput )
154- await check ( ( ) => {
155- if ( isTurbopack ) {
156- expect ( stripAnsi ( next . cliOutput ) ) . toMatch (
157- / m i d d l e w a r e .j s \( \d + : \d + \) @ \[ p r o j e c t \] \/ m i d d l e w a r e \. j s \[ m i d d l e w a r e \] \( e c m a s c r i p t \) /
158- )
159- } else {
160- expect ( stripAnsi ( next . cliOutput ) ) . toMatch (
161- / m i d d l e w a r e .j s \( \d + : \d + \) @ < u n k n o w n > /
162- )
163- }
164- expect ( stripAnsi ( next . cliOutput ) ) . toMatch ( / b o o o o o m ! / )
165- return 'success'
166- } , 'success' )
167- expect ( output ) . not . toContain (
168- 'webpack-internal:///(middleware)/./middleware.js'
180+
181+ await retry ( ( ) => {
182+ expect ( stripAnsi ( next . cliOutput ) ) . toContain ( `Error: booooom!` )
183+ } )
184+ // TODO: assert on full, ignore-listed stack
185+ expect ( stripAnsi ( next . cliOutput ) ) . toContain (
186+ isTurbopack
187+ ? '\n ⨯ middleware.js (3:13) @ [project]/middleware.js [middleware] (ecmascript)' +
188+ '\n ⨯ Error: booooom!' +
189+ '\n at <unknown> ([project]/middleware.js [middleware] (ecmascript) (./middleware.js:3:13)'
190+ : '\n ⨯ Error: booooom!' +
191+ '\n at <unknown> (webpack://_N_E/middleware.js'
169192 )
170193 } )
171194
0 commit comments