测试报告器


¥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 报告器以 TAP 格式输出测试结果。

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

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

    ¥spec The spec reporter outputs the test results in a human-readable 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

stdoutTTY 时,默认使用 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 模块获得:

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