@@ -9,6 +9,7 @@ const { expect } = chai;
9
9
10
10
const { requestlogger } = require ( '../lib' ) ;
11
11
const app = require ( './helpers/server' ) ;
12
+ const fetchTest = parseInt ( process . version . split ( '.' ) [ 0 ] . split ( 'v' ) [ 1 ] , 10 ) >= 20 ;
12
13
13
14
chai . use ( require ( 'chai-json-schema' ) ) ;
14
15
@@ -46,87 +47,93 @@ describe('Requestlog:', () => {
46
47
it ( 'GET /externalcall {} fetch 200' , async ( ) => {
47
48
const logger = requestlogger ( ) ;
48
49
const logspy = sandbox . spy ( logger , 'log' ) ;
49
- await global . fetch (
50
- `http://localhost:${ server . address ( ) . port } /externalcall` ,
51
- {
52
- headers : {
53
- testheader : "testvalue"
50
+ if ( fetchTest ) {
51
+ await global . fetch (
52
+ `http://localhost:${ server . address ( ) . port } /externalcall` ,
53
+ {
54
+ headers : {
55
+ testheader : "testvalue"
56
+ }
54
57
}
55
- }
56
- ) ;
57
- return new Promise ( ( resolve ) => {
58
- setTimeout ( ( ) => {
59
- sinon . assert . calledWith ( logspy , {
60
- request : {
61
- host : sinon . match ( / l o c a l h o s t : [ 0 - 9 ] + / gm ) ,
62
- path : '/externalcall ' ,
63
- method : 'GET' ,
64
- } ,
65
- response : { status : 200 , duration : sinon . match . number } ,
66
- protocol : 'http:' ,
67
- type : [ 'application' ] ,
68
- } ) ;
69
- resolve ( )
70
- } , 1 ) ;
71
- } ) ;
58
+ ) ;
59
+ return new Promise ( ( resolve ) => {
60
+ setTimeout ( ( ) => {
61
+ sinon . assert . calledWith ( logspy , {
62
+ request : {
63
+ host : sinon . match ( / l o c a l h o s t : [ 0 - 9 ] + / gm ) ,
64
+ path : '/externalcall' ,
65
+ method : 'GET ' ,
66
+ } ,
67
+ response : { status : 200 , duration : sinon . match . number } ,
68
+ protocol : 'http:' ,
69
+ type : [ 'application' ] ,
70
+ } ) ;
71
+ resolve ( )
72
+ } , 1 ) ;
73
+ } ) ;
74
+ }
72
75
} )
73
76
it ( 'GET /externalcall {} fetch 200 json' , async ( ) => {
74
77
const logger = requestlogger ( ) ;
75
78
const logspy = sandbox . spy ( logger , 'log' ) ;
76
- const request = await global . fetch (
77
- `http://localhost:${ server . address ( ) . port } /externalcall` ,
78
- {
79
- headers : {
80
- testheader : "testvalue"
79
+ if ( fetchTest ) {
80
+ const request = await global . fetch (
81
+ `http://localhost:${ server . address ( ) . port } /externalcall` ,
82
+ {
83
+ headers : {
84
+ testheader : "testvalue"
85
+ }
81
86
}
82
- }
83
- ) ;
84
- const body = await request . json ( ) ;
85
- expect ( body ) . to . eql ( { ok : 'ok' } )
86
- return new Promise ( ( resolve ) => {
87
- setTimeout ( ( ) => {
88
- sinon . assert . calledWith ( logspy , {
89
- request : {
90
- host : sinon . match ( / l o c a l h o s t : [ 0 - 9 ] + / gm ) ,
91
- path : '/externalcall ' ,
92
- method : 'GET' ,
93
- } ,
94
- response : { status : 200 , duration : sinon . match . number } ,
95
- protocol : 'http:' ,
96
- type : [ 'application' ] ,
97
- } ) ;
98
- resolve ( )
99
- } , 1 ) ;
100
- } ) ;
87
+ ) ;
88
+ const body = await request . json ( ) ;
89
+ expect ( body ) . to . eql ( { ok : 'ok' } )
90
+ return new Promise ( ( resolve ) => {
91
+ setTimeout ( ( ) => {
92
+ sinon . assert . calledWith ( logspy , {
93
+ request : {
94
+ host : sinon . match ( / l o c a l h o s t : [ 0 - 9 ] + / gm ) ,
95
+ path : '/externalcall' ,
96
+ method : 'GET ' ,
97
+ } ,
98
+ response : { status : 200 , duration : sinon . match . number } ,
99
+ protocol : 'http:' ,
100
+ type : [ 'application' ] ,
101
+ } ) ;
102
+ resolve ( )
103
+ } , 1 ) ;
104
+ } ) ;
105
+ }
101
106
} )
102
107
it ( 'GET /externalcall {} fetch 200 text' , async ( ) => {
103
108
const logger = requestlogger ( ) ;
104
109
const logspy = sandbox . spy ( logger , 'log' ) ;
105
- const request = await global . fetch (
106
- `http://localhost:${ server . address ( ) . port } /externalcall` ,
107
- {
108
- headers : {
109
- testheader : "testvalue"
110
+ if ( fetchTest ) {
111
+ const request = await global . fetch (
112
+ `http://localhost:${ server . address ( ) . port } /externalcall` ,
113
+ {
114
+ headers : {
115
+ testheader : "testvalue"
116
+ }
110
117
}
111
- }
112
- ) ;
113
- const body = await request . text ( ) ;
114
- expect ( body ) . to . eql ( '{"ok":"ok"}' )
115
- return new Promise ( ( resolve ) => {
116
- setTimeout ( ( ) => {
117
- sinon . assert . calledWith ( logspy , {
118
- request : {
119
- host : sinon . match ( / l o c a l h o s t : [ 0 - 9 ] + / gm ) ,
120
- path : '/externalcall ' ,
121
- method : 'GET' ,
122
- } ,
123
- response : { status : 200 , duration : sinon . match . number } ,
124
- protocol : 'http:' ,
125
- type : [ 'application' ] ,
126
- } ) ;
127
- resolve ( )
128
- } , 1 ) ;
129
- } ) ;
118
+ ) ;
119
+ const body = await request . text ( ) ;
120
+ expect ( body ) . to . eql ( '{"ok":"ok"}' )
121
+ return new Promise ( ( resolve ) => {
122
+ setTimeout ( ( ) => {
123
+ sinon . assert . calledWith ( logspy , {
124
+ request : {
125
+ host : sinon . match ( / l o c a l h o s t : [ 0 - 9 ] + / gm ) ,
126
+ path : '/externalcall' ,
127
+ method : 'GET ' ,
128
+ } ,
129
+ response : { status : 200 , duration : sinon . match . number } ,
130
+ protocol : 'http:' ,
131
+ type : [ 'application' ] ,
132
+ } ) ;
133
+ resolve ( )
134
+ } , 1 ) ;
135
+ } ) ;
136
+ }
130
137
} )
131
138
it ( 'no callback return res' , async ( ) => {
132
139
const options = {
@@ -396,9 +403,10 @@ describe('Requestlog:', () => {
396
403
it ( 'GET /externalcall fetch { logResponsePayload: true } 200' , async ( ) => {
397
404
const logger = requestlogger ( { logResponsePayload : true } ) ;
398
405
const logspy = sandbox . spy ( logger , 'log' ) ;
399
- const response = await global . fetch ( `http://localhost:${ server . address ( ) . port } /externalcall` ) ;
400
- await response . json ( ) ;
401
- return sinon . assert . calledWith ( logspy , {
406
+ if ( fetchTest ) {
407
+ const response = await global . fetch ( `http://localhost:${ server . address ( ) . port } /externalcall` ) ;
408
+ await response . json ( ) ;
409
+ return sinon . assert . calledWith ( logspy , {
402
410
type : [ 'application' ] ,
403
411
request : {
404
412
host : sinon . match ( / l o c a l h o s t : [ 0 - 9 ] + / gm) ,
@@ -412,13 +420,15 @@ describe('Requestlog:', () => {
412
420
} ,
413
421
protocol : 'http:' ,
414
422
} ) ;
423
+ }
415
424
} ) ;
416
425
it ( 'GET /externalcall fetch text { logResponsePayload: true } 200' , async ( ) => {
417
426
const logger = requestlogger ( { logResponsePayload : true } ) ;
418
427
const logspy = sandbox . spy ( logger , 'log' ) ;
419
- const response = await global . fetch ( `http://localhost:${ server . address ( ) . port } /externalcall` ) ;
420
- await response . text ( ) ;
421
- return sinon . assert . calledWith ( logspy , {
428
+ if ( fetchTest ) {
429
+ const response = await global . fetch ( `http://localhost:${ server . address ( ) . port } /externalcall` ) ;
430
+ await response . text ( ) ;
431
+ return sinon . assert . calledWith ( logspy , {
422
432
type : [ 'application' ] ,
423
433
request : {
424
434
host : sinon . match ( / l o c a l h o s t : [ 0 - 9 ] + / gm) ,
@@ -432,6 +442,7 @@ describe('Requestlog:', () => {
432
442
} ,
433
443
protocol : 'http:' ,
434
444
} ) ;
445
+ }
435
446
} ) ;
436
447
it ( 'POST /externalcall {} 200' , async ( ) => {
437
448
const logger = requestlogger ( ) ;
0 commit comments