Skip to content

Commit dec763a

Browse files
authored
better cache status (#54)
* feat: reflect the cache status in the log messages * chore: update npm in ci * fixup! feat: reflect the cache status in the log messages
1 parent a5aad1f commit dec763a

File tree

5 files changed

+64
-17
lines changed

5 files changed

+64
-17
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ jobs:
3737
with:
3838
node-version: ${{ matrix.node-version }}
3939

40+
- name: update npm
41+
run: npm i -g npm@latest
42+
4043
################################################################################
4144
# Install Dependencies
4245
#

check-response.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ function logRequest (method, res, startTime, opts) {
3838
const elapsedTime = Date.now() - startTime
3939
const attempt = res.headers.get('x-fetch-attempts')
4040
const attemptStr = attempt && attempt > 1 ? ` attempt #${attempt}` : ''
41-
const cacheStr = res.headers.get('x-local-cache') ? ' (from cache)' : ''
41+
const cacheStatus = res.headers.get('x-local-cache-status')
42+
const cacheStr = cacheStatus ? ` (cache ${cacheStatus})` : ''
4243

4344
let urlStr
4445
try {

package-lock.json

Lines changed: 30 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
"license": "ISC",
3131
"dependencies": {
32-
"make-fetch-happen": "^8.0.9",
32+
"make-fetch-happen": "^9.0.1",
3333
"minipass": "^3.1.3",
3434
"minipass-fetch": "^1.3.0",
3535
"minipass-json-stream": "^1.0.1",

test/check-response.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,31 @@ More info here: https://github.com/npm/cli/wiki/No-auth-for-URI,-but-auth-presen
168168
},
169169
}), errors.HttpErrorGeneral)
170170
})
171+
172+
t.test('logs the value of x-local-cache-status when set', t => {
173+
const headers = new Headers()
174+
const EE = require('events')
175+
headers.get = header => header === 'x-local-cache-status' ? 'hit' : undefined
176+
const res = Object.assign({}, mockFetchRes, {
177+
headers,
178+
status: 200,
179+
url: 'http://username:[email protected]/foo/bar/baz',
180+
body: new EE(),
181+
})
182+
t.plan(2)
183+
checkResponse({
184+
method: 'get',
185+
res,
186+
registry,
187+
startTime,
188+
opts: {
189+
log: Object.assign({}, silentLog, {
190+
http (header, msg) {
191+
t.equal(header, 'fetch')
192+
t.match(msg, /^GET 200 http:\/\/username:\*\*\*@example.com\/foo\/bar\/baz [0-9]+m?s \(cache hit\)$/)
193+
},
194+
}),
195+
},
196+
})
197+
res.body.emit('end')
198+
})

0 commit comments

Comments
 (0)