@@ -4,6 +4,7 @@ const figures = require('figures')
44const fs = require ( 'fs' )
55const mkdirp = require ( 'mkdirp' )
66const path = require ( 'path' )
7+ const cheerio = require ( 'cheerio' )
78
89const Container = require ( '../container' )
910const recorder = require ( '../recorder' )
@@ -133,7 +134,49 @@ module.exports = function (config) {
133134
134135 event . dispatcher . on ( event . all . result , ( ) => {
135136 if ( Object . keys ( recordedTests ) . length === 0 || ! Object . keys ( slides ) . length ) return
137+ generateRecordsHtml ( recordedTests )
138+ } )
139+
140+ event . dispatcher . on ( event . workers . result , async ( ) => {
141+ await recorder . add ( ( ) => {
142+ const recordedTests = getRecordFoldersWithDetails ( reportDir )
143+ generateRecordsHtml ( recordedTests )
144+ } )
145+ } )
136146
147+ function getRecordFoldersWithDetails ( dirPath ) {
148+ let results = { }
149+
150+ try {
151+ const items = fs . readdirSync ( dirPath , { withFileTypes : true } )
152+
153+ items . forEach ( ( item ) => {
154+ if ( item . isDirectory ( ) && item . name . startsWith ( 'record_' ) ) {
155+ const recordFolderPath = path . join ( dirPath , item . name )
156+ const indexPath = path . join ( recordFolderPath , 'index.html' )
157+
158+ let name = ''
159+ if ( fs . existsSync ( indexPath ) ) {
160+ try {
161+ const htmlContent = fs . readFileSync ( indexPath , 'utf-8' )
162+ const $ = cheerio . load ( htmlContent )
163+ name = $ ( '.navbar-brand' ) . text ( ) . trim ( )
164+ } catch ( err ) {
165+ console . error ( `Error reading index.html in ${ recordFolderPath } :` , err . message )
166+ }
167+ }
168+
169+ results [ name || 'Unkown' ] = `${ item . name } /index.html`
170+ }
171+ } )
172+ } catch ( err ) {
173+ console . error ( `Error reading directory ${ dirPath } :` , err . message )
174+ }
175+
176+ return results
177+ }
178+
179+ function generateRecordsHtml ( recordedTests ) {
137180 let links = ''
138181
139182 for ( const link in recordedTests ) {
@@ -150,7 +193,7 @@ module.exports = function (config) {
150193 output . print (
151194 `${ figures . circleFilled } Step-by-step preview: ${ colors . white . bold ( `file://${ reportDir } /records.html` ) } ` ,
152195 )
153- } )
196+ }
154197
155198 async function persistStep ( step ) {
156199 if ( stepNum === - 1 ) return // Ignore steps from BeforeSuite function
0 commit comments