context.runOnly(shouldRunOnlyTests)


  • shouldRunOnlyTests <boolean> 是否运行 only 测试。

如果 shouldRunOnlyTests 为真,则测试上下文将只运行设置了 only 选项的测试。 否则,将运行所有测试。 如果 Node.js 不是使用 --test-only 命令行选项启动的,则此函数是无操作的。

test('top level test', (t) => {
  // 可以将测试上下文设置为使用 'only' 选项运行子测试。
  t.runOnly(true);
  return Promise.all([
    t.test('this subtest is now skipped'),
    t.test('this subtest is run', { only: true }),
  ]);
});
  • shouldRunOnlyTests <boolean> Whether or not to run only tests.

If shouldRunOnlyTests is truthy, the test context will only run tests that have the only option set. Otherwise, all tests are run. If Node.js was not started with the --test-only command-line option, this function is a no-op.

test('top level test', (t) => {
  // The test context can be set to run subtests with the 'only' option.
  t.runOnly(true);
  return Promise.all([
    t.test('this subtest is now skipped'),
    t.test('this subtest is run', { only: true }),
  ]);
});