Skip to content
Merged
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
62 changes: 31 additions & 31 deletions lib/plugin/htmlReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ module.exports = function (config) {
// Method 1: Check retryNum property (most reliable)
if (test.retryNum && test.retryNum > 0) {
testRetryAttempts.set(testId, test.retryNum)
output.print(`HTML Reporter: Retry count detected (retryNum) for ${test.title}, attempts: ${test.retryNum}`)
output.debug(`HTML Reporter: Retry count detected (retryNum) for ${test.title}, attempts: ${test.retryNum}`)
}
// Method 2: Check currentRetry property
else if (test.currentRetry && test.currentRetry > 0) {
testRetryAttempts.set(testId, test.currentRetry)
output.print(`HTML Reporter: Retry count detected (currentRetry) for ${test.title}, attempts: ${test.currentRetry}`)
output.debug(`HTML Reporter: Retry count detected (currentRetry) for ${test.title}, attempts: ${test.currentRetry}`)
}
// Method 3: Check if this is a retried test
else if (test.retriedTest && test.retriedTest()) {
Expand All @@ -119,12 +119,12 @@ module.exports = function (config) {
} else {
testRetryAttempts.set(originalTestId, testRetryAttempts.get(originalTestId) + 1)
}
output.print(`HTML Reporter: Retry detected (retriedTest) for ${originalTest.title}, attempts: ${testRetryAttempts.get(originalTestId)}`)
output.debug(`HTML Reporter: Retry detected (retriedTest) for ${originalTest.title}, attempts: ${testRetryAttempts.get(originalTestId)}`)
}
// Method 4: Check if test has been seen before (indicating a retry)
else if (reportData.tests.some(t => t.id === testId)) {
testRetryAttempts.set(testId, 1) // First retry detected
output.print(`HTML Reporter: Retry detected (duplicate test) for ${test.title}, attempts: 1`)
output.debug(`HTML Reporter: Retry detected (duplicate test) for ${test.title}, attempts: 1`)
}
}
})
Expand Down Expand Up @@ -196,20 +196,20 @@ module.exports = function (config) {
if (test.retryNum && test.retryNum > 0) {
retryAttempts = test.retryNum
testRetryAttempts.set(testId, retryAttempts)
output.print(`HTML Reporter: Late retry detection (retryNum) for ${test.title}, attempts: ${retryAttempts}`)
output.debug(`HTML Reporter: Late retry detection (retryNum) for ${test.title}, attempts: ${retryAttempts}`)
} else if (test.currentRetry && test.currentRetry > 0) {
retryAttempts = test.currentRetry
testRetryAttempts.set(testId, retryAttempts)
output.print(`HTML Reporter: Late retry detection (currentRetry) for ${test.title}, attempts: ${retryAttempts}`)
output.debug(`HTML Reporter: Late retry detection (currentRetry) for ${test.title}, attempts: ${retryAttempts}`)
} else if (test._retries && test._retries > 0) {
retryAttempts = test._retries
testRetryAttempts.set(testId, retryAttempts)
output.print(`HTML Reporter: Late retry detection (_retries) for ${test.title}, attempts: ${retryAttempts}`)
output.debug(`HTML Reporter: Late retry detection (_retries) for ${test.title}, attempts: ${retryAttempts}`)
}
}

// Debug logging
output.print(`HTML Reporter: Test finished - ${test.title}, State: ${test.state}, Retries: ${retryAttempts}`)
output.debug(`HTML Reporter: Test finished - ${test.title}, State: ${test.state}, Retries: ${retryAttempts}`)

// Detect if this is a BDD/Gherkin test
const isBddTest = isBddGherkinTest(test, currentSuite)
Expand All @@ -222,7 +222,7 @@ module.exports = function (config) {
const currentlyFailed = test.state === 'failed'

// Debug artifacts collection (but don't process them yet - screenshots may not be ready)
output.print(`HTML Reporter: Test ${test.title} artifacts at test.finished: ${JSON.stringify(test.artifacts)}`)
output.debug(`HTML Reporter: Test ${test.title} artifacts at test.finished: ${JSON.stringify(test.artifacts)}`)

const testData = {
...test,
Expand All @@ -244,11 +244,11 @@ module.exports = function (config) {
if (existingTestIndex >= 0) {
// Update existing test with final result (including failed state)
reportData.tests[existingTestIndex] = testData
output.print(`HTML Reporter: Updated existing test - ${test.title}, Final state: ${test.state}`)
output.debug(`HTML Reporter: Updated existing test - ${test.title}, Final state: ${test.state}`)
} else {
// Add new test
reportData.tests.push(testData)
output.print(`HTML Reporter: Added new test - ${test.title}, State: ${test.state}`)
output.debug(`HTML Reporter: Added new test - ${test.title}, State: ${test.state}`)
}

// Track retry information - only add if there were actual retries AND the test failed at some point
Expand All @@ -262,7 +262,7 @@ module.exports = function (config) {
if (retryAttempts === 0 && existingRetryIndex >= 0) {
retryAttempts = reportData.retries[existingRetryIndex].attempts + 1
testRetryAttempts.set(testId, retryAttempts)
output.print(`HTML Reporter: Incremented retry count for duplicate test ${test.title}, attempts: ${retryAttempts}`)
output.debug(`HTML Reporter: Incremented retry count for duplicate test ${test.title}, attempts: ${retryAttempts}`)
}

// Remove existing retry info for this test and add updated one
Expand All @@ -274,7 +274,7 @@ module.exports = function (config) {
finalState: test.state,
duration: test.duration || 0,
})
output.print(`HTML Reporter: Added retry info for ${test.title}, attempts: ${retryAttempts}, state: ${test.state}`)
output.debug(`HTML Reporter: Added retry info for ${test.title}, attempts: ${retryAttempts}, state: ${test.state}`)
}

// Fallback: If this test already exists and either failed before or is failing now, it's a retry
Expand All @@ -288,7 +288,7 @@ module.exports = function (config) {
finalState: test.state,
duration: test.duration || 0,
})
output.print(`HTML Reporter: Fallback retry detection for failed test ${test.title}, attempts: ${fallbackAttempts}`)
output.debug(`HTML Reporter: Fallback retry detection for failed test ${test.title}, attempts: ${fallbackAttempts}`)
}
})

