Skip to content

Commit

Permalink
add diagnostics_channel publish at load time
Browse files Browse the repository at this point in the history
  • Loading branch information
bengl committed Aug 24, 2021
1 parent 6ded7ff commit 4aa6a75
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions fastify.js
Expand Up @@ -707,3 +707,11 @@ function loadVersion () {
module.exports = fastify
module.exports.fastify = fastify
module.exports.default = fastify

try {
const dc = require('diagnostics_channel')
dc.channel('fastify:loaded').publish(fastify)
} catch (e) {
// This only happens if `diagnostics_channel` isn't available, i.e. earlier versions of Node.js.
// In that event, we don't care, so ignore the error.
}
19 changes: 19 additions & 0 deletions test/diagnostics-channel.test.js
@@ -0,0 +1,19 @@
'use strict'

const t = require('tap')
const test = t.test
const dc = require('diagnostics_channel')

test('diagnostics_channel', t => {
t.plan(2)

let fastifyInHook

const channel = dc.channel('fastify:loaded')
channel.subscribe(function (fastify) {
t.pass('message passed to channel')
fastifyInHook = fastify
})
const fastify = require('../fastify')
t.equal(fastifyInHook, fastify)
})

0 comments on commit 4aa6a75

Please sign in to comment.