11import { expect , test } from '@playwright/test' ;
2- import { waitForError , waitForTransaction } from '@sentry-internal/test-utils' ;
2+ import { collectStreamedSpansUntilSegment , waitForError } from '@sentry-internal/test-utils' ;
3+
4+ const APP_NAME = 'nestjs-8' ;
35
46test ( 'Sends exception to Sentry' , async ( { baseURL } ) => {
5- const errorEventPromise = waitForError ( 'nestjs-8' , event => {
7+ const errorEventPromise = waitForError ( APP_NAME , event => {
68 return ! event . type && event . exception ?. values ?. [ 0 ] ?. value === 'This is an exception with id 123' ;
79 } ) ;
810
@@ -37,38 +39,35 @@ test('Sends exception to Sentry', async ({ baseURL }) => {
3739test ( 'Does not send HttpExceptions to Sentry' , async ( { baseURL } ) => {
3840 let errorEventOccurred = false ;
3941
40- waitForError ( 'nestjs-8' , event => {
42+ waitForError ( APP_NAME , event => {
4143 if ( ! event . type && event . exception ?. values ?. [ 0 ] ?. value === 'This is an expected 400 exception with id 123' ) {
4244 errorEventOccurred = true ;
4345 }
4446
4547 return event ?. transaction === 'GET /test-expected-400-exception/:id' ;
4648 } ) ;
4749
48- waitForError ( 'nestjs-8' , event => {
50+ waitForError ( APP_NAME , event => {
4951 if ( ! event . type && event . exception ?. values ?. [ 0 ] ?. value === 'This is an expected 500 exception with id 123' ) {
5052 errorEventOccurred = true ;
5153 }
5254
5355 return event ?. transaction === 'GET /test-expected-500-exception/:id' ;
5456 } ) ;
5557
56- const transactionEventPromise400 = waitForTransaction ( 'nestjs-8' , transactionEvent => {
57- return transactionEvent ?. transaction === 'GET /test-expected-400-exception/:id' ;
58- } ) ;
59-
60- const transactionEventPromise500 = waitForTransaction ( 'nestjs-8' , transactionEvent => {
61- return transactionEvent ?. transaction === 'GET /test-expected-500-exception/:id' ;
62- } ) ;
58+ // Waiting for each request's segment span is how this spec knows the request finished and
59+ // any error it would have produced had its chance to be sent.
60+ const spansPromise400 = collectStreamedSpansUntilSegment ( APP_NAME , 'GET /test-expected-400-exception/:id' ) ;
61+ const spansPromise500 = collectStreamedSpansUntilSegment ( APP_NAME , 'GET /test-expected-500-exception/:id' ) ;
6362
6463 const response400 = await fetch ( `${ baseURL } /test-expected-400-exception/123` ) ;
6564 expect ( response400 . status ) . toBe ( 400 ) ;
6665
6766 const response500 = await fetch ( `${ baseURL } /test-expected-500-exception/123` ) ;
6867 expect ( response500 . status ) . toBe ( 500 ) ;
6968
70- await transactionEventPromise400 ;
71- await transactionEventPromise500 ;
69+ await spansPromise400 ;
70+ await spansPromise500 ;
7271
7372 ( await fetch ( `${ baseURL } /flush` ) ) . text ( ) ;
7473
@@ -78,22 +77,20 @@ test('Does not send HttpExceptions to Sentry', async ({ baseURL }) => {
7877test ( 'Does not send RpcExceptions to Sentry' , async ( { baseURL } ) => {
7978 let errorEventOccurred = false ;
8079
81- waitForError ( 'nestjs-8' , event => {
80+ waitForError ( APP_NAME , event => {
8281 if ( ! event . type && event . exception ?. values ?. [ 0 ] ?. value === 'This is an expected RPC exception with id 123' ) {
8382 errorEventOccurred = true ;
8483 }
8584
8685 return event ?. transaction === 'GET /test-expected-rpc-exception/:id' ;
8786 } ) ;
8887
89- const transactionEventPromise = waitForTransaction ( 'nestjs-8' , transactionEvent => {
90- return transactionEvent ?. transaction === 'GET /test-expected-rpc-exception/:id' ;
91- } ) ;
88+ const spansPromise = collectStreamedSpansUntilSegment ( APP_NAME , 'GET /test-expected-rpc-exception/:id' ) ;
9289
9390 const response = await fetch ( `${ baseURL } /test-expected-rpc-exception/123` ) ;
9491 expect ( response . status ) . toBe ( 500 ) ;
9592
96- await transactionEventPromise ;
93+ await spansPromise ;
9794
9895 ( await fetch ( `${ baseURL } /flush` ) ) . text ( ) ;
9996
@@ -105,17 +102,15 @@ test('Global exception filter registered in main module is applied and exception
105102} ) => {
106103 let errorEventOccurred = false ;
107104
108- waitForError ( 'nestjs-8' , event => {
105+ waitForError ( APP_NAME , event => {
109106 if ( ! event . type && event . exception ?. values ?. [ 0 ] ?. value === 'Example exception was handled by global filter!' ) {
110107 errorEventOccurred = true ;
111108 }
112109
113110 return event ?. transaction === 'GET /example-exception-global-filter' ;
114111 } ) ;
115112
116- const transactionEventPromise = waitForTransaction ( 'nestjs-8' , transactionEvent => {
117- return transactionEvent ?. transaction === 'GET /example-exception-global-filter' ;
118- } ) ;
113+ const spansPromise = collectStreamedSpansUntilSegment ( APP_NAME , 'GET /example-exception-global-filter' ) ;
119114
120115 const response = await fetch ( `${ baseURL } /example-exception-global-filter` ) ;
121116 const responseBody = await response . json ( ) ;
@@ -128,7 +123,7 @@ test('Global exception filter registered in main module is applied and exception
128123 message : 'Example exception was handled by global filter!' ,
129124 } ) ;
130125
131- await transactionEventPromise ;
126+ await spansPromise ;
132127
133128 ( await fetch ( `${ baseURL } /flush` ) ) . text ( ) ;
134129
@@ -140,17 +135,15 @@ test('Local exception filter registered in main module is applied and exception
140135} ) => {
141136 let errorEventOccurred = false ;
142137
143- waitForError ( 'nestjs-8' , event => {
138+ waitForError ( APP_NAME , event => {
144139 if ( ! event . type && event . exception ?. values ?. [ 0 ] ?. value === 'Example exception was handled by local filter!' ) {
145140 errorEventOccurred = true ;
146141 }
147142
148143 return event ?. transaction === 'GET /example-exception-local-filter' ;
149144 } ) ;
150145
151- const transactionEventPromise = waitForTransaction ( 'nestjs-8' , transactionEvent => {
152- return transactionEvent ?. transaction === 'GET /example-exception-local-filter' ;
153- } ) ;
146+ const spansPromise = collectStreamedSpansUntilSegment ( APP_NAME , 'GET /example-exception-local-filter' ) ;
154147
155148 const response = await fetch ( `${ baseURL } /example-exception-local-filter` ) ;
156149 const responseBody = await response . json ( ) ;
@@ -163,7 +156,7 @@ test('Local exception filter registered in main module is applied and exception
163156 message : 'Example exception was handled by local filter!' ,
164157 } ) ;
165158
166- await transactionEventPromise ;
159+ await spansPromise ;
167160
168161 ( await fetch ( `${ baseURL } /flush` ) ) . text ( ) ;
169162
0 commit comments