@@ -3478,6 +3478,10 @@ ordered events, emitted immediately as the tests execute.
34783478| [ ` 'test:fail' ` ] [ ] | [ ` 'test:complete' ` ] [ ] (` details.passed ` is ` false ` ) |
34793479| [ ` 'test:plan' ` ] [ ] | |
34803480| [ ` 'test:diagnostic' ` ] [ ] | |
3481+ | | [ ` 'test:log' ` ] [ ] |
3482+
3483+ [ ` 'test:log' ` ] [ ] is deliberately execution ordered only: it is the live
3484+ counterpart of [ ` 'test:diagnostic' ` ] [ ] 's buffered reporting.
34813485
34823486File scoped and global events are always emitted immediately, in execution
34833487order.
@@ -3747,6 +3751,38 @@ When using process isolation (the default), the test name will be the file path
37473751since the parent runner only knows about file-level tests. When using
37483752` --test-isolation=none ` , the actual test name is shown.
37493753
3754+ ### Event: ` 'test:log' `
3755+
3756+ <!-- YAML
3757+ added: REPLACEME
3758+ -->
3759+
3760+ * ` data ` {Object}
3761+ * ` column ` {number|undefined} The column number where the test is defined, or
3762+ ` undefined ` if the test was run through the REPL.
3763+ * ` data ` {any} The structured payload passed to [ ` context.log ` ] [ ] , or
3764+ ` undefined ` if none was provided. The test runner does not interpret this
3765+ value.
3766+ * ` entryFile ` {string|undefined} The path of the test file that was
3767+ executed as the entry point of the child process that emitted this event.
3768+ Only present when tests run with process isolation. May differ from
3769+ ` file ` when the test is defined in a module imported by the entry file.
3770+ * ` file ` {string|undefined} The path of the test file,
3771+ ` undefined ` if test was run through the REPL.
3772+ * ` line ` {number|undefined} The line number where the test is defined, or
3773+ ` undefined ` if the test was run through the REPL.
3774+ * ` message ` {string} The log message.
3775+ * ` name ` {string} The test name.
3776+ * ` nesting ` {number} The nesting level of the test.
3777+ * ` parentId ` {number|undefined} The ` testId ` of the enclosing test, or
3778+ ` undefined ` for top-level tests.
3779+ * ` testId ` {number} A numeric identifier for the test instance that emitted
3780+ the log message.
3781+
3782+ Emitted when [ ` context.log ` ] [ ] is called. Unlike [ ` 'test:diagnostic' ` ] [ ] ,
3783+ this event is emitted immediately, in the order that the tests execute,
3784+ making it suitable for reporters that render test output unbuffered.
3785+
37503786### Event: ` 'test:pass' `
37513787
37523788* ` data ` {Object}
@@ -4272,6 +4308,29 @@ test('top level test', (t) => {
42724308});
42734309```
42744310
4311+ ### ` context.log(message[, data]) `
4312+
4313+ <!-- YAML
4314+ added: REPLACEME
4315+ -->
4316+
4317+ * ` message ` {string} Message to be reported.
4318+ * ` data ` {any} Optional structured payload attached to the message. The test
4319+ runner passes it through untouched. When tests run with process isolation,
4320+ this value must be compatible with the [ HTML structured clone algorithm] [ ] .
4321+
4322+ This function is used to write a log message to the output. Unlike
4323+ [ ` context.diagnostic ` ] [ ] , the resulting [ ` 'test:log' ` ] [ ] event is emitted
4324+ immediately, in the order that the tests execute, rather than being buffered
4325+ until the test reports its results. This function does not return a value.
4326+
4327+ ``` js
4328+ test (' top level test' , (t ) => {
4329+ t .log (' fetched user' , { userId: 42 });
4330+ t .log (' retrying flaky endpoint' , { attempt: 3 });
4331+ });
4332+ ```
4333+
42754334### ` context.filePath `
42764335
42774336<!-- YAML
@@ -4761,6 +4820,26 @@ test.describe('my suite', (suite) => {
47614820});
47624821```
47634822
4823+ ### ` context.log(message[, data]) `
4824+
4825+ <!-- YAML
4826+ added: REPLACEME
4827+ -->
4828+
4829+ * ` message ` {string} Message to be reported.
4830+ * ` data ` {any} Optional structured payload attached to the message. The test
4831+ runner passes it through untouched.
4832+
4833+ Write a log message to the output. The resulting [ ` 'test:log' ` ] [ ] event is
4834+ emitted immediately, in the order that the tests execute.
4835+
4836+ ``` js
4837+ test .describe (' my suite' , (suite ) => {
4838+ suite .log (' Suite log message' );
4839+ });
4840+ ```
4841+
4842+ [ HTML structured clone algorithm ] : https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
47644843[ TAP ] : https://testanything.org/
47654844[ Test tags ] : #test-tags
47664845[ `'test:complete'` ] : #event-testcomplete
@@ -4770,6 +4849,7 @@ test.describe('my suite', (suite) => {
47704849[ `'test:enqueue'` ] : #event-testenqueue
47714850[ `'test:fail'` ] : #event-testfail
47724851[ `'test:interrupted'` ] : #event-testinterrupted
4852+ [ `'test:log'` ] : #event-testlog
47734853[ `'test:pass'` ] : #event-testpass
47744854[ `'test:plan'` ] : #event-testplan
47754855[ `'test:start'` ] : #event-teststart
@@ -4805,6 +4885,7 @@ test.describe('my suite', (suite) => {
48054885[ `TracingChannel` ] : diagnostics_channel.md#class-tracingchannel
48064886[ `assert.throws` ] : assert.md#assertthrowsfn-error-message
48074887[ `context.diagnostic` ] : #contextdiagnosticmessage
4888+ [ `context.log` ] : #contextlogmessage-data
48084889[ `context.skip` ] : #contextskipmessage
48094890[ `context.tags` ] : #contexttags
48104891[ `context.todo` ] : #contexttodomessage
0 commit comments