@cucumber/pretty-formatter

中文文档
4.1.0发布于 2026/09/27MITTypeScriptES Module构建来源已验证近 30 天下载 631.3万


pretty-formatter

Rich formatting of Cucumber progress and results for the terminal

原始使用文档
文档目录5 节
  1. Usage
  2. SummaryPrinter
  3. ProgressPrinter
  4. PrettyPrinter
  5. Themes


pretty-formatter

Rich formatting of Cucumber progress and results for the terminal

Latest version on npm Build status

Example output of the pretty formatting, showing the different colors used

Usage

This package is used internally in @cucumber/cucumber to provide the summary, progress and pretty formatters; you don't need to install or manage it yourself. For usage, see https://github.com/cucumber/cucumber-js/blob/main/docs/formatters.md.

You can use these low-level classes to provide formatting for a different implementation of Cucumber.

SummaryPrinter

Prints a summary of test results including non-passing scenarios, statistics, and snippets.

import { SummaryPrinter } from '@cucumber/pretty-formatter'

const printer = new SummaryPrinter()

// each time a message is emitted
printer.update(envelope)

Can also be used to summarise a test run that already happened, with a pre-populated Query object:

import { Query } from '@cucumber/query'
import { SummaryPrinter } from '@cucumber/pretty-formatter'

const query = new Query()

// each time a message is emitted
query.update(envelope)

// later
SummaryPrinter.summarise(query)

ProgressPrinter

Prints test progress as single-character status indicators.

import { ProgressPrinter } from '@cucumber/pretty-formatter'

const printer = new ProgressPrinter()

// each time a message is emitted
printer.update(envelope)

PrettyPrinter

Prints test progress in a prettified Gherkin-style format.

import { PrettyPrinter } from '@cucumber/pretty-formatter'

const printer = new PrettyPrinter()

// each time a message is emitted
printer.update(envelope)

Themes

Here's the schema for a theme:

interface Theme {
    attachment?: Style
    dataTable?: {
        all?: Style
        border?: Style
        content?: Style
    }
    docString?: {
        all?: Style
        content?: Style
        delimiter?: Style
        mediaType?: Style
    }
    feature?: {
        all?: Style
        keyword?: Style
        name?: Style
    }
    location?: Style
    rule?: {
        all?: Style
        keyword?: Style
        name?: Style
    }
    scenario?: {
        all?: Style
        keyword?: Style
        name?: Style
    }
    status?: {
        all?: Partial<Record<TestStepResultStatus, Style>>
        icon?: Partial<Record<TestStepResultStatus, string>>
        progress?: Partial<Record<TestStepResultStatus, string>>
    }
    step?: {
        argument?: Style
        keyword?: Style
        text?: Style
    }
    tag?: Style
    symbol?: {
        bullet?: string
    }
}

enum TestStepResultStatus {
    UNKNOWN = "UNKNOWN",
    PASSED = "PASSED",
    SKIPPED = "SKIPPED",
    PENDING = "PENDING",
    UNDEFINED = "UNDEFINED",
    AMBIGUOUS = "AMBIGUOUS",
    FAILED = "FAILED"
}

Style is any Node.js supported modifier or an array of them.

See the default theme for a good example. It's exported as CUCUMBER_THEME, so you can clone and extend it if you'd like.

版本与发布记录

@cucumber/pretty-formatter 共发布 21 个版本,首次发布于 2021/01/08;过去 12 个月发布了 9 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
4.1.0latest2026/09/271 个月前
4.0.22026/09/022 个月前
4.0.12026/08/063 个月前
4.0.02026/06/124 个月前
3.3.12026/05/145 个月前
3.3.02026/05/036 个月前

关于 @cucumber/pretty-formatter 的常见问题

@cucumber/pretty-formatter 是什么?

pretty-formatter Rich formatting of Cucumber progress and results for the terminal

如何安装 @cucumber/pretty-formatter?

在项目目录运行 npm install @cucumber/pretty-formatter,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@cucumber/messages(*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@cucumber/pretty-formatter 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cucumber/pretty-formatter 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@cucumber/pretty-formatter 可以商用吗?

@cucumber/pretty-formatter 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cucumber/pretty-formatter 的下载量有多少?

根据 npm 官方下载统计,@cucumber/pretty-formatter 在 2026/10/11 – 2026/11/09 这 30 天内被下载 6,313,086 次,日均约 210,436 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cucumber/pretty-formatter 还在维护吗?

最新版本 4.1.0 发布于 2026/09/27(1 个月前);至今共发布 21 个版本,其中过去 12 个月发布了 9 个;首次发布于 2021/01/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。