测试报告器


🌐 Test reporters

node:test 模块支持传递 --test-reporter 标志,以便测试运行器使用特定的报告器。

🌐 The node:test module supports passing --test-reporter flags for the test runner to use a specific reporter.

支持以下内置报告器:

🌐 The following built-reporters are supported:

  • tap tap 报告器以 轻拍 格式输出测试结果。
  • spec spec 报告器以人类可读的格式输出测试结果。
  • dot dot 报告器以简洁的格式输出测试结果,其中每个通过的测试用 . 表示,每个失败的测试用 X 表示。
  • junit junit 报告器以 jUnit XML 格式输出测试结果

stdout文字电话 时,默认使用 spec 报告器。否则,默认使用 tap 报告器。

🌐 When stdout is a TTY, the spec reporter is used by default. Otherwise, the tap reporter is used by default.

可以通过 node:test/reporters 模块使用这些 reporters:

🌐 The reporters are available via the node:test/reporters module:

import { tap, spec, dot, junit } from 'node:test/reporters';const { tap, spec, dot, junit } = require('node:test/reporters');