Skip to content

Commit bbddc0c

Browse files
committed
test: cover executeIgnoringIncremental traced path and drop unused traceSync
The traced branch of `executeIgnoringIncremental` was not exercised by any subscriber-attached test, tripping the 100% coverage threshold on CI. Add a case in execute-diagnostics-test that subscribes to `graphql:execute` and asserts start/end around a call. Also drop the `traceSync` helper from diagnostics.ts; every call site invokes `channel.traceSync(...)` directly, so the export was dead code. Mark the `require('node:diagnostics_channel')` CJS fallback and the enclosing `catch` block with c8 ignore comments — they are only reachable on Node 20.0-20.15 (pre-`getBuiltinModule`) and on runtimes without `diagnostics_channel` at all, neither of which the unit tests run on.
1 parent 03c9fea commit bbddc0c

2 files changed

Lines changed: 14 additions & 15 deletions

File tree

src/diagnostics.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,14 @@ function resolveDiagnosticsChannel(): DiagnosticsChannelModule | undefined {
8585
}
8686
).getBuiltinModule('node:diagnostics_channel');
8787
}
88+
/* c8 ignore next 6 */
8889
if (!dc && typeof require === 'function') {
8990
// CJS fallback for runtimes that lack `process.getBuiltinModule`
9091
// (e.g. Node 20.0 - 20.15). ESM builds skip this branch because
9192
// `require` is undeclared there.
9293
dc = require('node:diagnostics_channel') as DiagnosticsChannelModule;
9394
}
95+
/* c8 ignore next 3 */
9496
} catch {
9597
// diagnostics_channel not available on this runtime; tracing is a no-op.
9698
}
@@ -122,21 +124,6 @@ export const subscribeChannel: MinimalTracingChannel | undefined =
122124
export const resolveChannel: MinimalTracingChannel | undefined =
123125
dc?.tracingChannel('graphql:resolve');
124126

125-
/**
126-
* Publish a synchronous operation through `channel`. Caller has already
127-
* verified that a subscriber is attached; this helper exists only so the
128-
* traced path doesn't need to be duplicated at every emission site.
129-
*
130-
* @internal
131-
*/
132-
export function traceSync<T>(
133-
channel: MinimalTracingChannel,
134-
ctx: object,
135-
fn: () => T,
136-
): T {
137-
return channel.traceSync(fn, ctx);
138-
}
139-
140127
/**
141128
* Publish a mixed sync-or-promise operation through `channel`. Caller has
142129
* already verified that a subscriber is attached.

src/execution/__tests__/execute-diagnostics-test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { buildSchema } from '../../utilities/buildASTSchema.js';
1313
import type { ExecutionArgs } from '../execute.js';
1414
import {
1515
execute,
16+
executeIgnoringIncremental,
1617
executeSubscriptionEvent,
1718
executeSync,
1819
validateExecutionArgs,
@@ -78,6 +79,17 @@ describe('execute diagnostics channel', () => {
7879
expect(active.events.map((e) => e.kind)).to.deep.equal(['start', 'end']);
7980
});
8081

82+
it('emits start and end around executeIgnoringIncremental', () => {
83+
active = collectEvents(executeChannel);
84+
85+
const document = parse('query Q { sync }');
86+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
87+
executeIgnoringIncremental({ schema, document, rootValue });
88+
89+
expect(active.events.map((e) => e.kind)).to.deep.equal(['start', 'end']);
90+
expect(active.events[0].ctx.operationName).to.equal('Q');
91+
});
92+
8193
it('emits start, error, and end when execute throws synchronously', () => {
8294
active = collectEvents(executeChannel);
8395

0 commit comments

Comments
 (0)