@@ -1392,46 +1392,75 @@ describe('globals', function() {
1392
1392
} ) ;
1393
1393
} ) ;
1394
1394
1395
- it ( 'should apply globalOptions.headers if specified' , function ( ) {
1396
- this . sinon . stub ( Raven , 'isSetup' ) . returns ( true ) ;
1397
- this . sinon . stub ( window , 'fetch' ) . resolves ( true ) ;
1395
+ if ( supportsFetch ( ) ) {
1396
+ it ( 'should apply globalOptions.headers with string value to fetch call if specified' , function ( ) {
1397
+ this . sinon . stub ( window , 'fetch' ) . resolves ( true ) ;
1398
1398
1399
- Raven . _globalProject = '2' ;
1400
- Raven . _globalOptions = {
1401
- logger : 'javascript' ,
1402
- maxMessageLength : 100 ,
1403
- headers : {
1399
+ Raven . _globalProject = '2' ;
1400
+ Raven . _globalOptions = {
1401
+ logger : 'javascript' ,
1402
+ maxMessageLength : 100 ,
1403
+ headers : {
1404
+ 'custom-header' : 'value'
1405
+ }
1406
+ } ;
1407
+
1408
+ Raven . _send ( { message : 'bar' } ) ;
1409
+
1410
+ assert . deepEqual ( window . fetch . lastCall . args [ 1 ] . headers , {
1404
1411
'custom-header' : 'value'
1405
- }
1406
- } ;
1412
+ } ) ;
1413
+ } ) ;
1407
1414
1408
- Raven . _send ( { message : 'bar' } ) ;
1415
+ it ( 'should apply globalOptions.headers with function value to fetch call if specified' , function ( ) {
1416
+ this . sinon . stub ( window , 'fetch' ) . resolves ( true ) ;
1417
+
1418
+ Raven . _globalProject = '2' ;
1419
+ Raven . _globalOptions = {
1420
+ logger : 'javascript' ,
1421
+ maxMessageLength : 100 ,
1422
+ headers : {
1423
+ 'custom-header' : function ( ) {
1424
+ return 'computed-header-value' ;
1425
+ }
1426
+ }
1427
+ } ;
1428
+
1429
+ Raven . _send ( { message : 'bar' } ) ;
1409
1430
1410
- assert . deepEqual ( window . fetch . lastCall . args [ 1 ] . headers , {
1411
- 'custom-header' : 'value'
1431
+ assert . deepEqual ( window . fetch . lastCall . args [ 1 ] . headers , {
1432
+ 'custom-header' : 'computed-header-value'
1433
+ } ) ;
1412
1434
} ) ;
1413
- } ) ;
1435
+ }
1414
1436
1415
- it ( 'should apply globalOptions.headers with function value if specified' , function ( ) {
1416
- this . sinon . stub ( Raven , 'isSetup' ) . returns ( true ) ;
1417
- this . sinon . stub ( window , 'fetch' ) . resolves ( true ) ;
1437
+ it ( 'should apply globalOptions.headers with string or function value to XHR call if specified' , function ( ) {
1438
+ var origFetch = window . fetch ;
1439
+ delete window . fetch ;
1440
+
1441
+ var requests = [ ] ;
1442
+ var xhr = sinon . useFakeXMLHttpRequest ( ) ;
1443
+
1444
+ xhr . onCreate = function ( xhr ) {
1445
+ requests . push ( xhr ) ;
1446
+ } ;
1418
1447
1419
- Raven . _globalProject = '2' ;
1420
1448
Raven . _globalOptions = {
1421
- logger : 'javascript' ,
1422
- maxMessageLength : 100 ,
1423
1449
headers : {
1424
- 'custom-header' : function ( ) {
1425
- return 'computed-header-value' ;
1450
+ 'custom-string-header' : 'pickle-rick' ,
1451
+ 'custom-function-header' : function ( ) {
1452
+ return 'morty' ;
1426
1453
}
1427
1454
}
1428
1455
} ;
1429
1456
1430
1457
Raven . _send ( { message : 'bar' } ) ;
1431
1458
1432
- assert . deepEqual ( window . fetch . lastCall . args [ 1 ] . headers , {
1433
- 'custom-header' : 'computed-header-value'
1434
- } ) ;
1459
+ var lastXhr = requests [ requests . length - 1 ] ;
1460
+ assert . equal ( lastXhr . HEADERS_RECEIVED , 2 ) ;
1461
+
1462
+ window . fetch = origFetch ;
1463
+ xhr . restore ( ) ;
1435
1464
} ) ;
1436
1465
1437
1466
it ( 'should check `Raven.isSetup`' , function ( ) {
0 commit comments