|
1 | | -/* eslint-disable import/no-nodejs-modules */ |
| 1 | +/* eslint-disable import/no-nodejs-modules, n/no-unsupported-features/node-builtins */ |
2 | 2 | import dc from 'node:diagnostics_channel'; |
3 | 3 |
|
4 | 4 | import { expect } from 'chai'; |
5 | 5 | import { describe, it } from 'mocha'; |
6 | 6 |
|
7 | 7 | import { invariant } from '../jsutils/invariant.js'; |
8 | 8 |
|
| 9 | +import type { MinimalTracingChannel } from '../diagnostics.js'; |
9 | 10 | import { |
10 | 11 | executeChannel, |
11 | 12 | parseChannel, |
12 | 13 | resolveChannel, |
| 14 | + shouldTrace, |
13 | 15 | subscribeChannel, |
14 | 16 | validateChannel, |
15 | 17 | } from '../diagnostics.js'; |
@@ -40,4 +42,32 @@ describe('diagnostics', () => { |
40 | 42 | dc.channel('tracing:graphql:resolve:start'), |
41 | 43 | ); |
42 | 44 | }); |
| 45 | + |
| 46 | + describe('shouldTrace', () => { |
| 47 | + it('returns false when channel is undefined', () => { |
| 48 | + expect(shouldTrace(undefined)).to.equal(false); |
| 49 | + }); |
| 50 | + |
| 51 | + it('reflects the aggregate hasSubscribers on a real tracing channel', () => { |
| 52 | + const tc = dc.tracingChannel( |
| 53 | + 'shouldTrace:aggregate', |
| 54 | + ) as unknown as MinimalTracingChannel; |
| 55 | + expect(shouldTrace(tc)).to.equal(false); |
| 56 | + |
| 57 | + const handler = { |
| 58 | + start: () => undefined, |
| 59 | + end: () => undefined, |
| 60 | + asyncStart: () => undefined, |
| 61 | + asyncEnd: () => undefined, |
| 62 | + error: () => undefined, |
| 63 | + }; |
| 64 | + const realTC = dc.tracingChannel('shouldTrace:aggregate'); |
| 65 | + realTC.subscribe(handler); |
| 66 | + try { |
| 67 | + expect(shouldTrace(tc)).to.equal(true); |
| 68 | + } finally { |
| 69 | + realTC.unsubscribe(handler); |
| 70 | + } |
| 71 | + }); |
| 72 | + }); |
43 | 73 | }); |
0 commit comments