UNPKG

donobu

Version:

Create browser automations with an LLM agent and replay them as Playwright scripts.

79 lines 3.05 kB
"use strict"; /** * @fileoverview Donobu Markdown Reporter for Playwright. * * Writes a Markdown summary of the run to disk. When `$GITHUB_STEP_SUMMARY` * is set (i.e. running inside a GitHub Actions step), the same Markdown is * also written there so the report shows up in the job summary without * needing a separate `cat >> $GITHUB_STEP_SUMMARY` workflow step. Both * writes are truncating, so when auto-heal regenerates the report afterwards * the consolidated version overwrites the initial one. * * @usage * ```ts * // playwright.config.ts * reporter: [ * ['donobu/reporter/markdown', { outputFile: 'test-results/report.md' }], * ], * ``` * * During an auto-heal rerun (`DONOBU_AUTO_HEAL_ACTIVE=1`) the reporter skips * file writes. It always merges its output entry into the shared state file * so the orchestrator knows to regenerate the markdown from the merged report. */ Object.defineProperty(exports, "__esModule", { value: true }); const fs_1 = require("fs"); const path_1 = require("path"); const envVars_1 = require("../envVars"); const Logger_1 = require("../utils/Logger"); const buildReport_1 = require("./buildReport"); const renderMarkdown_1 = require("./renderMarkdown"); const stateFile_1 = require("./stateFile"); class DonobuMarkdownReporter { constructor(options = {}) { this.resultsByTest = new Map(); this.options = options; } onBegin(config, _suite) { this.rootDir = config.rootDir; } onTestEnd(test, result) { const existing = this.resultsByTest.get(test); if (existing) { existing.push(result); } else { this.resultsByTest.set(test, [result]); } } async onEnd(_result) { const outputFile = (0, path_1.resolve)(this.options.outputFile ?? 'test-results/report.md'); const outputDir = (0, path_1.dirname)(outputFile); const autoHealActive = envVars_1.env.data.DONOBU_AUTO_HEAL_ACTIVE === '1'; const report = (0, buildReport_1.buildDonobuReport)(this.resultsByTest, this.rootDir); (0, stateFile_1.mergeStateFileEntry)(envVars_1.env.data.PLAYWRIGHT_JSON_OUTPUT_DIR, report, { markdown: { outputFile }, }); if (autoHealActive) { return; } const markdown = (0, renderMarkdown_1.renderMarkdown)(report); (0, fs_1.mkdirSync)(outputDir, { recursive: true }); (0, fs_1.writeFileSync)(outputFile, markdown, 'utf8'); Logger_1.appLogger.info(`Donobu Markdown report written to ${outputFile}`); const stepSummary = envVars_1.env.data.GITHUB_STEP_SUMMARY; if (stepSummary) { try { (0, fs_1.writeFileSync)(stepSummary, markdown, 'utf8'); } catch (error) { Logger_1.appLogger.warn('Failed to write GitHub Actions step summary.', error); } } } printsToStdio() { return false; } } exports.default = DonobuMarkdownReporter; //# sourceMappingURL=markdown.js.map