Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch: improve util.inspect output for web specifications #2938

Merged
merged 3 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/web/fetch/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
} = require('./util')
const { webidl } = require('./webidl')
const assert = require('node:assert')
const util = require('util')
mertcanaltin marked this conversation as resolved.
Show resolved Hide resolved

const kHeadersMap = Symbol('headers map')
const kHeadersSortedMap = Symbol('headers map sorted')
Expand Down Expand Up @@ -576,8 +577,18 @@

return this[kHeadersList]
}

[util.inspect.custom] (depth, options) {
const inspected = util.inspect(this[kHeadersList].entries)

Check failure on line 583 in lib/web/fetch/headers.js

View workflow job for this annotation

GitHub Actions / Lint

Trailing spaces not allowed
return `Headers ${inspected}`
}
}

Object.defineProperty(Headers.prototype, util.inspect.custom, {
enumerable: false
})

iteratorMixin('Headers', Headers, kHeadersSortedMap, 0, 1)

Object.defineProperties(Headers.prototype, {
Expand Down
18 changes: 18 additions & 0 deletions test/fetch/headers-inspect-custom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict'

const { Headers } = require('../../lib/web/fetch/headers')
const { test } = require('node:test')
const assert = require('node:assert')
const util = require('util')

test('Headers class custom inspection', () => {
const headers = new Headers()
headers.set('content-Type', 'application/json')
headers.set('authorization', 'Bearer token')
Fixed Show fixed Hide fixed

const inspectedOutput = util.inspect(headers, { depth: 1 })

const expectedOutput =
'Headers:\nContent-Type: application/json\nAuthorization: Bearer token'
assert.strictEqual(inspectedOutput, expectedOutput)

Check failure on line 17 in test/fetch/headers-inspect-custom.js

View workflow job for this annotation

GitHub Actions / Test with Node.js 18 on ubuntu-latest

Headers class custom inspection

[Error [ERR_TEST_FAILURE]: Expected values to be strictly equal: + actual - expected + "Headers { 'content-Type': 'application/json', authorization: '***' }" - 'Headers:\nContent-Type: application/json\nAuthorization: ***'] { failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: + actual - expected + "Headers { 'content-Type': 'application/json', authorization: '***' }" - 'Headers:\nContent-Type: application/json\nAuthorization: ***' at TestContext.<anonymous> (/home/runner/work/undici/undici/test/fetch/headers-inspect-custom.js:17:10) at Test.runInAsyncScope (node:async_hooks:203:9) at Test.run (node:internal/test_runner/test:631:25) at Test.start (node:internal/test_runner/test:542:17) at startSubtest (node:internal/test_runner/harness:214:17) { generatedMessage: true, code: 'ERR_ASSERTION', actual: "Headers { 'content-Type': 'application/json', authorization: '***' }", expected: 'Headers:\nContent-Type: application/json\nAuthorization: ***', operator: 'strictEqual' }, code: 'ERR_TEST_FAILURE' }

Check failure on line 17 in test/fetch/headers-inspect-custom.js

View workflow job for this annotation

GitHub Actions / Test with Node.js 20 on ubuntu-latest

Headers class custom inspection

[Error [ERR_TEST_FAILURE]: Expected values to be strictly equal: + actual - expected + "Headers { 'content-Type': 'application/json', authorization: '***' }" - 'Headers:\nContent-Type: application/json\nAuthorization: ***'] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: + actual - expected + "Headers { 'content-Type': 'application/json', authorization: '***' }" - 'Headers:\nContent-Type: application/json\nAuthorization: ***' at TestContext.<anonymous> (/home/runner/work/undici/undici/test/fetch/headers-inspect-custom.js:17:10) at Test.runInAsyncScope (node:async_hooks:206:9) at Test.run (node:internal/test_runner/test:631:25) at Test.start (node:internal/test_runner/test:542:17) at startSubtest (node:internal/test_runner/harness:216:17) { generatedMessage: true, code: 'ERR_ASSERTION', actual: "Headers { 'content-Type': 'application/json', authorization: '***' }", expected: 'Headers:\nContent-Type: application/json\nAuthorization: ***', operator: 'strictEqual' } }

Check failure on line 17 in test/fetch/headers-inspect-custom.js

View workflow job for this annotation

GitHub Actions / Test with Node.js 21 on ubuntu-latest

Headers class custom inspection

[Error [ERR_TEST_FAILURE]: Expected values to be strictly equal: + actual - expected + "Headers { 'content-Type': 'application/json', authorization: '***' }" - 'Headers:\nContent-Type: application/json\nAuthorization: ***'] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: + actual - expected + "Headers { 'content-Type': 'application/json', authorization: '***' }" - 'Headers:\nContent-Type: application/json\nAuthorization: ***' at TestContext.<anonymous> (/home/runner/work/undici/undici/test/fetch/headers-inspect-custom.js:17:10) at Test.runInAsyncScope (node:async_hooks:206:9) at Test.run (node:internal/test_runner/test:639:25) at Test.start (node:internal/test_runner/test:550:17) at startSubtest (node:internal/test_runner/harness:218:17) { generatedMessage: true, code: 'ERR_ASSERTION', actual: "Headers { 'content-Type': 'application/json', authorization: '***' }", expected: 'Headers:\nContent-Type: application/json\nAuthorization: ***', operator: 'strictEqual' } }
})
Loading