测试报告器


¥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:

  • spec spec 报告器以人类可读的格式输出测试结果。这是默认报告器。

    ¥spec The spec reporter outputs the test results in a human-readable format. This is the default reporter.

  • tap tap 报告器以 TAP 格式输出测试结果。

    ¥tap The tap reporter outputs the test results in the TAP format.

  • dot dot 报告器以紧凑格式输出测试结果,其中每个通过的测试用 . 表示,每个失败的测试用 X 表示。

    ¥dot The dot reporter outputs the test results in a compact format, where each passing test is represented by a ., and each failing test is represented by a X.

  • junit junit 报告器以 jUnit XML 格式输出测试结果

    ¥junit The junit reporter outputs test results in a jUnit XML format

  • lcov--experimental-test-coverage 标志一起使用时,lcov 报告器会输出测试覆盖率。

    ¥lcov The lcov reporter outputs test coverage when used with the --experimental-test-coverage flag.

这些报告器的确切输出可能会因 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 模块获得:

¥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');