debug: write fixture log BEFORE guard check to diagnose 0/0 coverage

This commit is contained in:
bymyself
2026-04-07 02:07:32 -07:00
parent 49b1d9b82b
commit bdd375c86b

View File

@@ -412,58 +412,44 @@ export const comfyPageFixture = base.extend<{
collectCoverage: [COLLECT_COVERAGE, { option: true }],
page: async ({ page, collectCoverage, browserName }, use, testInfo) => {
// Debug: ALWAYS write to verify fixture runs, BEFORE guard
const debugDir = require('path').join(
process.cwd(),
'coverage',
'playwright'
)
await fs.mkdir(debugDir, { recursive: true })
await fs.appendFile(
require('path').join(debugDir, 'debug-log.txt'),
`[${new Date().toISOString()}] page fixture called: browser=${browserName} collectCoverage=${collectCoverage} test=${testInfo.title}\n`
)
if (browserName !== 'chromium' || !collectCoverage) {
return use(page)
}
// Debug: write to both stderr and a file to ensure visibility
const debugLog = (msg: string) => process.stderr.write(`[coverage] ${msg}\n`)
debugLog(`page fixture ENTERED for: ${testInfo.title}`)
// Also write a marker file so we can verify the fixture ran
const markerDir = require('path').join(process.cwd(), 'coverage', 'debug')
await fs.mkdir(markerDir, { recursive: true })
await fs.appendFile(
require('path').join(markerDir, 'fixture-log.txt'),
`[${new Date().toISOString()}] page fixture ENTERED for: ${testInfo.title}\n`
)
await page.coverage.startJSCoverage({ resetOnNavigation: false })
await use(page)
const entries = await page.coverage.stopJSCoverage()
const httpEntries = entries.filter((e) => e.url.startsWith('http'))
const withSource = entries.filter(
(e) => typeof e.source === 'string'
).length
debugLog(
`${testInfo.title}: ${entries.length} entries, ${httpEntries.length} HTTP, ${withSource} with source`
)
if (httpEntries.length > 0) {
debugLog(
`Sample URLs: ${httpEntries
.slice(0, 3)
.map((e) => e.url)
.join(', ')}`
)
}
let fetchedCount = 0
for (const entry of entries) {
if (typeof entry.source !== 'string' && entry.url.startsWith('http')) {
try {
const resp = await fetch(entry.url)
if (resp.ok) {
;(entry as Record<string, unknown>).source = await resp.text()
fetchedCount++
} else {
debugLog(`fetch failed ${entry.url}: ${resp.status}`)
}
} catch (err) {
debugLog(`fetch error ${entry.url}: ${err}`)
}
if (resp.ok)
(entry as Record<string, unknown>).source = await resp.text()
} catch {}
}
}
debugLog(`Fetched sources for ${fetchedCount} scripts`)
const httpCount = entries.filter((e) => e.url.startsWith('http')).length
const withSource = entries.filter(
(e) => typeof e.source === 'string'
).length
await fs.appendFile(
require('path').join(debugDir, 'debug-log.txt'),
`[${new Date().toISOString()}] TEARDOWN ${testInfo.title}: entries=${entries.length} http=${httpCount} withSource=${withSource}\n`
)
const resultFile = testInfo.outputPath('v8-coverage.json')
await fs.writeFile(resultFile, JSON.stringify({ result: entries }))
@@ -472,19 +458,6 @@ export const comfyPageFixture = base.extend<{
contentType: 'application/json',
path: resultFile
})
debugLog(`Wrote coverage to ${resultFile}`)
// Also write debug summary to coverage dir for artifact upload
const summaryPath = require('path').join(
process.cwd(),
'coverage',
'playwright',
'debug-log.txt'
)
await fs.mkdir(require('path').dirname(summaryPath), { recursive: true })
await fs.appendFile(
summaryPath,
`[${new Date().toISOString()}] ${testInfo.title}: entries=${entries.length} http=${httpEntries.length} withSource=${withSource} fetched=${fetchedCount} resultFile=${resultFile}\n`
)
},
comfyPage: async ({ page, request }, use, testInfo) => {