1- import { MockTraceEventFileSink } from '../../../mocks/sink.mock.js ' ;
1+ import path from 'node:path ' ;
22import type { PerformanceEntryEncoder } from '../performance-observer.js' ;
33import { NodejsProfiler } from './profiler-node.js' ;
44
@@ -10,7 +10,6 @@ describe('NodeJS Profiler Integration', () => {
1010 return [ ] ;
1111 } ;
1212
13- let mockSink : MockTraceEventFileSink ;
1413 let nodejsProfiler : NodejsProfiler < string > ;
1514 const originalProfilingEnv = process . env . CP_PROFILING ;
1615 const originalDebugEnv = process . env . CP_PROFILER_DEBUG ;
@@ -23,13 +22,11 @@ describe('NodeJS Profiler Integration', () => {
2322 // eslint-disable-next-line functional/immutable-data
2423 delete process . env . CP_PROFILER_DEBUG ;
2524
26- mockSink = new MockTraceEventFileSink ( ) ;
27-
2825 nodejsProfiler = new NodejsProfiler ( {
2926 prefix : 'test' ,
3027 track : 'test-track' ,
31- sink : mockSink ,
3228 encodePerfEntry : simpleEncoder ,
29+ filename : path . join ( process . cwd ( ) , 'tmp' , 'int' , 'utils' , 'trace.json' ) ,
3330 enabled : true ,
3431 } ) ;
3532 } ) ;
@@ -55,9 +52,8 @@ describe('NodeJS Profiler Integration', () => {
5552 } ) ;
5653
5754 it ( 'should initialize with sink opened when enabled' , ( ) => {
58- expect ( mockSink . isClosed ( ) ) . toBeFalse ( ) ;
5955 expect ( nodejsProfiler . isEnabled ( ) ) . toBeTrue ( ) ;
60- expect ( mockSink . open ) . toHaveBeenCalledOnce ( ) ;
56+ expect ( nodejsProfiler . stats . walOpen ) . toBeTrue ( ) ;
6157 } ) ;
6258
6359 it ( 'should create performance entries and write to sink' , ( ) => {
@@ -75,26 +71,24 @@ describe('NodeJS Profiler Integration', () => {
7571 ) . resolves . toBe ( 'async-result' ) ;
7672 } ) ;
7773
78- it ( 'should disable profiling and keep sink open ' , ( ) => {
74+ it ( 'should disable profiling and close sink' , ( ) => {
7975 nodejsProfiler . setEnabled ( false ) ;
8076 expect ( nodejsProfiler . isEnabled ( ) ) . toBeFalse ( ) ;
81- expect ( mockSink . isClosed ( ) ) . toBeFalse ( ) ;
82- expect ( mockSink . close ) . not . toHaveBeenCalled ( ) ;
77+ expect ( nodejsProfiler . stats . walOpen ) . toBeFalse ( ) ;
8378
8479 expect ( nodejsProfiler . measure ( 'disabled-test' , ( ) => 'success' ) ) . toBe (
8580 'success' ,
8681 ) ;
87-
88- expect ( mockSink . getWrittenItems ( ) ) . toHaveLength ( 0 ) ;
8982 } ) ;
9083
9184 it ( 'should re-enable profiling correctly' , ( ) => {
9285 nodejsProfiler . setEnabled ( false ) ;
86+ expect ( nodejsProfiler . stats . walOpen ) . toBeFalse ( ) ;
87+
9388 nodejsProfiler . setEnabled ( true ) ;
9489
9590 expect ( nodejsProfiler . isEnabled ( ) ) . toBeTrue ( ) ;
96- expect ( mockSink . isClosed ( ) ) . toBeFalse ( ) ;
97- expect ( mockSink . open ) . toHaveBeenCalledTimes ( 2 ) ;
91+ expect ( nodejsProfiler . stats . walOpen ) . toBeTrue ( ) ;
9892
9993 expect ( nodejsProfiler . measure ( 're-enabled-test' , ( ) => 42 ) ) . toBe ( 42 ) ;
10094 } ) ;
@@ -107,8 +101,14 @@ describe('NodeJS Profiler Integration', () => {
107101 db : { track : 'Database' , color : 'secondary' } ,
108102 cache : { track : 'Cache' , color : 'primary' } ,
109103 } ,
110- sink : mockSink ,
111104 encodePerfEntry : simpleEncoder ,
105+ filename : path . join (
106+ process . cwd ( ) ,
107+ 'tmp' ,
108+ 'int' ,
109+ 'utils' ,
110+ 'trace-tracks.json' ,
111+ ) ,
112112 } ) ;
113113
114114 expect (
@@ -124,15 +124,21 @@ describe('NodeJS Profiler Integration', () => {
124124 const bufferedProfiler = new NodejsProfiler ( {
125125 prefix : 'buffered-test' ,
126126 track : 'Test' ,
127- sink : mockSink ,
128127 encodePerfEntry : simpleEncoder ,
129128 captureBufferedEntries : true ,
129+ filename : path . join (
130+ process . cwd ( ) ,
131+ 'tmp' ,
132+ 'int' ,
133+ 'utils' ,
134+ 'trace-buffered.json' ,
135+ ) ,
130136 enabled : true ,
131137 } ) ;
132138
133139 const bufferedStats = bufferedProfiler . stats ;
134140 expect ( bufferedStats . state ) . toBe ( 'running' ) ;
135- expect ( bufferedStats . sinkOpen ) . toBeTrue ( ) ;
141+ expect ( bufferedStats . walOpen ) . toBeTrue ( ) ;
136142 expect ( bufferedStats . isSubscribed ) . toBeTrue ( ) ;
137143 expect ( bufferedStats . queued ) . toBe ( 0 ) ;
138144 expect ( bufferedStats . dropped ) . toBe ( 0 ) ;
@@ -145,18 +151,24 @@ describe('NodeJS Profiler Integration', () => {
145151 const statsProfiler = new NodejsProfiler ( {
146152 prefix : 'stats-test' ,
147153 track : 'Stats' ,
148- sink : mockSink ,
149154 encodePerfEntry : simpleEncoder ,
150155 maxQueueSize : 2 ,
151156 flushThreshold : 2 ,
157+ filename : path . join (
158+ process . cwd ( ) ,
159+ 'tmp' ,
160+ 'int' ,
161+ 'utils' ,
162+ 'trace-stats.json' ,
163+ ) ,
152164 enabled : true ,
153165 } ) ;
154166
155167 expect ( statsProfiler . measure ( 'test-op' , ( ) => 'result' ) ) . toBe ( 'result' ) ;
156168
157169 const stats = statsProfiler . stats ;
158170 expect ( stats . state ) . toBe ( 'running' ) ;
159- expect ( stats . sinkOpen ) . toBeTrue ( ) ;
171+ expect ( stats . walOpen ) . toBeTrue ( ) ;
160172 expect ( stats . isSubscribed ) . toBeTrue ( ) ;
161173 expect ( typeof stats . queued ) . toBe ( 'number' ) ;
162174 expect ( typeof stats . dropped ) . toBe ( 'number' ) ;
@@ -169,16 +181,22 @@ describe('NodeJS Profiler Integration', () => {
169181 const profiler = new NodejsProfiler ( {
170182 prefix : 'stats-profiler' ,
171183 track : 'Stats' ,
172- sink : mockSink ,
173184 encodePerfEntry : simpleEncoder ,
174185 maxQueueSize : 3 ,
175186 flushThreshold : 2 ,
187+ filename : path . join (
188+ process . cwd ( ) ,
189+ 'tmp' ,
190+ 'int' ,
191+ 'utils' ,
192+ 'trace-stats-comprehensive.json' ,
193+ ) ,
176194 enabled : true ,
177195 } ) ;
178196
179197 const initialStats = profiler . stats ;
180198 expect ( initialStats . state ) . toBe ( 'running' ) ;
181- expect ( initialStats . sinkOpen ) . toBeTrue ( ) ;
199+ expect ( initialStats . walOpen ) . toBeTrue ( ) ;
182200 expect ( initialStats . isSubscribed ) . toBeTrue ( ) ;
183201 expect ( initialStats . queued ) . toBe ( 0 ) ;
184202 expect ( initialStats . dropped ) . toBe ( 0 ) ;
@@ -193,7 +211,7 @@ describe('NodeJS Profiler Integration', () => {
193211
194212 const finalStats = profiler . stats ;
195213 expect ( finalStats . state ) . toBe ( 'idle' ) ;
196- expect ( finalStats . sinkOpen ) . toBeTrue ( ) ;
214+ expect ( finalStats . walOpen ) . toBeFalse ( ) ;
197215 expect ( finalStats . isSubscribed ) . toBeFalse ( ) ;
198216 expect ( finalStats . queued ) . toBe ( 0 ) ;
199217
0 commit comments