Skip to content

Commit d294092

Browse files
logaretmclaude
andcommitted
address reviewer feedback: use skip() instead of exit, export dc for testability
- Replace process.exit(0) with poku's skip() for better test reporting - Export dc and hasTracingChannel from tracing.js for testing - Add unit test for tracing module (dc availability, channel setup, getServerContext) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b35f667 commit d294092

4 files changed

Lines changed: 55 additions & 3 deletions

File tree

lib/tracing.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export interface PoolConnectTraceContext {
2929
serverPort: number | undefined;
3030
}
3131

32+
export declare const dc: typeof import('node:diagnostics_channel') | undefined;
33+
export declare const hasTracingChannel: boolean;
34+
3235
export declare const queryChannel:
3336
| TracingChannel<QueryTraceContext>
3437
| undefined;

lib/tracing.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ function tracePoolConnect(fn, contextFactory) {
7070
}
7171

7272
module.exports = {
73+
dc,
74+
hasTracingChannel,
7375
queryChannel,
7476
executeChannel,
7577
connectChannel,

test/integration/tracing-channel.test.mts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ import type {
66
} from '../../lib/tracing.js';
77
import type { RowDataPacket } from '../../promise.js';
88
import diagnostics_channel from 'node:diagnostics_channel';
9-
import { assert, describe, it } from 'poku';
9+
import { assert, describe, it, skip } from 'poku';
1010
import { config, createConnection, createPool } from '../common.test.mjs';
1111

1212
const hasTracingChannel =
1313
typeof diagnostics_channel.tracingChannel === 'function';
1414

1515
if (!hasTracingChannel) {
16-
// TracingChannel requires Node 19.9+ / 20+
17-
process.exit(0);
16+
skip('TracingChannel requires Node 19.9+ / 20+');
1817
}
1918

2019
interface TraceEvent<T> {

test/unit/test-tracing.test.mts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { describe, it, strict } from 'poku';
2+
import tracing from '../../lib/tracing.js';
3+
4+
const { dc, hasTracingChannel } = tracing;
5+
6+
await describe('Tracing module', async () => {
7+
await it('should load diagnostics_channel', () => {
8+
// dc should be defined on Node.js versions that support diagnostics_channel
9+
strict.ok(
10+
dc !== undefined,
11+
'diagnostics_channel should be available'
12+
);
13+
});
14+
15+
await it('should detect TracingChannel support', () => {
16+
if (typeof dc?.tracingChannel === 'function') {
17+
strict.ok(hasTracingChannel, 'hasTracingChannel should be true when tracingChannel exists');
18+
strict.ok(tracing.queryChannel !== undefined, 'queryChannel should be defined');
19+
strict.ok(tracing.executeChannel !== undefined, 'executeChannel should be defined');
20+
strict.ok(tracing.connectChannel !== undefined, 'connectChannel should be defined');
21+
strict.ok(tracing.poolConnectChannel !== undefined, 'poolConnectChannel should be defined');
22+
} else {
23+
strict.ok(!hasTracingChannel, 'hasTracingChannel should be false when tracingChannel is unavailable');
24+
strict.strictEqual(tracing.queryChannel, undefined, 'queryChannel should be undefined');
25+
strict.strictEqual(tracing.executeChannel, undefined, 'executeChannel should be undefined');
26+
strict.strictEqual(tracing.connectChannel, undefined, 'connectChannel should be undefined');
27+
strict.strictEqual(tracing.poolConnectChannel, undefined, 'poolConnectChannel should be undefined');
28+
}
29+
});
30+
31+
await it('should return server context for host/port', () => {
32+
const ctx = tracing.getServerContext({ host: '127.0.0.1', port: 3307 });
33+
strict.strictEqual(ctx.serverAddress, '127.0.0.1');
34+
strict.strictEqual(ctx.serverPort, 3307);
35+
});
36+
37+
await it('should return server context for socketPath', () => {
38+
const ctx = tracing.getServerContext({ socketPath: '/tmp/mysql.sock' });
39+
strict.strictEqual(ctx.serverAddress, '/tmp/mysql.sock');
40+
strict.strictEqual(ctx.serverPort, undefined);
41+
});
42+
43+
await it('should default to localhost:3306', () => {
44+
const ctx = tracing.getServerContext({});
45+
strict.strictEqual(ctx.serverAddress, 'localhost');
46+
strict.strictEqual(ctx.serverPort, 3306);
47+
});
48+
});

0 commit comments

Comments
 (0)