@@ -204,17 +204,23 @@ describeWithMockConnection('ConsoleViewMessage', () => {
204204 assert . isTrue ( showLess . checkVisibility ( ) ) ;
205205 }
206206
207- function errorMessageForStack ( stack : Protocol . Runtime . StackTrace ) {
208- return [
207+ function errorMessageForStack ( stack : Protocol . Runtime . StackTrace , withBuiltinFrames ?: boolean ) {
208+ const lines = [
209209 'Error:' ,
210- ...( stack . callFrames . map (
211- frame => ` at ${ frame . functionName } (${ frame . url } :${ frame . lineNumber } :${ frame . columnNumber } )` ) ) ,
212- ] . join ( '\n' ) ;
210+ ...( stack . callFrames . flatMap ( frame => {
211+ const line = ` at ${ frame . functionName } (${ frame . url } :${ frame . lineNumber } :${ frame . columnNumber } )` ;
212+ if ( withBuiltinFrames ) {
213+ return [ line , ' at JSON.parse (<anonymous>)' ] ;
214+ }
215+ return [ line ] ;
216+ } ) ) ,
217+ ] ;
218+ return lines . join ( '\n' ) ;
213219 }
214220
215221 function getCallFrames ( element : HTMLElement ) : string [ ] {
216222 const results = [ ] ;
217- for ( const line of element . querySelectorAll ( '.formatted-stack-frame' ) ) {
223+ for ( const line of element . querySelectorAll ( '.formatted-stack-frame,.formatted-builtin-stack-frame ' ) ) {
218224 if ( line . checkVisibility ( ) ) {
219225 results . push ( line . textContent ?? 'Error: line was null or undefined' ) ;
220226 }
@@ -246,15 +252,16 @@ describeWithMockConnection('ConsoleViewMessage', () => {
246252 ( showLess . querySelector ( '.link' ) as HTMLElement ) . click ( ) ;
247253 }
248254
249- async function createConsoleMessageWithIgnoreListing ( ignoreListFn : ( url : string ) => Boolean ) : Promise < HTMLElement > {
255+ async function createConsoleMessageWithIgnoreListing (
256+ ignoreListFn : ( url : string ) => Boolean , withBuiltinFrames ?: boolean ) : Promise < HTMLElement > {
250257 const target = createTarget ( ) ;
251258 const runtimeModel = target . model ( SDK . RuntimeModel . RuntimeModel ) ;
252259 const stackTrace = createStackTrace ( [
253260 'USER_ID::userNestedFunction::http://example.com/script.js::40::15' ,
254261 'USER_ID::userFunction::http://example.com/script.js::10::2' ,
255262 'APP_ID::entry::http://example.com/app.js::25::10' ,
256263 ] ) ;
257- const stackTraceMessage = errorMessageForStack ( stackTrace ) ;
264+ const stackTraceMessage = errorMessageForStack ( stackTrace , withBuiltinFrames ) ;
258265 const messageDetails = {
259266 type : Protocol . Runtime . ConsoleAPICalledEventType . Error ,
260267 stackTrace,
@@ -305,6 +312,20 @@ describeWithMockConnection('ConsoleViewMessage', () => {
305312 ' at userNestedFunction (/script.js:40:15)\n' ,
306313 ' at userFunction (/script.js:10:2)\n' ,
307314 ] ;
315+ const EXPANDED_UNSTRUCTURED_WITH_BUILTIN = [
316+ ' at userNestedFunction (/script.js:40:15)\n' ,
317+ ' at JSON.parse (<anonymous>)\n' ,
318+ ' at userFunction (/script.js:10:2)\n' ,
319+ ' at JSON.parse (<anonymous>)\n' ,
320+ ' at entry (/app.js:25:10)\n' ,
321+ ' at JSON.parse (<anonymous>)' ,
322+ ] ;
323+ const COLLAPSED_UNSTRUCTURED_WITH_BUILTIN = [
324+ ' at userNestedFunction (/script.js:40:15)\n' ,
325+ ' at JSON.parse (<anonymous>)\n' ,
326+ ' at userFunction (/script.js:10:2)\n' ,
327+ ' at JSON.parse (<anonymous>)\n' ,
328+ ] ;
308329 const EXPANDED_STRUCTURED = [
309330 '\nuserNestedFunction @ example.com/script.js:41' ,
310331 '\nuserFunction @ example.com/script.js:11' ,
@@ -360,5 +381,51 @@ describeWithMockConnection('ConsoleViewMessage', () => {
360381 assert . deepEqual ( getStructuredCallFrames ( element ) , COLLAPSED_STRUCTURED ) ;
361382 assert . deepEqual ( getCallFrames ( element ) , COLLAPSED_UNSTRUCTURED ) ;
362383 } ) ;
384+
385+ it ( 'shows everything with no links when nothing is ignore listed, including builtin frames' , async ( ) => {
386+ const element = await createConsoleMessageWithIgnoreListing ( _ => false , true ) ;
387+ assertNoLinks ( element ) ;
388+ assert . deepEqual ( getCallFrames ( element ) , EXPANDED_UNSTRUCTURED_WITH_BUILTIN ) ;
389+ assert . deepEqual ( getStructuredCallFrames ( element ) , [ ] ) ;
390+ expandStructuredTrace ( element ) ;
391+ assertNoLinks ( element ) ;
392+ assert . deepEqual ( getStructuredCallFrames ( element ) , EXPANDED_STRUCTURED ) ;
393+ } ) ;
394+
395+ it ( 'shows everything with no links when everything is ignore listed, including builtin frames' , async ( ) => {
396+ const element = await createConsoleMessageWithIgnoreListing ( _ => true , true ) ;
397+ assertNoLinks ( element ) ;
398+ assert . deepEqual ( getCallFrames ( element ) , EXPANDED_UNSTRUCTURED_WITH_BUILTIN ) ;
399+ assert . deepEqual ( getStructuredCallFrames ( element ) , [ ] ) ;
400+ expandStructuredTrace ( element ) ;
401+ assertNoLinks ( element ) ;
402+ assert . deepEqual ( getStructuredCallFrames ( element ) , EXPANDED_STRUCTURED ) ;
403+ } ) ;
404+
405+ it ( 'shows expandable list when something is ignore listed, collapsing builtin frames' , async ( ) => {
406+ const element = await createConsoleMessageWithIgnoreListing ( url => url . includes ( '/app.js' ) , true ) ;
407+ assertShowAllLink ( element ) ;
408+ assert . deepEqual ( getStructuredCallFrames ( element ) , [ ] ) ;
409+ assert . deepEqual ( getCallFrames ( element ) , COLLAPSED_UNSTRUCTURED_WITH_BUILTIN ) ;
410+ expandIgnored ( element ) ;
411+ assertShowLessLink ( element ) ;
412+ assert . deepEqual ( getCallFrames ( element ) , EXPANDED_UNSTRUCTURED_WITH_BUILTIN ) ;
413+ collapseIgnored ( element ) ;
414+ assertShowAllLink ( element ) ;
415+
416+ expandStructuredTrace ( element ) ;
417+
418+ assertShowAllLink ( element ) ;
419+ assert . deepEqual ( getStructuredCallFrames ( element ) , COLLAPSED_STRUCTURED ) ;
420+ assert . deepEqual ( getCallFrames ( element ) , COLLAPSED_UNSTRUCTURED_WITH_BUILTIN ) ;
421+ expandIgnored ( element ) ;
422+ assertShowLessLink ( element ) ;
423+ assert . deepEqual ( getCallFrames ( element ) , EXPANDED_UNSTRUCTURED_WITH_BUILTIN ) ;
424+ assert . deepEqual ( getStructuredCallFrames ( element ) , EXPANDED_STRUCTURED ) ;
425+ collapseIgnored ( element ) ;
426+ assertShowAllLink ( element ) ;
427+ assert . deepEqual ( getStructuredCallFrames ( element ) , COLLAPSED_STRUCTURED ) ;
428+ assert . deepEqual ( getCallFrames ( element ) , COLLAPSED_UNSTRUCTURED_WITH_BUILTIN ) ;
429+ } ) ;
363430 } ) ;
364431} ) ;
0 commit comments