context.diagnostic(message[, options])


  • message <any> 一个可结构化克隆的诊断值。使用 CLI 进程隔离时,它还必须支持高级子进程序列化。
  • options <Object>
    • level <string> 要么是 'info',要么是 'warning'。默认: 'info'。
    • detail <any> 额外的可结构化克隆诊断数据。使用 CLI 进程隔离时,它还必须被高级子进程序列化支持。
  • 返回:<undefined>

将与当前基准测试、阶段和样本索引相关的诊断排队。多个诊断会保留调用顺序。它们会在样本回调完成后、该样本的 'bench:sample' 事件之前发出。即使热身样本不会发出,热身诊断也会被发出。在回调失败之前排队的诊断会在失败的 'bench:complete' 事件之前发出,并且它们本身不会导致基准测试失败。如果在回调完成之前超时或中止发生,排队的诊断可能不会被发出。

🌐 Queues a diagnostic associated with the current benchmark, phase, and sample index. Multiple diagnostics preserve call order. They are emitted after the sample callback settles and before that sample's 'bench:sample' event. Warmup diagnostics are emitted even though warmup samples are not. Diagnostics queued before a callback failure are emitted before the failed 'bench:complete' event and do not themselves cause the benchmark to fail. If a timeout or abort wins before the callback settles, queued diagnostics might not be emitted.

消息和细节会同步克隆。选项也会同步验证。因此,在 context.start() 和 context.end() 之间调用 diagnostic() 会把这些工作算入测量的时间。无效的参数或者不可克隆的消息或细节会违反示例协议。

🌐 The message and detail are cloned synchronously. Options are also validated synchronously. Calling diagnostic() between context.start() and context.end() therefore includes that work in the measured duration. Invalid arguments or an uncloneable message or detail violate the sample contract.