A WebdriverIO plugin to report in spec style
npx @tessl/cli install tessl/npm-wdio--spec-reporter@9.19.0WDIO Spec Reporter is a WebdriverIO plugin that provides spec-style test reporting with hierarchical output similar to Mocha and Jasmine. The reporter formats test results in a clean, readable format with customizable symbols, colors, and advanced features like realtime reporting, console log integration, failure-only modes, and Sauce Labs integration.
npm install @wdio/spec-reporter --save-devimport SpecReporter from "@wdio/spec-reporter";For CommonJS:
const SpecReporter = require("@wdio/spec-reporter").default;Import types:
import type { SpecReporterOptions, Symbols, State } from "@wdio/spec-reporter";// wdio.conf.js
export const config = {
reporters: [
'dot',
['spec', {
sauceLabsSharableLinks: true,
symbols: {
passed: '✓',
failed: '✖'
},
onlyFailures: false,
addConsoleLogs: true,
realtimeReporting: false,
showPreface: true,
color: true
}]
]
};
// Programmatic usage
import SpecReporter from "@wdio/spec-reporter";
const reporter = new SpecReporter({
symbols: { passed: '[PASS]', failed: '[FAIL]' },
onlyFailures: false,
color: true
});WDIO Spec Reporter is built around several key components:
Core configuration options for customizing reporter behavior, output formatting, and integration features.
interface SpecReporterOptions {
/** Enable/disable Sauce Labs sharable links */
sauceLabsSharableLinks?: boolean;
/** Custom symbols for test states */
symbols?: Partial<Symbols>;
/** Show only failed test results */
onlyFailures?: boolean;
/** Include console logs in report */
addConsoleLogs?: boolean;
/** Enable real-time test status output */
realtimeReporting?: boolean;
/** Show/hide preface on each line */
showPreface?: boolean;
/** Enable/disable colored terminal output */
color?: boolean;
}Event-driven lifecycle methods that handle WebdriverIO test execution events and update reporter state.
class SpecReporter extends WDIOReporter {
/** Handle test runner start event */
onRunnerStart(runner: RunnerStats): void;
/** Handle test runner end event */
onRunnerEnd(runner: RunnerStats): void;
/** Handle suite start event */
onSuiteStart(suite: SuiteStats): void;
/** Handle suite end event */
onSuiteEnd(): void;
/** Handle suite retry event */
onSuiteRetry(): void;
/** Handle test start event */
onTestStart(): void;
/** Handle test pass event */
onTestPass(testStat: TestStats): void;
/** Handle test failure event */
onTestFail(testStat: TestStats): void;
/** Handle test skip event */
onTestSkip(testStat: TestStats): void;
/** Handle test pending event */
onTestPending(testStat: TestStats): void;
/** Handle hook end event */
onHookEnd(hook: HookStats): void;
}Methods for generating formatted test reports with customizable display options and color schemes.
class SpecReporter {
/** Print complete test report to stdout */
printReport(runner: RunnerStats): void;
/** Print real-time test status during execution */
printCurrentStats(stat: TestStats | HookStats | SuiteStats): void;
/** Apply color formatting to messages */
setMessageColor(message: string, state?: State): string;
/** Get formatted test results display */
getResultDisplay(prefaceString?: string): string[];
/** Get formatted test count summary */
getCountDisplay(duration: string): string[];
/** Get detailed failure display with stack traces */
getFailureDisplay(): string[];
/** Get formatted header information */
getHeaderDisplay(runner: RunnerStats): string[];
/** Get events to report from a suite */
getEventsToReport(suite: SuiteStats): (HookStats | TestStats)[];
/** Get suites in execution order */
getOrderedSuites(): SuiteStats[];
/** Calculate indentation for nested suites */
indent(uid: string): string;
/** Get symbol for test state */
getSymbol(state?: keyof Symbols): string;
/** Get color name for test state */
getColor(state?: string): ChalkColors;
/** Format browser and environment information */
getEnviromentCombo(capability: Capabilities.ResolvedTestrunnerCapabilities, verbose?: boolean, isMultiremote?: boolean): string;
}Advanced integration features for Sauce Labs test execution including job link generation and authentication.
interface TestLink {
capabilities: Capabilities.ResolvedTestrunnerCapabilities;
sessionId: string;
isMultiremote: boolean;
instanceName?: string;
}
class SpecReporter {
/** Generate Sauce Labs job URLs */
getTestLink(options: TestLink): string[];
}interface Symbols {
passed: string;
skipped: string;
pending: string;
failed: string;
retried: string;
}
interface StateCount {
passed: number;
failed: number;
skipped: number;
pending: number;
retried: number;
}
enum State {
FAILED = 'failed',
PASSED = 'passed',
PENDING = 'pending',
SKIPPED = 'skipped',
RETRIED = 'retried'
}
enum ChalkColors {
RED = 'red',
GREEN = 'green',
CYAN = 'cyan',
GRAY = 'gray',
GREY = 'grey',
BLACCK = 'black',
YELLOW = 'yellow',
BLUE = 'blue',
MAGENTA = 'magenta',
WHITE = 'white'
}