Expand All @@ -298,40 +298,40 @@ module.exports = function (config) {
reportData.duration = reportData.endTime - reportData.startTime

// Process artifacts now that all async tasks (including screenshots) are complete
output.print(`HTML Reporter: Processing artifacts for ${reportData.tests.length} tests after all async tasks complete`)
output.debug(`HTML Reporter: Processing artifacts for ${reportData.tests.length} tests after all async tasks complete`)

reportData.tests.forEach(test => {
const originalArtifacts = test.artifacts
let collectedArtifacts = []

output.print(`HTML Reporter: Processing test "${test.title}" (ID: ${test.id})`)
output.print(`HTML Reporter: Test ${test.title} final artifacts: ${JSON.stringify(originalArtifacts)}`)
output.debug(`HTML Reporter: Processing test "${test.title}" (ID: ${test.id})`)
output.debug(`HTML Reporter: Test ${test.title} final artifacts: ${JSON.stringify(originalArtifacts)}`)

if (originalArtifacts) {
if (Array.isArray(originalArtifacts)) {
collectedArtifacts = originalArtifacts
output.print(`HTML Reporter: Using array artifacts: ${collectedArtifacts.length} items`)
output.debug(`HTML Reporter: Using array artifacts: ${collectedArtifacts.length} items`)
} else if (typeof originalArtifacts === 'object') {
// Convert object properties to array (screenshotOnFail plugin format)
collectedArtifacts = Object.values(originalArtifacts).filter(artifact => artifact)
output.print(`HTML Reporter: Converted artifacts object to array: ${collectedArtifacts.length} items`)
output.print(`HTML Reporter: Converted artifacts: ${JSON.stringify(collectedArtifacts)}`)
output.debug(`HTML Reporter: Converted artifacts object to array: ${collectedArtifacts.length} items`)
output.debug(`HTML Reporter: Converted artifacts: ${JSON.stringify(collectedArtifacts)}`)
}
}

// Only use filesystem fallback if no artifacts found from screenshotOnFail plugin
if (collectedArtifacts.length === 0 && test.state === 'failed') {
output.print(`HTML Reporter: No artifacts from plugin, trying filesystem for test "${test.title}"`)
output.debug(`HTML Reporter: No artifacts from plugin, trying filesystem for test "${test.title}"`)
collectedArtifacts = collectScreenshotsFromFilesystem(test, test.id)
output.print(`HTML Reporter: Collected ${collectedArtifacts.length} screenshots from filesystem for failed test "${test.title}"`)
output.debug(`HTML Reporter: Collected ${collectedArtifacts.length} screenshots from filesystem for failed test "${test.title}"`)
if (collectedArtifacts.length > 0) {
output.print(`HTML Reporter: Filesystem screenshots for "${test.title}": ${JSON.stringify(collectedArtifacts)}`)
output.debug(`HTML Reporter: Filesystem screenshots for "${test.title}": ${JSON.stringify(collectedArtifacts)}`)
}
}

// Update test with processed artifacts
test.artifacts = collectedArtifacts
output.print(`HTML Reporter: Final artifacts for "${test.title}": ${JSON.stringify(test.artifacts)}`)
output.debug(`HTML Reporter: Final artifacts for "${test.title}": ${JSON.stringify(test.artifacts)}`)
})

// Calculate stats from our collected test data instead of using result.stats
Expand Down Expand Up @@ -384,19 +384,19 @@ module.exports = function (config) {
}

// Debug logging for final stats
output.print(`HTML Reporter: Calculated stats - Tests: ${reportData.stats.tests}, Passes: ${reportData.stats.passes}, Failures: ${reportData.stats.failures}`)
output.print(`HTML Reporter: Collected ${reportData.tests.length} tests in reportData`)
output.print(`HTML Reporter: Failures array has ${reportData.failures.length} items`)
output.print(`HTML Reporter: Retries array has ${reportData.retries.length} items`)
output.print(`HTML Reporter: testRetryAttempts Map size: ${testRetryAttempts.size}`)
output.debug(`HTML Reporter: Calculated stats - Tests: ${reportData.stats.tests}, Passes: ${reportData.stats.passes}, Failures: ${reportData.stats.failures}`)
output.debug(`HTML Reporter: Collected ${reportData.tests.length} tests in reportData`)
output.debug(`HTML Reporter: Failures array has ${reportData.failures.length} items`)
output.debug(`HTML Reporter: Retries array has ${reportData.retries.length} items`)
output.debug(`HTML Reporter: testRetryAttempts Map size: ${testRetryAttempts.size}`)

// Log retry attempts map contents
for (const [testId, attempts] of testRetryAttempts.entries()) {
output.print(`HTML Reporter: testRetryAttempts - ${testId}: ${attempts} attempts`)
output.debug(`HTML Reporter: testRetryAttempts - ${testId}: ${attempts} attempts`)
}

reportData.tests.forEach(test => {
output.print(`HTML Reporter: Test in reportData - ${test.title}, State: ${test.state}, Retries: ${test.retryAttempts}`)
output.debug(`HTML Reporter: Test in reportData - ${test.title}, State: ${test.state}, Retries: ${test.retryAttempts}`)
})

// Check if running with workers
Expand Down
Loading