@bifravst/bdd-markdown

中文文档
9.0.5发布于 2026/10/30BSD-3-ClauseTypeScriptES Module构建来源已验证近 30 天下载 1743

Write BDD tests in Markdown.

原始使用文档
文档目录17 节
  1. Idea
  2. History
  3. Examples
  4. Test eventual consistent systems using the Soon keyword
  5. Control feature execution order via dependencies
  6. Running features first and last
  7. Example: running a feature before all others
  8. Example: running a feature after all others:
  9. Skipping features
  10. Example: skipping a feature
  11. Running only specific features
  12. Example: running only a specific feature
  13. Variants
  14. Number placeholders in JSON
  15. Markdown Reporter
  16. Node & NPM
  17. TypeScript 6 and 7

BDD Markdown npm version

Test and Release semantic-release Renovate @commitlint/config-conventional code style: prettier ESLint: TypeScript

Write BDD tests in Markdown.

Idea

Writing BDD tests should be more comfortable than this, so why not use Markdown? It can look like this.

  • it is a well supported document format, many tools like auto-formatters already exist
  • it provide good tools to structure a hierarchical document
  • it has support for embedding source code / JSON payloads, and even tables
  • front matter can be used for feature-level configuration

History

Work on the original BDD e2e feature runner began in 2018, and the project has been proved very useful for testing cloud-native solutions. Read more about the original idea here. However, the implementation had some shortcomings. Especially understanding test results and the way state and retries were handled was not optimal. In addition was the old codebase itself not sufficiently covered with tests. Therefore this project was initiated in 2022, with four years of experience authoring and running tests. With a fresh set of eyes, the way to write test was complete changed from Gherkin to Markdown which called for releasing it as a standalone project.

Examples

  • Demo of supported syntax
  • Gherkin Rule keyword
  • Mars Rover Kata (this demonstrates the Soon keyword which retries steps)
    Run: $(set -o pipefail && node --no-warnings examples/mars-rover/tests.ts | node --no-warnings reporter/console-cli.ts)
  • Firmware UART log assertions (this demonstrates the use of the Context, which is a global object available to provide run-time settings to the test run, which replace placeholders in step titles and codeblocks.)
    Run: $(set -o pipefail && node --no-warnings examples/firmware/tests.ts | node --no-warnings reporter/console-cli.ts)

Test eventual consistent systems using the Soon keyword

Let's have a look at this scenario:

# To Do List

## Create a new todo list item

Given I create a new task named `My item`

Then the list of tasks should contain `My item`

What if you are testing a todo list system, that is eventually consistent?

More specifically: creating a new task happens through a POST request to an API that returns a 202 Accepted status code.

The system does not guarantee that task you've just created is immediately available.

The Then assertion will fail, because it is executed immediately.

For testing eventual consistent systems, we need to either wait a reasonable enough time or retry the assertion.

However, if there are many similar assertions in your test suite will quickly add up to long run times.

Therefore the most efficient solution is to retry the assertion until it passes, or times out. This way a back-off algorithm can be used to wait increasing longer times and many tries during the test run will have the least amount of impact on the run time.

Implementing the appropriate way of retrying is left to the implementing step, however you are encourage to mark these eventual consisted steps using the Soon keyword.

Control feature execution order via dependencies

By default the features are loaded in no particular order. You may attempt to order them using a naming convention, however this can enforce a forced ranking of all features, and over time files might need to get renamed to make room for new features.

In this project, features can specify a dependency to one or more other features in their front matter, and after parsing all features files, they will be sorted topologically.

Features can define their dependencies via the needs keyword:

---
needs:
  - First feature
---

# Second

## Scenario

Given this is the first step

This feature will be run after a feature with the name First feature

Running features first and last

In addition, features can specify whether they should be run before all other features, or after all. Multiple keywords can have this flag, but dependencies will take precedence.

Example: running a feature before all others

---
order: first
---

# Runs before all others

## Scenario

Given this is the first step

Example: running a feature after all others:

---
order: last
---

# Runs before all others

## Scenario

Given this is the first step

Skipping features

Features can be skipped, this will also skip all dependent and transiently dependent features.

Example: skipping a feature

---
run: never
---

# This feature never runs

## Scenario

Given this is the first step

Running only specific features

Features can be run exclusively, this will also run all dependent and transiently dependent features. All other features not marked as run: only will be skipped.

Example: running only a specific feature

---
run: only
---

# This feature runs, all other features are skipped

## Scenario

Given this is the first step

Variants

Variants (defined in the frontmatter of a feature) can be used to run the same feature in different variants. For every entry in variants, the feature file is run. (Example)

Number placeholders in JSON

For JSON code-blocks there is a special notation to replace number placeholders, while still maintaining the JSON syntax and allow for formatters like prettier to format the code-block.

Given `v` is the number `42`

And I store this in `result`

```json
{ "foo": "$number{v}" }
```

Then `result` should match

```json
{ "foo": 42 }
```

Markdown Reporter

It includes a markdown reporter, which will turn the suite result into markdown, suitable for displaying it as GitHub Actions job summaries.

Example: Mars Rover Report

Node & NPM

This project requires Node.js >=24.19.0 <25 and npm >=12.0.2 <13 (enforced via check-node-version on npm install and npm ci).

The check is skipped during npm publish and npm pack, because semantic-release bundles its own npm (@semantic-release/npm depends on npm@^11.6.2) and runs the publish with that version rather than the one installed in CI.

TypeScript 6 and 7

This repo runs TypeScript 6 and 7 side by side, so that eslint works.

版本与发布记录

@bifravst/bdd-markdown 共发布 87 个版本,首次发布于 2024/07/13;过去 12 个月发布了 12 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
9.0.5latest2026/10/3010 天前
9.0.42026/10/011 个月前
9.0.32026/09/151 个月前
9.0.22026/08/192 个月前
9.0.12026/08/172 个月前
16.3.0-dev.4dev2026/08/172 个月前

关于 @bifravst/bdd-markdown 的常见问题

@bifravst/bdd-markdown 是什么?

Write BDD tests in Markdown.

如何安装 @bifravst/bdd-markdown?

在项目目录运行 npm install @bifravst/bdd-markdown,或使用 pnpm add / yarn add / bun add。

@bifravst/bdd-markdown 支持 TypeScript 吗?

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

@bifravst/bdd-markdown 支持 ESM 还是 CommonJS?

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

@bifravst/bdd-markdown 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24.22.1 <25 || >=26.12.1 <27。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@bifravst/bdd-markdown 可以商用吗?

@bifravst/bdd-markdown 使用 BSD-3-Clause 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。另外不得用原作者名义为衍生产品背书。以上为概括,不构成法律意见,请以许可原文为准。

@bifravst/bdd-markdown 的下载量有多少?

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

@bifravst/bdd-markdown 还在维护吗?

最新版本 9.0.5 发布于 2026/10/30(10 天前);至今共发布 87 个版本,其中过去 12 个月发布了 12 个;首次发布于 2024/07/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。