run([options])


  • options <Object> 运行测试的配置选项。支持以下属性:

    ¥options <Object> Configuration options for running tests. The following properties are supported:

    • concurrency <number> | <boolean> 如果提供了一个数字,那么许多测试进程将并行运行,其中每个进程对应一个测试文件。如果是 true,它将并行运行 os.availableParallelism() - 1 个测试文件。如果是 false,它一次只会运行一个测试文件。默认值:false

      ¥concurrency <number> | <boolean> If a number is provided, then that many test processes would run in parallel, where each process corresponds to one test file. If true, it would run os.availableParallelism() - 1 test files in parallel. If false, it would only run one test file at a time. Default: false.

    • files<Array> 包含要运行的文件列表的数组。测试运行器执行模型 中的默认匹配文件。

      ¥files: <Array> An array containing the list of files to run. Default matching files from test runner execution model.

    • inspectPort <number> | <Function> 设置测试子进程的检查器端口。这可以是数字,也可以是不带参数并返回数字的函数。如果提供了一个空值,每个进程都有自己的端口,从主进程的 process.debugPort 递增。默认值:undefined

      ¥inspectPort <number> | <Function> Sets inspector port of test child process. This can be a number, or a function that takes no arguments and returns a number. If a nullish value is provided, each process gets its own port, incremented from the primary's process.debugPort. Default: undefined.

    • only<boolean> 如果为真,测试上下文将仅运行设置了 only 选项的测试

      ¥only: <boolean> If truthy, the test context will only run tests that have the only option set

    • setup <Function> 接受 TestsStream 实例并可用于在运行任何测试之前设置监听器的函数。默认值:undefined

      ¥setup <Function> A function that accepts the TestsStream instance and can be used to setup listeners before any tests are run. Default: undefined.

    • signal <AbortSignal> 允许中止正在进行的测试执行。

      ¥signal <AbortSignal> Allows aborting an in-progress test execution.

    • testNamePatterns <string> | <RegExp> | <Array> 一个字符串、正则表达式或正则表达式数组,可用于仅运行名称与提供的模式匹配的测试。测试名称模式被解释为 JavaScript 正则表达式。对于执行的每个测试,也会运行任何相应的测试钩子,例如 beforeEach()。默认值:undefined

      ¥testNamePatterns <string> | <RegExp> | <Array> A String, RegExp or a RegExp Array, that can be used to only run tests whose name matches the provided pattern. Test name patterns are interpreted as JavaScript regular expressions. For each test that is executed, any corresponding test hooks, such as beforeEach(), are also run. Default: undefined.

    • timeout <number> 测试执行将在几毫秒后失败。如果未指定,则子测试从其父测试继承此值。默认值:Infinity

      ¥timeout <number> A number of milliseconds the test execution will fail after. If unspecified, subtests inherit this value from their parent. Default: Infinity.

    • watch <boolean> 是否以监视模式运行。默认值:false

      ¥watch <boolean> Whether to run in watch mode or not. Default: false.

    • shard <Object> 在特定分片中运行测试。默认值:undefined

      ¥shard <Object> Running tests in a specific shard. Default: undefined.

      • index <number> 是 1 到 <total> 之间的正整数,指定要运行的分片的索引。此选项是必需的。

        ¥index <number> is a positive integer between 1 and <total> that specifies the index of the shard to run. This option is required.

      • total <number> 是一个正整数,指定将测试文件拆分为的分片总数。此选项是必需的。

        ¥total <number> is a positive integer that specifies the total number of shards to split the test files to. This option is required.

  • 返回:<TestsStream>

    ¥Returns: <TestsStream>

import { tap } from 'node:test/reporters';
import process from 'node:process';

run({ files: [path.resolve('./tests/test.js')] })
  .compose(tap)
  .pipe(process.stdout);const { tap } = require('node:test/reporters');

run({ files: [path.resolve('./tests/test.js')] })
  .compose(tap)
  .pipe(process.stdout);