context.log(message[, data])


  • message <string> 要报告的信息。
  • data <any> 可选的结构化负载附加到消息上。测试运行器会原样传递它。当测试在进程隔离下运行时,该值必须与 HTML 结构化克隆算法 兼容。

这个函数用来向输出写入日志信息。与 context.diagnostic 不同,生成的 'test:log' 事件会立即发出,按测试执行的顺序,而不是等到测试报告结果时才缓冲。这个函数没有返回值。

🌐 This function is used to write a log message to the output. Unlike context.diagnostic, the resulting 'test:log' event is emitted immediately, in the order that the tests execute, rather than being buffered until the test reports its results. This function does not return a value.

test('top level test', (t) => {
  t.log('fetched user', { userId: 42 });
  t.log('retrying flaky endpoint', { attempt: 3 });
});