@@ -138,6 +138,42 @@ describe('performance', () => {
138138 ) ;
139139 } ) ;
140140 } ) ;
141+
142+ it ( 'supports filePath' , async ( ) => {
143+ const rawData = loadTraceAsBuffer ( 'basic-trace.json.gz' ) ;
144+ await withMcpContext ( async ( response , context ) => {
145+ const filePath = 'test-trace.json' ;
146+ const selectedPage = context . getSelectedPage ( ) ;
147+ sinon . stub ( selectedPage , 'url' ) . callsFake ( ( ) => 'https://www.test.com' ) ;
148+ sinon . stub ( selectedPage , 'goto' ) . callsFake ( ( ) => Promise . resolve ( null ) ) ;
149+ sinon . stub ( selectedPage . tracing , 'start' ) ;
150+ sinon . stub ( selectedPage . tracing , 'stop' ) . resolves ( rawData ) ;
151+ const saveFileStub = sinon
152+ . stub ( context , 'saveFile' )
153+ . resolves ( { filename : filePath } ) ;
154+
155+ const clock = sinon . useFakeTimers ( { shouldClearNativeTimers : true } ) ;
156+ try {
157+ const handlerPromise = startTrace . handler (
158+ { params : { reload : true , autoStop : true , filePath} } ,
159+ response ,
160+ context ,
161+ ) ;
162+ await clock . tickAsync ( 6_000 ) ;
163+ await handlerPromise ;
164+
165+ assert . ok (
166+ response . responseLines . includes (
167+ `The raw trace data was saved to ${ filePath } .` ,
168+ ) ,
169+ ) ;
170+ sinon . assert . calledOnce ( saveFileStub ) ;
171+ sinon . assert . calledWith ( saveFileStub , rawData , filePath ) ;
172+ } finally {
173+ clock . restore ( ) ;
174+ }
175+ } ) ;
176+ } ) ;
141177 } ) ;
142178
143179 describe ( 'performance_analyze_insight' , ( ) => {
@@ -275,5 +311,31 @@ describe('performance', () => {
275311 t . assert . snapshot ?.( response . responseLines . join ( '\n' ) ) ;
276312 } ) ;
277313 } ) ;
314+
315+ it ( 'supports filePath' , async ( ) => {
316+ const rawData = loadTraceAsBuffer ( 'basic-trace.json.gz' ) ;
317+ await withMcpContext ( async ( response , context ) => {
318+ const filePath = 'test-trace.json' ;
319+ context . setIsRunningPerformanceTrace ( true ) ;
320+ const selectedPage = context . getSelectedPage ( ) ;
321+ const stopTracingStub = sinon
322+ . stub ( selectedPage . tracing , 'stop' )
323+ . resolves ( rawData ) ;
324+ const saveFileStub = sinon
325+ . stub ( context , 'saveFile' )
326+ . resolves ( { filename : filePath } ) ;
327+
328+ await stopTrace . handler ( { params : { filePath} } , response , context ) ;
329+
330+ sinon . assert . calledOnce ( stopTracingStub ) ;
331+ sinon . assert . calledOnce ( saveFileStub ) ;
332+ sinon . assert . calledWith ( saveFileStub , rawData , filePath ) ;
333+ assert . ok (
334+ response . responseLines . includes (
335+ `The raw trace data was saved to ${ filePath } .` ,
336+ ) ,
337+ ) ;
338+ } ) ;
339+ } ) ;
278340 } ) ;
279341} ) ;
0 commit comments