Skip to content

test:start events are not emitted correctly #51907

Closed
@connor4312

Description

@connor4312

Version

21.6.2

Platform

windows x64

Subsystem

test_runner

What steps will reproduce the bug?

  1. Have a test file like

test.js

const { describe, it } = require('node:test');
const { strictEqual } = require('node:assert');

describe('math', () => {
  it('addition', async () => {
    await new Promise((resolve) => setTimeout(resolve, 5000));
    strictEqual(1 + 1, 2);
  });

  it(`subtraction`, async () => {
    strictEqual(1 - 1, 0);
  });
});

and a reporter.js

module.exports = async function* reporter(stream) {
  for await (const evt of stream) {
    console.log(new Date().toISOString(), evt.type, evt.data);
  }
};
  1. Run node --test-reporter=./reporter.js test.js

How often does it reproduce? Is there a required condition?

100%

What is the expected behavior? Why is that the expected behavior?

test:start should be fired before math addition is run

What do you see instead?

test:start is fired only after the test finishes. Here's an example log, notice that test:started is fired only after the 5 second delay, which is in fact after the tests already finished.

log.txt

Additional information

I originally requested this in #46727 which resulted in test:queued and test:dequeued events being added. (Maybe this should be titled instead a general "I (still) cannot tell when a test is started")

However these are not useful because the tests are just enqueued event when they're not running: subtraction is enqueued alongside addition and based on the results it 'takes' 5 seconds to run, but in reality is instant.

Metadata

Metadata

Assignees

No one assigned

    Labels

    test_runnerIssues and PRs related to the test runner subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions