|
| 1 | +import t from 'tap' |
| 2 | +import actualDC from 'node:diagnostics_channel' |
| 3 | + |
| 4 | +t.test('diagnostics channel loads polyfills then fills in', async t => { |
| 5 | + const dc = await t.mockImport< |
| 6 | + typeof import('../src/diagnostics-channel-esm.mjs') |
| 7 | + >('../src/diagnostics-channel-esm.mjs', { |
| 8 | + 'node:diagnostics_channel': actualDC, |
| 9 | + }) |
| 10 | + actualDC.subscribe('lru-cache:metrics', () => {}) |
| 11 | + const tc = actualDC.tracingChannel('lru-cache') |
| 12 | + tc.subscribe({ |
| 13 | + start: () => {}, |
| 14 | + asyncStart: () => {}, |
| 15 | + asyncEnd: () => {}, |
| 16 | + error: () => {}, |
| 17 | + end: () => {}, |
| 18 | + }) |
| 19 | + |
| 20 | + // verify that the dummies were not used |
| 21 | + t.equal(dc.metrics.hasSubscribers, true) |
| 22 | + t.equal(dc.tracing.hasSubscribers, true) |
| 23 | + t.equal(actualDC.channel('lru-cache:metrics').hasSubscribers, true) |
| 24 | + t.equal(tc.hasSubscribers, true) |
| 25 | +}) |
| 26 | + |
| 27 | +t.test('dummy dc that just says no subs', async t => { |
| 28 | + const dc = await t.mockImport< |
| 29 | + typeof import('../src/diagnostics-channel-esm.mjs') |
| 30 | + >('../src/diagnostics-channel-esm.mjs', { |
| 31 | + 'node:diagnostics_channel': { |
| 32 | + get default() { |
| 33 | + throw new Error('no diagnostics channel for you!') |
| 34 | + }, |
| 35 | + }, |
| 36 | + }) |
| 37 | + t.equal(dc.metrics.hasSubscribers, false) |
| 38 | + t.equal(dc.tracing.hasSubscribers, false) |
| 39 | + // these still have subs from previous test though |
| 40 | + t.equal(actualDC.channel('lru-cache:metrics').hasSubscribers, true) |
| 41 | + t.equal(actualDC.tracingChannel('lru-cache').hasSubscribers, true) |
| 42 | +}) |
0 commit comments