@@ -25,10 +25,10 @@ describe('app-dir - server source maps', () => {
2525 if ( skipped ) return
2626
2727 it ( 'logged errors have a sourcemapped stack with a codeframe' , async ( ) => {
28- const outputIndex = next . cliOutput . length
29- await next . render ( '/rsc-error-log' )
30-
3128 if ( isNextDev ) {
29+ const outputIndex = next . cliOutput . length
30+ await next . render ( '/rsc-error-log' )
31+
3232 await retry ( ( ) => {
3333 expect ( next . cliOutput . slice ( outputIndex ) ) . toContain (
3434 'Error: rsc-error-log'
@@ -48,15 +48,28 @@ describe('app-dir - server source maps', () => {
4848 '\n'
4949 )
5050 } else {
51- // TODO: Test `next build` with `--enable-source-maps`.
51+ if ( isTurbopack ) {
52+ // TODO(veil): Sourcemap names
53+ // TODO(veil): relative paths
54+ expect ( normalizeCliOutput ( next . cliOutput ) ) . toContain (
55+ '(turbopack:///[project]/app/rsc-error-log/page.js:4:16)'
56+ )
57+ expect ( normalizeCliOutput ( next . cliOutput ) ) . toContain (
58+ '' +
59+ "\n> 4 | const error = new Error('rsc-error-log')" +
60+ '\n | ^'
61+ )
62+ } else {
63+ // TODO(veil): line/column numbers are flaky in Webpack
64+ }
5265 }
5366 } )
5467
5568 it ( 'logged errors have a sourcemapped `cause`' , async ( ) => {
56- const outputIndex = next . cliOutput . length
57- await next . render ( '/rsc-error-log-cause' )
58-
5969 if ( isNextDev ) {
70+ const outputIndex = next . cliOutput . length
71+ await next . render ( '/rsc-error-log-cause' )
72+
6073 await retry ( ( ) => {
6174 expect ( next . cliOutput . slice ( outputIndex ) ) . toContain (
6275 'Error: rsc-error-log-cause'
@@ -84,15 +97,36 @@ describe('app-dir - server source maps', () => {
8497 '\n'
8598 )
8699 } else {
87- // TODO: Test `next build` with `--enable-source-maps`.
100+ if ( isTurbopack ) {
101+ // TODO(veil): Sourcemap names
102+ // TODO(veil): relative paths
103+ expect ( normalizeCliOutput ( next . cliOutput ) ) . toContain (
104+ '(turbopack:///[project]/app/rsc-error-log-cause/page.js:2:16)'
105+ )
106+ expect ( normalizeCliOutput ( next . cliOutput ) ) . toContain (
107+ '(turbopack:///[project]/app/rsc-error-log-cause/page.js:7:16)'
108+ )
109+ expect ( normalizeCliOutput ( next . cliOutput ) ) . toContain (
110+ '' +
111+ "\n> 2 | const error = new Error('rsc-error-log-cause', { cause })" +
112+ '\n | ^'
113+ )
114+ expect ( normalizeCliOutput ( next . cliOutput ) ) . toContain (
115+ '' +
116+ "\n > 7 | const error = new Error('Boom')" +
117+ '\n | ^'
118+ )
119+ } else {
120+ // TODO(veil): line/column numbers are flaky in Webpack
121+ }
88122 }
89123 } )
90124
91125 it ( 'stack frames are ignore-listed in ssr' , async ( ) => {
92- const outputIndex = next . cliOutput . length
93- const browser = await next . browser ( '/ssr-error-log-ignore-listed' )
94-
95126 if ( isNextDev ) {
127+ const outputIndex = next . cliOutput . length
128+ const browser = await next . browser ( '/ssr-error-log-ignore-listed' )
129+
96130 await retry ( ( ) => {
97131 expect ( next . cliOutput . slice ( outputIndex ) ) . toContain (
98132 'Error: ssr-error-log-ignore-listed'
@@ -189,7 +223,19 @@ describe('app-dir - server source maps', () => {
189223 ` )
190224 }
191225 } else {
192- // TODO: Test `next build` with `--enable-source-maps`.
226+ if ( isTurbopack ) {
227+ // TODO(veil): Sourcemapping line off
228+ // TODO(veil): Sourcemap names
229+ // TODO(veil): relative paths
230+ expect ( normalizeCliOutput ( next . cliOutput ) ) . toContain (
231+ '(turbopack:///[project]/app/ssr-error-log-ignore-listed/page.js:24:2)'
232+ )
233+ expect ( normalizeCliOutput ( next . cliOutput ) ) . toContain (
234+ '\n> 24 | })\n | ^'
235+ )
236+ } else {
237+ // TODO(veil): line/column numbers are flaky in Webpack
238+ }
193239 }
194240 } )
195241
@@ -242,15 +288,28 @@ describe('app-dir - server source maps', () => {
242288 '\n'
243289 )
244290 } else {
245- // TODO: Test `next build` with `--enable-source-maps`.
291+ if ( isTurbopack ) {
292+ // TODO(veil): Sourcemap names
293+ // TODO(veil): relative paths
294+ expect ( normalizeCliOutput ( next . cliOutput ) ) . toContain (
295+ 'at <unknown> (turbopack:///[project]/app/rsc-error-log-ignore-listed/page.js:8:16)'
296+ )
297+ expect ( normalizeCliOutput ( next . cliOutput ) ) . toContain (
298+ '' +
299+ "\n> 8 | const error = new Error('rsc-error-log-ignore-listed')" +
300+ '\n | ^'
301+ )
302+ } else {
303+ // TODO(veil): line/column numbers are flaky in Webpack
304+ }
246305 }
247306 } )
248307
249308 it ( 'thrown SSR errors' , async ( ) => {
250- const outputIndex = next . cliOutput . length
251- const browser = await next . browser ( '/ssr-throw' )
252-
253309 if ( isNextDev ) {
310+ const outputIndex = next . cliOutput . length
311+ const browser = await next . browser ( '/ssr-throw' )
312+
254313 await retry ( ( ) => {
255314 expect ( next . cliOutput . slice ( outputIndex ) ) . toContain ( 'Error: ssr-throw' )
256315 } )
@@ -287,7 +346,7 @@ describe('app-dir - server source maps', () => {
287346 }
288347 ` )
289348 } else {
290- // TODO: Test `next build` with `--enable-source-maps` .
349+ // SSR errors are not logged because React retries them during hydration .
291350 }
292351 } )
293352
@@ -356,7 +415,23 @@ describe('app-dir - server source maps', () => {
356415 ) . toEqual ( 3 )
357416 }
358417 } else {
359- // TODO: test `next start` with `--enable-source-maps`
418+ if ( isTurbopack ) {
419+ // Expect the invalid sourcemap warning only once per render.
420+ expect (
421+ normalizeCliOutput ( next . cliOutput ) . split ( 'Invalid source map.' )
422+ . length - 1
423+ ) . toEqual (
424+ // >= 20
425+ // behavior in Node.js 20+ is intended
426+ process . versions . node . startsWith ( '18' ) ? 0 : 2
427+ )
428+ } else {
429+ // Webpack is silent about invalid sourcemaps for next build.
430+ expect (
431+ normalizeCliOutput ( next . cliOutput ) . split ( 'Invalid source map.' )
432+ . length - 1
433+ ) . toEqual ( 0 )
434+ }
360435 }
361436 } )
362437} )
0 commit comments