@@ -20,9 +20,8 @@ describe('plugin-network-instrumentation', () => {
2020 status : number | null
2121 statusText : string
2222 responseURL : string
23- response : string
24- responseText : string
25- responseType : string
23+ response : typeof XMLHttpRequest . prototype . response
24+ responseType : typeof XMLHttpRequest . prototype . responseType
2625 _method : string
2726 _url : string
2827 _requestHeaders : Headers
@@ -34,7 +33,6 @@ describe('plugin-network-instrumentation', () => {
3433 this . statusText = ''
3534 this . responseURL = ''
3635 this . response = ''
37- this . responseText = ''
3836 this . responseType = ''
3937 this . _method = 'GET'
4038 this . _url = ''
@@ -102,7 +100,9 @@ describe('plugin-network-instrumentation', () => {
102100 const notifyCallbacks : Event [ ] = [ ]
103101
104102 plugin = createPlugin ( {
105- httpErrorCodes : { min : 400 , max : 499 }
103+ httpErrorCodes : { min : 400 , max : 499 } ,
104+ maxRequestSize : 1000 ,
105+ maxResponseSize : 1000
106106 } )
107107
108108 const client = new Client ( { apiKey : 'api_key' , plugins : [ plugin ] } )
@@ -114,7 +114,7 @@ describe('plugin-network-instrumentation', () => {
114114 xhr . statusText = 'Not Found'
115115 xhr . responseURL = 'https://api.example.com/users/123'
116116 xhr . response = '{"error": "User not found", "code": "USER_NOT_FOUND"}'
117- xhr . responseText = '{"error": "User not found", "code": "USER_NOT_FOUND"} '
117+ xhr . responseType = 'json '
118118
119119 // Simulate an XHR request
120120 xhr . open ( 'POST' , 'https://api.example.com/users/123' )
@@ -143,22 +143,22 @@ describe('plugin-network-instrumentation', () => {
143143 expect ( event . request . httpMethod ) . toBe ( 'POST' )
144144 expect ( event . request . body ) . toBe ( requestBody )
145145 expect ( event . request . bodyLength ) . toBe ( requestBody . length )
146- // expect(event.request.headers?.['content-type']).toBe( 'application/json')
146+ expect ( event . request . headers ) . toStrictEqual ( { 'Content-Type' : 'application/json' } )
147147
148148 // Verify response metadata including body
149149 expect ( event . response . statusCode ) . toBe ( 404 )
150150 expect ( event . response . headers [ 'content-type' ] ) . toBe ( 'application/json' )
151151 expect ( event . response . headers [ 'content-length' ] ) . toBe ( '45' )
152- expect ( event . response . body ) . toBe ( '{"error": "User not found", "code": "USER_NOT_FOUND"}' )
153- expect ( event . response . bodyLength ) . toBe ( xhr . responseText . length )
152+ expect ( event . response . body ) . toBe ( JSON . stringify ( xhr . response ) )
153+ expect ( event . response . bodyLength ) . toBe ( JSON . stringify ( xhr . response ) . length )
154154 } )
155155
156- it ( 'should truncate XHR response body when it exceeds maxRequestSize ' , async ( ) => {
156+ it ( 'should truncate XHR response body when it exceeds maxResponseSize ' , async ( ) => {
157157 const notifyCallbacks : Event [ ] = [ ]
158158
159159 plugin = createPlugin ( {
160160 httpErrorCodes : { min : 400 , max : 499 } ,
161- maxRequestSize : 20
161+ maxResponseSize : 20
162162 } )
163163
164164 const client = new Client ( { apiKey : 'api_key' , plugins : [ plugin ] } )
@@ -171,7 +171,6 @@ describe('plugin-network-instrumentation', () => {
171171 xhr . statusText = 'Internal Server Error'
172172 xhr . responseURL = 'https://api.example.com/error'
173173 xhr . response = largeResponseBody
174- xhr . responseText = largeResponseBody
175174
176175 xhr . open ( 'GET' , 'https://api.example.com/error' )
177176 xhr . send ( )
@@ -225,7 +224,6 @@ describe('plugin-network-instrumentation', () => {
225224 xhr . status = 403
226225 xhr . statusText = 'Forbidden'
227226 xhr . response = 'Forbidden'
228- xhr . responseText = 'Forbidden'
229227
230228 xhr . open ( 'GET' , 'https://api.example.com/data?userId=42' )
231229 xhr . send ( )
0 commit comments