Skip to content

Commit c9a8727

Browse files
committed
fix: linting
1 parent a72fb7c commit c9a8727

File tree

5 files changed

+55
-67
lines changed

5 files changed

+55
-67
lines changed

lib/check-response.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ function checkErrors (method, res, startTime, opts) {
6161
let parsed = body
6262
try {
6363
parsed = JSON.parse(body.toString('utf8'))
64-
} catch (e) {}
64+
} catch {
65+
// ignore errors
66+
}
6567
if (res.status === 401 && res.headers.get('www-authenticate')) {
6668
const auth = res.headers.get('www-authenticate')
6769
.split(/,\s*/)

lib/clean-url.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ const cleanUrl = (str) => {
1414
if (url.password) {
1515
str = str.replace(url.password, replace)
1616
}
17-
} catch {}
17+
} catch {
18+
// ignore errors
19+
}
1820

1921
return str
2022
.replace(tokenRegex, `npm_${replace}`)

test/check-response.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ t.test('log x-fetch-attempts header value', async t => {
6666
let msg
6767
process.on('log', (level, ...args) => {
6868
if (level === 'http') {
69-
;[, msg] = args
69+
[, msg] = args
7070
}
7171
})
7272
await t.rejects(checkResponse({
@@ -92,7 +92,7 @@ t.test('log the url fetched', t => {
9292
let header, msg
9393
process.on('log', (level, ...args) => {
9494
if (level === 'http') {
95-
;[header, msg] = args
95+
[header, msg] = args
9696
}
9797
})
9898
checkResponse({
@@ -121,7 +121,7 @@ t.test('redact password from log', t => {
121121
let header, msg
122122
process.on('log', (level, ...args) => {
123123
if (level === 'http') {
124-
;[header, msg] = args
124+
[header, msg] = args
125125
}
126126
})
127127
checkResponse({
@@ -149,7 +149,7 @@ t.test('redact well known token from log', t => {
149149
let header, msg
150150
process.on('log', (level, ...args) => {
151151
if (level === 'http') {
152-
;[header, msg] = args
152+
[header, msg] = args
153153
}
154154
})
155155
checkResponse({
@@ -176,7 +176,7 @@ t.test('report auth for registry, but not for this request', async t => {
176176
let header, msg
177177
process.on('log', (level, ...args) => {
178178
if (level === 'warn') {
179-
;[header, msg] = args
179+
[header, msg] = args
180180
}
181181
})
182182
await t.rejects(checkResponse({
@@ -214,7 +214,7 @@ t.test('logs the value of x-local-cache-status when set', t => {
214214
let header, msg
215215
process.on('log', (level, ...args) => {
216216
if (level === 'http') {
217-
;[header, msg] = args
217+
[header, msg] = args
218218
}
219219
})
220220
checkResponse({

test/errors.js

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ t.test('OTP error', t => {
130130
)
131131
})
132132

133-
t.test('OTP error with prompt', t => {
133+
t.test('OTP error with prompt', async t => {
134134
let OTP = null
135135
tnock(t, OPTS.registry)
136136
.get('/otplease').times(2)
@@ -150,16 +150,13 @@ t.test('OTP error with prompt', t => {
150150
})
151151

152152
const otpPrompt = async () => '12345'
153-
return fetch('/otplease', { ...OPTS, otpPrompt })
154-
.then(res => {
155-
t.strictSame(res.status, 200, 'got 200 response')
156-
return res.json()
157-
}).then(body => {
158-
t.strictSame(body, { ok: 'this is fine' }, 'got expected body')
159-
})
153+
const res = await fetch('/otplease', { ...OPTS, otpPrompt })
154+
t.strictSame(res.status, 200, 'got 200 response')
155+
const body = await res.json()
156+
t.strictSame(body, { ok: 'this is fine' }, 'got expected body')
160157
})
161158

162-
t.test('OTP error with prompt, expired OTP in settings', t => {
159+
t.test('OTP error with prompt, expired OTP in settings', async t => {
163160
let OTP = null
164161
tnock(t, OPTS.registry)
165162
.get('/otplease').times(2)
@@ -183,13 +180,10 @@ t.test('OTP error with prompt, expired OTP in settings', t => {
183180
})
184181

185182
const otpPrompt = async () => '12345'
186-
return fetch('/otplease', { ...OPTS, otpPrompt, otp: '98765' })
187-
.then(res => {
188-
t.strictSame(res.status, 200, 'got 200 response')
189-
return res.json()
190-
}).then(body => {
191-
t.strictSame(body, { ok: 'this is fine' }, 'got expected body')
192-
})
183+
const res = await fetch('/otplease', { ...OPTS, otpPrompt, otp: '98765' })
184+
t.strictSame(res.status, 200, 'got 200 response')
185+
const body = await res.json()
186+
t.strictSame(body, { ok: 'this is fine' }, 'got expected body')
193187
})
194188

195189
t.test('OTP error with prompt that fails', t => {

test/index.js

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ t.test('stream body param', t => {
124124
.then(json => t.same(json, { hello: 'world' }))
125125
})
126126

127-
t.test('JSON body param', t => {
127+
t.test('JSON body param', async t => {
128128
tnock(t, defaultOpts.registry)
129129
.matchHeader('content-type', ctype => {
130130
t.equal(ctype[0], 'application/json', 'content-type automatically set')
@@ -143,10 +143,8 @@ t.test('JSON body param', t => {
143143
body: { hello: 'world' },
144144
gzip: true,
145145
}
146-
return fetch('/hello', opts)
147-
.then(res => {
148-
t.equal(res.status, 200, 'request succeeded')
149-
})
146+
const res = await fetch('/hello', opts)
147+
t.equal(res.status, 200, 'request succeeded')
150148
})
151149

152150
t.test('gzip + buffer body param', t => {
@@ -275,43 +273,41 @@ t.test('query string with ?write=true', t => {
275273
.then(res => t.strictSame(res, { write: 'go for it' }))
276274
})
277275

278-
t.test('fetch.json.stream()', t => {
276+
t.test('fetch.json.stream()', async t => {
279277
tnock(t, defaultOpts.registry).get('/hello').reply(200, {
280278
a: 1,
281279
b: 2,
282280
c: 3,
283281
})
284-
return fetch.json.stream('/hello', '$*', OPTS).collect().then(data => {
285-
t.same(data, [
286-
{ key: 'a', value: 1 },
287-
{ key: 'b', value: 2 },
288-
{ key: 'c', value: 3 },
289-
], 'got a streamed JSON body')
290-
})
282+
const data = await fetch.json.stream('/hello', '$*', OPTS).collect()
283+
t.same(data, [
284+
{ key: 'a', value: 1 },
285+
{ key: 'b', value: 2 },
286+
{ key: 'c', value: 3 },
287+
], 'got a streamed JSON body')
291288
})
292289

293-
t.test('fetch.json.stream opts.mapJSON', t => {
290+
t.test('fetch.json.stream opts.mapJSON', async t => {
294291
tnock(t, defaultOpts.registry).get('/hello').reply(200, {
295292
a: 1,
296293
b: 2,
297294
c: 3,
298295
})
299-
return fetch.json.stream('/hello', '*', {
296+
const data = await fetch.json.stream('/hello', '*', {
300297
...OPTS,
301298
mapJSON (value, [key]) {
302299
return [key, value]
303300
},
304-
}).collect().then(data => {
305-
t.same(data, [
306-
['a', 1],
307-
['b', 2],
308-
['c', 3],
309-
], 'data mapped')
310-
})
301+
}).collect()
302+
t.same(data, [
303+
['a', 1],
304+
['b', 2],
305+
['c', 3],
306+
], 'data mapped')
311307
})
312308

313-
t.test('fetch.json.stream gets fetch error on stream', t => {
314-
return t.rejects(fetch.json.stream('/hello', '*', {
309+
t.test('fetch.json.stream gets fetch error on stream', async t => {
310+
await t.rejects(fetch.json.stream('/hello', '*', {
315311
...OPTS,
316312
body: Promise.reject(new Error('no body for you')),
317313
method: 'POST',
@@ -321,28 +317,24 @@ t.test('fetch.json.stream gets fetch error on stream', t => {
321317
})
322318
})
323319

324-
t.test('opts.ignoreBody', t => {
320+
t.test('opts.ignoreBody', async t => {
325321
tnock(t, defaultOpts.registry)
326322
.get('/hello')
327323
.reply(200, { hello: 'world' })
328-
return fetch('/hello', { ...OPTS, ignoreBody: true })
329-
.then(res => {
330-
t.equal(res.body, null, 'body omitted')
331-
})
324+
const res = await fetch('/hello', { ...OPTS, ignoreBody: true })
325+
t.equal(res.body, null, 'body omitted')
332326
})
333327

334-
t.test('method configurable', t => {
328+
t.test('method configurable', async t => {
335329
tnock(t, defaultOpts.registry)
336330
.delete('/hello')
337331
.reply(200)
338332
const opts = {
339333
...OPTS,
340334
method: 'DELETE',
341335
}
342-
return fetch('/hello', opts)
343-
.then(res => {
344-
t.equal(res.status, 200, 'successfully used DELETE method')
345-
})
336+
const res = await fetch('/hello', opts)
337+
t.equal(res.status, 200, 'successfully used DELETE method')
346338
})
347339

348340
t.test('npm-notice header logging', async t => {
@@ -355,7 +347,7 @@ t.test('npm-notice header logging', async t => {
355347
let header, msg
356348
process.on('log', (level, ...args) => {
357349
if (level === 'notice') {
358-
;[header, msg] = args
350+
[header, msg] = args
359351
}
360352
})
361353

@@ -463,7 +455,7 @@ t.test('pickRegistry through opts.spec', t => {
463455
))
464456
})
465457

466-
t.test('miscellaneous headers', t => {
458+
t.test('miscellaneous headers', async t => {
467459
tnock(t, defaultOpts.registry)
468460
.matchHeader('npm-session', session =>
469461
t.strictSame(session, ['foobarbaz'], 'session set from options'))
@@ -478,30 +470,28 @@ t.test('miscellaneous headers', t => {
478470
.get('/hello')
479471
.reply(200, { hello: 'world' })
480472

481-
return fetch('/hello', {
473+
const res = await fetch('/hello', {
482474
...OPTS,
483475
registry: null, // always falls back on falsey registry value
484476
npmSession: 'foobarbaz',
485477
scope: '@foo',
486478
userAgent: 'agent of use',
487479
npmCommand: 'hello-world',
488480
authType: 'auth',
489-
}).then(res => {
490-
t.equal(res.status, 200, 'got successful response')
491481
})
482+
t.equal(res.status, 200, 'got successful response')
492483
})
493484

494-
t.test('miscellaneous headers not being set if not present in options', t => {
485+
t.test('miscellaneous headers not being set if not present in options', async t => {
495486
tnock(t, defaultOpts.registry)
496487
.matchHeader('npm-auth-type', authType =>
497488
t.strictSame(authType, undefined, 'auth-type not set from options'))
498489
.get('/hello')
499490
.reply(200, { hello: 'world' })
500491

501-
return fetch('/hello', {
492+
const res = await fetch('/hello', {
502493
...OPTS,
503494
authType: undefined,
504-
}).then(res => {
505-
t.equal(res.status, 200, 'got successful response')
506495
})
496+
t.equal(res.status, 200, 'got successful response')
507497
})

0 commit comments

Comments
 (0)