Skip to content

Commit

Permalink
fix(stepByStepReport): no records html is generated when running with…
Browse files Browse the repository at this point in the history
… run-workers (#4638)
  • Loading branch information
kobenguyent authored Dec 15, 2024
1 parent 02420fa commit dd7bf1f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
45 changes: 44 additions & 1 deletion lib/plugin/stepByStepReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const figures = require('figures')
const fs = require('fs')
const mkdirp = require('mkdirp')
const path = require('path')
const cheerio = require('cheerio')

const Container = require('../container')
const recorder = require('../recorder')
Expand Down Expand Up @@ -133,7 +134,49 @@ module.exports = function (config) {

event.dispatcher.on(event.all.result, () => {
if (Object.keys(recordedTests).length === 0 || !Object.keys(slides).length) return
generateRecordsHtml(recordedTests)
})

event.dispatcher.on(event.workers.result, async () => {
await recorder.add(() => {
const recordedTests = getRecordFoldersWithDetails(reportDir)
generateRecordsHtml(recordedTests)
})
})

function getRecordFoldersWithDetails(dirPath) {
let results = {}

try {
const items = fs.readdirSync(dirPath, { withFileTypes: true })

items.forEach((item) => {
if (item.isDirectory() && item.name.startsWith('record_')) {
const recordFolderPath = path.join(dirPath, item.name)
const indexPath = path.join(recordFolderPath, 'index.html')

let name = ''
if (fs.existsSync(indexPath)) {
try {
const htmlContent = fs.readFileSync(indexPath, 'utf-8')
const $ = cheerio.load(htmlContent)
name = $('.navbar-brand').text().trim()
} catch (err) {
console.error(`Error reading index.html in ${recordFolderPath}:`, err.message)
}
}

results[name || 'Unkown'] = `${item.name}/index.html`
}
})
} catch (err) {
console.error(`Error reading directory ${dirPath}:`, err.message)
}

return results
}

function generateRecordsHtml(recordedTests) {
let links = ''

for (const link in recordedTests) {
Expand All @@ -150,7 +193,7 @@ module.exports = function (config) {
output.print(
`${figures.circleFilled} Step-by-step preview: ${colors.white.bold(`file://${reportDir}/records.html`)}`,
)
})
}

async function persistStep(step) {
if (stepNum === -1) return // Ignore steps from BeforeSuite function
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"chai-match-pattern": "1.3.0",
"chai-string": "1.5.0",
"chalk": "4.1.2",
"cheerio": "^1.0.0",
"commander": "11.1.0",
"cross-spawn": "7.0.5",
"css-to-xpath": "0.1.0",
Expand Down Expand Up @@ -134,7 +135,6 @@
"apollo-server-express": "3.13.0",
"chai-as-promised": "7.1.2",
"chai-subset": "1.6.0",
"cheerio": "^1.0.0",
"contributor-faces": "1.1.0",
"documentation": "14.0.3",
"electron": "33.2.1",
Expand Down Expand Up @@ -184,4 +184,4 @@
"strict": false
}
}
}
}

0 comments on commit dd7bf1f

Please sign in to comment.