@@ -4,6 +4,7 @@ const figures = require('figures')
4
4
const fs = require ( 'fs' )
5
5
const mkdirp = require ( 'mkdirp' )
6
6
const path = require ( 'path' )
7
+ const cheerio = require ( 'cheerio' )
7
8
8
9
const Container = require ( '../container' )
9
10
const recorder = require ( '../recorder' )
@@ -133,7 +134,49 @@ module.exports = function (config) {
133
134
134
135
event . dispatcher . on ( event . all . result , ( ) => {
135
136
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
+ } )
136
146
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 ) {
137
180
let links = ''
138
181
139
182
for ( const link in recordedTests ) {
@@ -150,7 +193,7 @@ module.exports = function (config) {
150
193
output . print (
151
194
`${ figures . circleFilled } Step-by-step preview: ${ colors . white . bold ( `file://${ reportDir } /records.html` ) } ` ,
152
195
)
153
- } )
196
+ }
154
197
155
198
async function persistStep ( step ) {
156
199
if ( stepNum === - 1 ) return // Ignore steps from BeforeSuite function
0 commit comments