Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(stepByStepReport): no records html is generated when running with run-workers #4638

Merged
merged 2 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
}
}
Loading