测试报告器
【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:】
specspec报告器以人类可读的格式输出测试结果。这是默认的报告器。taptap报告器以 轻拍 格式输出测试结果。dotdot报告器以简洁的格式输出测试结果,其中每个通过的测试用.表示,每个失败的测试用X表示。junitjunit 报告器以 jUnit XML 格式输出测试结果lcov报告器在与--experimental-test-coverage标志一起使用时会输出测试覆盖率。
这些报告器的具体输出可能会因 Node.js 的版本而变化,因此不应在程序中依赖。如果需要以编程方式访问测试运行器的输出,请使用 <TestsStream> 发出的事件。
【The exact output of these reporters is subject to change between versions of Node.js, and should not be relied on programmatically. If programmatic access to the test runner's output is required, use the events emitted by the <TestsStream>.】
可以通过 node:test/reporters 模块使用这些 reporters:
【The reporters are available via the node:test/reporters module:】
import { tap, spec, dot, junit, lcov } from 'node:test/reporters';const { tap, spec, dot, junit, lcov } = require('node:test/reporters');