Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.

Commit abaefb4

Browse files
authored
fix: specify updated formatter for multiaddrs (#36)
1 parent d2920de commit abaefb4

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
"@libp2p/peer-id": "^2.0.3",
150150
"@types/debug": "^4.1.7",
151151
"aegir": "^38.1.7",
152+
"sinon": "^15.1.0",
152153
"uint8arrays": "^4.0.3"
153154
}
154155
}

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ debug.formatters.k = (v: Key): string => {
3838
}
3939

4040
// Add a formatter for stringifying Multiaddrs
41-
debug.formatters.ma = (v?: Multiaddr): string => {
41+
debug.formatters.a = (v?: Multiaddr): string => {
4242
return v == null ? 'undefined' : v.toString()
4343
}
4444

test/index.spec.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { base58btc } from 'multiformats/bases/base58'
99
import { base32 } from 'multiformats/bases/base32'
1010
import { base64 } from 'multiformats/bases/base64'
1111
import { Key } from 'interface-datastore'
12+
import sinon from 'sinon'
1213

1314
describe('logger', () => {
1415
it('creates a logger', () => {
@@ -70,13 +71,26 @@ describe('logger', () => {
7071
expect(debug.formatters).to.have.property('p').that.is.a('function')
7172
expect(debug.formatters).to.have.property('c').that.is.a('function')
7273
expect(debug.formatters).to.have.property('k').that.is.a('function')
73-
expect(debug.formatters).to.have.property('ma').that.is.a('function')
74+
expect(debug.formatters).to.have.property('a').that.is.a('function')
75+
})
76+
77+
it('test printf style formatting', () => {
78+
const log = logger('printf-style')
79+
debug.enable('printf-style')
80+
81+
const ma = multiaddr('/ip4/127.0.0.1/tcp/4001')
82+
83+
const debugSpy = sinon.spy(debug, 'log')
84+
85+
log('multiaddr %a', ma)
86+
87+
expect(debugSpy.firstCall.args[0], 'Multiaddr formatting not included').to.include(`multiaddr ${ma.toString()}`)
7488
})
7589

7690
it('test ma formatter', () => {
7791
const ma = multiaddr('/ip4/127.0.0.1/tcp/4001')
7892

79-
expect(debug.formatters.ma(ma)).to.equal(ma.toString())
93+
expect(debug.formatters.a(ma)).to.equal(ma.toString())
8094
})
8195

8296
it('test peerId formatter', () => {

0 commit comments

Comments
 (0)