From e9a2a51e6d72e75802a73fe3b2b0e84753cc202a Mon Sep 17 00:00:00 2001 From: Gar Date: Mon, 15 Aug 2022 13:34:42 -0700 Subject: [PATCH] fix: linting (#166) --- lib/cache/entry.js | 1 + test/fetch.js | 42 +++++++++++++----------------------------- 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/lib/cache/entry.js b/lib/cache/entry.js index 4307962..dba89d7 100644 --- a/lib/cache/entry.js +++ b/lib/cache/entry.js @@ -288,6 +288,7 @@ class CacheEntry { // stick a flag on here so downstream users will know if they can expect integrity events tee.pipe(cacheStream) // TODO if the cache write fails, log a warning but return the response anyway + // eslint-disable-next-line promise/catch-or-return cacheStream.promise().then(cacheWriteResolve, cacheWriteReject) body.unshift(tee) body.unshift(this.response.body) diff --git a/test/fetch.js b/test/fetch.js index c0613d5..1f677ff 100644 --- a/test/fetch.js +++ b/test/fetch.js @@ -495,16 +495,14 @@ t.test('supports proxy configurations', { skip: true }, async (t) => { }).listen(9854).on('error', err => { throw err }) - fetch('http://npm.im/make-fetch-happen', { + const res = await fetch('http://npm.im/make-fetch-happen', { proxy: 'http://localhost:9854', retry: { retries: 0, }, - }).then(res => { - return res.buffer() - }).then(buf => { - t.same(buf, CONTENT, 'request succeeded') }) + const buf = await res.buffer() + t.same(buf, CONTENT, 'request succeeded') }) t.test('supports custom agent config', async (t) => { @@ -558,31 +556,17 @@ t.test('handle integrity options', async (t) => { .twice() .reply(200, data) - const firstFetch = fetch(`${HOST}/integrity`, { integrity }) - .then((res) => { - t.equal(res.status, 200, 'successful status code') - t.ok(Minipass.isStream(res.body), 'body is a stream') - return res.buffer() - }) - .then((buf) => { - t.same(buf.toString(), data, 'request succeeded') - }) - - // 100% branch coverage - const secondFetch = fetch(`${HOST}/integrity`, { integrity }) - .then((res) => { - t.equal(res.status, 200, 'successful status code') - t.ok(Minipass.isStream(res.body), 'body is a stream') - return res.buffer() - }) - .then((buf) => { - t.same(buf.toString(), data, 'request succeeded') - }) - - await Promise.resolve() - .then(() => firstFetch) - .then(() => secondFetch) + const firstRes = await fetch(`${HOST}/integrity`, { integrity }) + t.equal(firstRes.status, 200, 'successful status code') + t.ok(Minipass.isStream(firstRes.body), 'body is a stream') + const firstBuf = await firstRes.buffer() + t.same(firstBuf.toString(), data, 'request succeeded') + const secondRes = await fetch(`${HOST}/integrity`, { integrity }) + t.equal(secondRes.status, 200, 'successful status code') + t.ok(Minipass.isStream(secondRes.body), 'body is a stream') + const secondBuf = await secondRes.buffer() + t.same(secondBuf.toString(), data, 'request succeeded') t.ok(srv.isDone()) })