@@ -3,7 +3,6 @@ const t = require('tap')
3
3
4
4
const checkResponse = require ( '../lib/check-response.js' )
5
5
const errors = require ( '../lib/errors.js' )
6
- const silentLog = require ( '../lib/silentlog.js' )
7
6
const registry = 'registry'
8
7
const startTime = Date . now ( )
9
8
@@ -56,27 +55,27 @@ t.test('all checks are ok, nothing to report', t => {
56
55
t . end ( )
57
56
} )
58
57
59
- t . test ( 'log x-fetch-attempts header value' , t => {
58
+ t . test ( 'log x-fetch-attempts header value' , async t => {
60
59
const headers = new Headers ( )
61
60
headers . get = header => header === 'x-fetch-attempts' ? 3 : undefined
62
61
const res = Object . assign ( { } , mockFetchRes , {
63
62
headers,
64
63
status : 400 ,
65
64
} )
66
65
t . plan ( 2 )
67
- t . rejects ( checkResponse ( {
66
+ let msg
67
+ process . on ( 'log' , ( level , ...args ) => {
68
+ if ( level === 'http' ) {
69
+ ; [ , msg ] = args
70
+ }
71
+ } )
72
+ await t . rejects ( checkResponse ( {
68
73
method : 'get' ,
69
74
res,
70
75
registry,
71
76
startTime,
72
- opts : {
73
- log : Object . assign ( { } , silentLog , {
74
- http ( header , msg ) {
75
- t . ok ( msg . endsWith ( 'attempt #3' ) , 'should log correct number of attempts' )
76
- } ,
77
- } ) ,
78
- } ,
79
77
} ) )
78
+ t . ok ( msg . endsWith ( 'attempt #3' ) , 'should log correct number of attempts' )
80
79
} )
81
80
82
81
t . test ( 'log the url fetched' , t => {
@@ -90,21 +89,22 @@ t.test('log the url fetched', t => {
90
89
body : new EE ( ) ,
91
90
} )
92
91
t . plan ( 2 )
92
+ let header , msg
93
+ process . on ( 'log' , ( level , ...args ) => {
94
+ if ( level === 'http' ) {
95
+ ; [ header , msg ] = args
96
+ }
97
+ } )
93
98
checkResponse ( {
94
99
method : 'get' ,
95
100
res,
96
101
registry,
97
102
startTime,
98
- opts : {
99
- log : Object . assign ( { } , silentLog , {
100
- http ( header , msg ) {
101
- t . equal ( header , 'fetch' )
102
- t . match ( msg , / ^ G E T 2 0 0 h t t p : \/ \/ e x a m p l e .c o m \/ f o o \/ b a r \/ b a z [ 0 - 9 ] + m ? s / )
103
- } ,
104
- } ) ,
105
- } ,
103
+
106
104
} )
107
105
res . body . emit ( 'end' )
106
+ t . equal ( header , 'fetch' )
107
+ t . match ( msg , / ^ G E T 2 0 0 h t t p : \/ \/ e x a m p l e .c o m \/ f o o \/ b a r \/ b a z [ 0 - 9 ] + m ? s / )
108
108
} )
109
109
110
110
t . test ( 'redact password from log' , t => {
@@ -118,34 +118,40 @@ t.test('redact password from log', t => {
118
118
body : new EE ( ) ,
119
119
} )
120
120
t . plan ( 2 )
121
+ let header , msg
122
+ process . on ( 'log' , ( level , ...args ) => {
123
+ if ( level === 'http' ) {
124
+ ; [ header , msg ] = args
125
+ }
126
+ } )
121
127
checkResponse ( {
122
128
method : 'get' ,
123
129
res,
124
130
registry,
125
131
startTime,
126
- opts : {
127
- log : Object . assign ( { } , silentLog , {
128
- http ( header , msg ) {
129
- t . equal ( header , 'fetch' )
130
- t . match ( msg , / ^ G E T 2 0 0 h t t p : \/ \/ u s e r n a m e : \* \* \* @ e x a m p l e .c o m \/ f o o \/ b a r \/ b a z [ 0 - 9 ] + m ? s / )
131
- } ,
132
- } ) ,
133
- } ,
134
132
} )
135
133
res . body . emit ( 'end' )
134
+ t . equal ( header , 'fetch' )
135
+ t . match ( msg , / ^ G E T 2 0 0 h t t p : \/ \/ u s e r n a m e : \* \* \* @ e x a m p l e .c o m \/ f o o \/ b a r \/ b a z [ 0 - 9 ] + m ? s / )
136
136
} )
137
137
138
138
/* eslint-disable-next-line max-len */
139
139
const moreInfoUrl = 'https://github.com/npm/cli/wiki/No-auth-for-URI,-but-auth-present-for-scoped-registry'
140
140
141
- t . test ( 'report auth for registry, but not for this request' , t => {
141
+ t . test ( 'report auth for registry, but not for this request' , async t => {
142
142
const res = Object . assign ( { } , mockFetchRes , {
143
143
buffer : ( ) => Promise . resolve ( Buffer . from ( 'ok' ) ) ,
144
144
status : 400 ,
145
145
url : 'https://example.com/' ,
146
146
} )
147
147
t . plan ( 3 )
148
- t . rejects ( checkResponse ( {
148
+ let header , msg
149
+ process . on ( 'log' , ( level , ...args ) => {
150
+ if ( level === 'warn' ) {
151
+ ; [ header , msg ] = args
152
+ }
153
+ } )
154
+ await t . rejects ( checkResponse ( {
149
155
method : 'get' ,
150
156
res,
151
157
uri : 'https://example.com/' ,
@@ -156,20 +162,14 @@ t.test('report auth for registry, but not for this request', t => {
156
162
auth : null ,
157
163
token : null ,
158
164
} ,
159
- opts : {
160
- log : Object . assign ( { } , silentLog , {
161
- warn ( header , msg ) {
162
- t . equal ( header , 'registry' )
163
- t . equal ( msg , `No auth for URI, but auth present for scoped registry.
165
+ } ) , errors . HttpErrorGeneral )
166
+ t . equal ( header , 'registry' )
167
+ t . equal ( msg , `No auth for URI, but auth present for scoped registry.
164
168
165
169
URI: https://example.com/
166
170
Scoped Registry Key: //some-scope-registry.com/
167
171
168
172
More info here: ${ moreInfoUrl } ` )
169
- } ,
170
- } ) ,
171
- } ,
172
- } ) , errors . HttpErrorGeneral )
173
173
} )
174
174
175
175
t . test ( 'logs the value of x-local-cache-status when set' , t => {
@@ -183,22 +183,22 @@ t.test('logs the value of x-local-cache-status when set', t => {
183
183
body : new EE ( ) ,
184
184
} )
185
185
t . plan ( 2 )
186
+ let header , msg
187
+ process . on ( 'log' , ( level , ...args ) => {
188
+ if ( level === 'http' ) {
189
+ ; [ header , msg ] = args
190
+ }
191
+ } )
186
192
checkResponse ( {
187
193
method : 'get' ,
188
194
res,
189
195
registry,
190
196
startTime,
191
- opts : {
192
- log : Object . assign ( { } , silentLog , {
193
- http ( header , msg ) {
194
- t . equal ( header , 'fetch' )
195
- t . match (
196
- msg ,
197
- / ^ G E T 2 0 0 h t t p : \/ \/ u s e r n a m e : \* \* \* @ e x a m p l e .c o m \/ f o o \/ b a r \/ b a z [ 0 - 9 ] + m ? s \( c a c h e h i t \) $ /
198
- )
199
- } ,
200
- } ) ,
201
- } ,
202
197
} )
203
198
res . body . emit ( 'end' )
199
+ t . equal ( header , 'fetch' )
200
+ t . match (
201
+ msg ,
202
+ / ^ G E T 2 0 0 h t t p : \/ \/ u s e r n a m e : \* \* \* @ e x a m p l e .c o m \/ f o o \/ b a r \/ b a z [ 0 - 9 ] + m ? s \( c a c h e h i t \) $ /
203
+ )
204
204
} )
0 commit comments