@@ -15,6 +15,7 @@ import type {
1515} from '@sentry/types' ;
1616import axios from 'axios' ;
1717import { createBasicSentryServer } from './server' ;
18+ import { normalize } from '@sentry/utils' ;
1819
1920export function assertSentryEvent ( actual : Event , expected : Event ) : void {
2021 expect ( actual ) . toMatchObject ( {
@@ -130,8 +131,7 @@ async function runDockerCompose(options: DockerOptions): Promise<VoidFunction> {
130131 function newData ( data : Buffer ) : void {
131132 const text = data . toString ( 'utf8' ) ;
132133
133- // eslint-disable-next-line no-console
134- if ( process . env . DEBUG ) console . log ( text ) ;
134+ if ( process . env . DEBUG ) log ( text ) ;
135135
136136 for ( const match of options . readyMatches ) {
137137 if ( text . includes ( match ) ) {
@@ -254,7 +254,7 @@ export function createRunner(...paths: string[]) {
254254
255255 function complete ( error ?: Error ) : void {
256256 child ?. kill ( ) ;
257- done ?.( error ) ;
257+ done ?.( normalize ( error ) ) ;
258258 }
259259
260260 /** Called after each expect callback to check if we're complete */
@@ -397,8 +397,7 @@ export function createRunner(...paths: string[]) {
397397 ? { ...process . env , ...withEnv , SENTRY_DSN : `http://public@localhost:${ mockServerPort } /1337` }
398398 : { ...process . env , ...withEnv } ;
399399
400- // eslint-disable-next-line no-console
401- if ( process . env . DEBUG ) console . log ( 'starting scenario' , testPath , flags , env . SENTRY_DSN ) ;
400+ if ( process . env . DEBUG ) log ( 'starting scenario' , testPath , flags , env . SENTRY_DSN ) ;
402401
403402 child = spawn ( 'node' , [ ...flags , testPath ] , { env } ) ;
404403
@@ -425,8 +424,7 @@ export function createRunner(...paths: string[]) {
425424
426425 // Pass error to done to end the test quickly
427426 child . on ( 'error' , e => {
428- // eslint-disable-next-line no-console
429- if ( process . env . DEBUG ) console . log ( 'scenario error' , e ) ;
427+ if ( process . env . DEBUG ) log ( 'scenario error' , e ) ;
430428 complete ( e ) ;
431429 } ) ;
432430
@@ -465,8 +463,7 @@ export function createRunner(...paths: string[]) {
465463 logs . push ( line . trim ( ) ) ;
466464
467465 buffer = Buffer . from ( buffer . subarray ( splitIndex + 1 ) ) ;
468- // eslint-disable-next-line no-console
469- if ( process . env . DEBUG ) console . log ( 'line' , line ) ;
466+ if ( process . env . DEBUG ) log ( 'line' , line ) ;
470467 tryParseEnvelopeFromStdoutLine ( line ) ;
471468 }
472469 } ) ;
@@ -484,34 +481,40 @@ export function createRunner(...paths: string[]) {
484481 method : 'get' | 'post' ,
485482 path : string ,
486483 headers : Record < string , string > = { } ,
487- data ?: any , // axios accept any as data
484+ data ?: unknown ,
488485 ) : Promise < T | undefined > {
489486 try {
490487 await waitFor ( ( ) => scenarioServerPort !== undefined ) ;
491488 } catch ( e ) {
492489 complete ( e as Error ) ;
493- return undefined ;
490+ return ;
494491 }
495492
496493 const url = `http://localhost:${ scenarioServerPort } ${ path } ` ;
497- if ( expectError ) {
498- try {
499- if ( method === 'get' ) {
500- await axios . get ( url , { headers } ) ;
501- } else {
502- await axios . post ( url , data , { headers } ) ;
503- }
504- } catch ( e ) {
494+
495+ try {
496+ if ( method === 'post' ) {
497+ const res = await axios . post ( url , data , { headers } ) ;
498+ return res . data ;
499+ } else {
500+ const res = await axios . get ( url , { headers } ) ;
501+ return res . data ;
502+ }
503+ } catch ( e ) {
504+ if ( expectError ) {
505505 return ;
506506 }
507+
508+ complete ( e as Error ) ;
507509 return ;
508- } else if ( method === 'get' ) {
509- return ( await axios . get ( url , { headers } ) ) . data ;
510- } else {
511- return ( await axios . post ( url , data , { headers } ) ) . data ;
512510 }
513511 } ,
514512 } ;
515513 } ,
516514 } ;
517515}
516+
517+ function log ( ...args : unknown [ ] ) : void {
518+ // eslint-disable-next-line no-console
519+ console . log ( ...args . map ( arg => normalize ( arg ) ) ) ;
520+ }
0 commit comments