Skip to content

Commit dd7bf1f

Browse files
authored
fix(stepByStepReport): no records html is generated when running with run-workers (#4638)
1 parent 02420fa commit dd7bf1f

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

lib/plugin/stepByStepReport.js

+44-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const figures = require('figures')
44
const fs = require('fs')
55
const mkdirp = require('mkdirp')
66
const path = require('path')
7+
const cheerio = require('cheerio')
78

89
const Container = require('../container')
910
const 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

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"chai-match-pattern": "1.3.0",
8686
"chai-string": "1.5.0",
8787
"chalk": "4.1.2",
88+
"cheerio": "^1.0.0",
8889
"commander": "11.1.0",
8990
"cross-spawn": "7.0.5",
9091
"css-to-xpath": "0.1.0",
@@ -134,7 +135,6 @@
134135
"apollo-server-express": "3.13.0",
135136
"chai-as-promised": "7.1.2",
136137
"chai-subset": "1.6.0",
137-
"cheerio": "^1.0.0",
138138
"contributor-faces": "1.1.0",
139139
"documentation": "14.0.3",
140140
"electron": "33.2.1",
@@ -184,4 +184,4 @@
184184
"strict": false
185185
}
186186
}
187-
}
187+
}

0 commit comments

Comments
 (0)