11const yargs = require ( "yargs" ) ;
22const path = require ( "path" ) ;
3+ const fs = require ( 'fs' ) ;
34
45const pLimitReady = import ( "p-limit" ) ;
56const AggregateErrorReady = import ( "aggregate-error" ) ;
@@ -12,6 +13,22 @@ const TestCasesConfig = require("../../modules/integration-test/test-case/test-c
1213const TestCases = require ( "../../modules/integration-test/test-case/test-cases.js" ) ;
1314
1415
16+ function checkFileExist ( path , timeout = 5000 )
17+ {
18+ let totalTime = 0 ;
19+ let checkTime = 100 ;
20+ return new Promise ( ( resolve , reject ) => {
21+ const timer = setInterval ( function ( ) {
22+ totalTime += checkTime ;
23+ let fileExists = fs . existsSync ( path ) ;
24+ if ( fileExists || totalTime >= timeout ) {
25+ clearInterval ( timer ) ;
26+ resolve ( fileExists ) ;
27+ }
28+ } , checkTime ) ;
29+ } ) ;
30+ }
31+
1532class VideoRecorder {
1633
1734 #pLimit;
@@ -59,6 +76,9 @@ class VideoRecorder {
5976
6077 #runVideoRecorder( ) {
6178 return new Promise ( ( resolve , reject ) => {
79+ fs . rmSync ( "generated" , {
80+ force : true , recursive : true
81+ } ) ;
6282 this . #testCasesReady. then ( testCases => {
6383 this . #testCases = testCases ;
6484 if ( testCases . filteredTestCases . length > 0 ) {
@@ -88,6 +108,11 @@ class VideoRecorder {
88108 vizzuUrl = "/" + path . relative ( TestEnv . getWorkspacePath ( ) , vizzuUrl ) ;
89109 }
90110 let suitePath = "/" + path . relative ( TestEnv . getWorkspacePath ( ) , TestEnv . getTestSuitePath ( ) ) ;
111+ let downloadedFile = path . relative ( suitePath , path . dirname ( testCase . testFile ) ) . replaceAll ( "/" , "___" ) + "___" + path . basename ( testCase . testName ) + ".webm" ;
112+ fs . rmSync ( downloadedFile , {
113+ force : true ,
114+ } ) ;
115+ let outputFile = "generated/" + downloadedFile . replaceAll ( "___" , "/" ) ;
91116 browserChrome . getUrl ( "http://127.0.0.1:" + String ( this . #workspaceHostServerPort)
92117 + suitePath + "/modules/videorecorder/client/index.html"
93118 + "?testSuitePath=" + suitePath
@@ -106,7 +131,15 @@ class VideoRecorder {
106131 } else {
107132 console . log ( "ERROR: " + testCase . testName + " " + result . description ) ;
108133 }
109- return resolve ( result ) ;
134+ checkFileExist ( downloadedFile ) . then ( ( fileExists ) => {
135+ if ( fileExists ) {
136+ fs . mkdirSync ( path . dirname ( outputFile ) , { recursive : true } ) ;
137+ fs . renameSync ( downloadedFile , outputFile )
138+ return resolve ( result ) ;
139+ } else {
140+ return reject ( "TimeoutError: Waiting for file to be downloaded" ) ;
141+ }
142+ } ) ;
110143 } )
111144 } ) . catch ( err => {
112145 let errMsg = err . toString ( ) ;
0 commit comments