11import {
22 AveragedTestCaseResult ,
3- Measure ,
43 TestCaseIterationResult ,
54 TestCaseIterationStatus ,
65} from "@perf-profiler/types" ;
76import { PerformanceMeasurer } from "./PerformanceMeasurer" ;
8- import { profiler } from "@perf-profiler/profiler" ;
9- import { basename , dirname } from "path" ;
107
118export interface TestCase {
129 beforeTest ?: ( ) => Promise < void > | void ;
@@ -39,11 +36,15 @@ export class SingleIterationTester {
3936 ) { }
4037
4138 private currentTestCaseIterationResult : TestCaseIterationResult | undefined = undefined ;
42- private performanceMeasurer : PerformanceMeasurer = new PerformanceMeasurer ( this . bundleId ) ;
4339 private videoPath = `${ this . options . resultsFileOptions . path . replace ( ".json" , "" ) } _iteration_${
4440 this . iterationIndex
4541 } _${ new Date ( ) . getTime ( ) } .mp4`;
46- private recorder = profiler . getScreenRecorder ( basename ( this . videoPath ) ) ;
42+ private performanceMeasurer : PerformanceMeasurer = new PerformanceMeasurer ( this . bundleId , {
43+ recordOptions : {
44+ ...this . options . recordOptions ,
45+ videoPath : this . videoPath ,
46+ } ,
47+ } ) ;
4748
4849 public getCurrentTestCaseIterationResult ( ) {
4950 return this . currentTestCaseIterationResult ;
@@ -55,62 +56,34 @@ export class SingleIterationTester {
5556 try {
5657 if ( beforeTest ) await beforeTest ( ) ;
5758
58- await this . maybeStartRecording ( ) ;
59- this . performanceMeasurer . start ( ) ;
59+ await this . performanceMeasurer . start ( ) ;
6060 await run ( ) ;
6161 const measures = await this . performanceMeasurer . stop ( duration ) ;
62- await this . maybeStopRecording ( ) ;
6362
6463 if ( afterTest ) await afterTest ( ) ;
6564
6665 this . setCurrentTestCaseIterationResult ( measures , "SUCCESS" ) ;
6766 } catch ( error ) {
6867 const measures = await this . performanceMeasurer . stop ( ) ;
69- await this . maybeStopRecording ( ) ;
7068 this . setCurrentTestCaseIterationResult ( measures , "FAILURE" ) ;
7169 this . performanceMeasurer . forceStop ( ) ;
7270 throw error ;
7371 }
7472 }
7573
76- private async maybeStartRecording ( ) {
77- if ( this . options . recordOptions . record && this . recorder ) {
78- const { bitRate, size } = this . options . recordOptions ;
79- await this . recorder . startRecording ( { bitRate, size } ) ;
80- }
81- }
82-
8374 public setIsRetry ( isRetry : boolean ) {
8475 if ( this . currentTestCaseIterationResult ) {
8576 this . currentTestCaseIterationResult . isRetriedIteration = isRetry ;
8677 }
8778 }
8879
89- private async maybeStopRecording ( ) {
90- if ( this . options . recordOptions . record && this . recorder ) {
91- await this . recorder . stopRecording ( ) ;
92- await this . recorder . pullRecording ( dirname ( this . options . resultsFileOptions . path ) ) ;
93- }
94- }
95-
9680 private setCurrentTestCaseIterationResult (
97- measures : {
98- time : number ;
99- startTime : number ;
100- measures : Measure [ ] ;
101- } ,
81+ measures : TestCaseIterationResult ,
10282 status : TestCaseIterationStatus
10383 ) {
10484 this . currentTestCaseIterationResult = {
10585 ...measures ,
10686 status,
107- videoInfos :
108- this . options . recordOptions . record && this . recorder
109- ? {
110- path : this . videoPath ,
111- startOffset : Math . floor ( measures . startTime - this . recorder . getRecordingStartTime ( ) ) ,
112- }
113- : undefined ,
11487 } ;
11588 }
11689}
0 commit comments