import WDIOReporter, { RunnerStats, SuiteStats, TestStats, HookStats, BeforeCommandArgs } from '@wdio/reporter'; import type { Reporters } from '@wdio/types'; import type { CtrfReport, CtrfTest, CtrfEnvironment } from './types'; export interface CtrfReporterOptions extends Reporters.Options { outputDir?: string; outputFile?: string; outputFileStrategy?: 'unique' | 'static'; logLevel?: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent'; captureLogs?: boolean; /** Automatically log meaningful WebDriver/Appium commands (click, setValue, * navigation, etc.) as they happen. Sensitive input values are never logged. */ captureCommands?: boolean; environment?: Partial; tags?: string[]; testType?: string; metadata?: Record; transformTest?: (test: CtrfTest) => CtrfTest | null; onComplete?: (report: CtrfReport, outputPath: string) => void | Promise; } export default class CtrfReporter extends WDIOReporter { private opts; private report; private testMap; private suiteMap; private suiteCount; private currentSuite; private currentSpecFile; private runnerCid; private runnerStartTime; private runnerEndTime; private globalAttachments; private currentGlobalHookBeingProcessed; /** beforeEach hooks awaiting attribution to the test they belong to. `owner` * (from WDIO's `HookStats.currentTest`) pins a hook to a specific test/suite * so a hook for test B never gets attached to test A just because A started * first - WDIO does not guarantee hook:end fires before the next test:start. */ private pendingBeforeEachHooks; private lastStartedTestState; /** Current destination for logs, owned by the reporter (test or hook). Used * both by the in-process log API (via shared.setLogSink) and by the * command-event handlers below, so attribution never depends on the service. */ private activeSink; /** WDIO can emit test and hook lifecycle events in an order where ending a * hook happens after the test sink was installed. Keep explicit owners so a * completed hook restores command/manual-log attribution to its test. */ private activeTestForLogs; private activeHookForLogs; constructor(options: CtrfReporterOptions); onRunnerStart(runner: RunnerStats): void; onSuiteStart(suite: SuiteStats): void; onTestStart(test: TestStats): void; /** Assigns the beforeEach hooks that ran immediately before this test and * marks it as the target for the afterEach hooks that follow. Only hooks * with no known owner (older WDIO without `currentTest`) or whose owner * matches this test are consumed - hooks queued for a different test stay * queued instead of being misattributed. */ private attachPendingHooks; private createTestState; onTestPass(test: TestStats): void; onTestFail(test: TestStats): void; onTestSkip(test: TestStats): void; onTestEnd(test: TestStats): void; private applySharedTestData; onHookStart(hook: HookStats): void; onHookEnd(hook: HookStats): void; onRunnerEnd(_runner: RunnerStats): void; /** Single owner of log attribution. Points both the in-process log API * (shared.setLogSink, used by browser.ctrf.log / CommonUtil.log) and the * command-event handlers at the same test/hook target. */ private routeLogsTo; private routeLogsToTest; /** Single owner of attachment attribution, mirroring `routeLogsTo`. Needed * because `activeTests`/`activeGlobalHooks` (driven by the service) only * cover the test body and before-all/after-all hooks - an attachment added * during a regular beforeEach/afterEach has no service-tracked window to * land in and would otherwise be silently dropped. */ private routeAttachmentsTo; private routeAttachmentsToTest; private routeAttachmentsToHook; /** The test a beforeEach/afterEach hook belongs to, per WDIO's own * `HookStats.currentTest`. Returns null when WDIO doesn't populate it. */ private hookOwner; /** WDIO emits this for every WebDriver/Appium command in-process, correctly * ordered relative to test/hook events. We turn the meaningful ones into * human-readable log lines so a test always has an activity trail — even * when the optional service is not loaded and no manual logs are written. */ onBeforeCommand(command: BeforeCommandArgs): void; /** Translate a raw WebDriver/Appium request into a readable action label. * Returns null for noisy, non-actionable commands (element lookups, polling, * attribute/state reads). Never includes typed text (may be a password). */ private describeCommand; private createEmptyReport; private buildTestKey; private getTestKey; private saveRetryAttempt; private finalizeTest; private buildReport; /** * Apply a service-recorded hook failure (status + message/trace + attachments * such as the failure screenshot) to a hook. The service is the source of * truth for hook pass/fail because the reporter's HookStats frequently lacks * the error. Failures are consumed FIFO from per-type queues so they align * with execution order. */ private applyRecordedHookFailure; private applyRecordedGlobalHookFailures; private normalizeAttachment; private dedupeAttachments; private buildSuiteHierarchy; private writeReport; private resolveOutputPath; private safeFilePart; private getCap; private extractDeviceInfo; private classifyHook; private mapWdioStateToCtrf; private shouldLog; private log; } //# sourceMappingURL=reporter.d.ts.map