Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add diagnostics_channel publish at initialization time (#3279)
- Loading branch information
Showing
3 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
'use strict' | ||
|
||
const t = require('tap') | ||
const test = t.test | ||
const proxyquire = require('proxyquire') | ||
|
||
test('diagnostics_channel when present and subscribers', t => { | ||
t.plan(3) | ||
|
||
let fastifyInHook | ||
|
||
const dc = { | ||
channel (name) { | ||
t.equal(name, 'fastify.initialization') | ||
return { | ||
hasSubscribers: true, | ||
publish (event) { | ||
t.ok(event.fastify) | ||
fastifyInHook = event.fastify | ||
} | ||
} | ||
}, | ||
'@noCallThru': true | ||
} | ||
|
||
const fastify = proxyquire('../fastify', { | ||
diagnostics_channel: dc | ||
})() | ||
t.equal(fastifyInHook, fastify) | ||
}) | ||
|
||
test('diagnostics_channel when present and no subscribers', t => { | ||
t.plan(1) | ||
|
||
const dc = { | ||
channel (name) { | ||
t.equal(name, 'fastify.initialization') | ||
return { | ||
hasSubscribers: false, | ||
publish () { | ||
t.fail('publish should not be called') | ||
} | ||
} | ||
}, | ||
'@noCallThru': true | ||
} | ||
|
||
proxyquire('../fastify', { | ||
diagnostics_channel: dc | ||
})() | ||
}) | ||
|
||
test('diagnostics_channel when not present', t => { | ||
t.plan(1) | ||
|
||
t.doesNotThrow(() => { | ||
proxyquire('../fastify', { | ||
diagnostics_channel: null | ||
})() | ||
}) | ||
}) |