Skip to content

Test runner: spurious "Promise resolution is still pending but the event loop has already resolved" when a callback tests fails #51381

Description

@domenic

Version

v21.4.0

Platform

Microsoft Windows NT 10.0.22621.0 x64

Subsystem

test

What steps will reproduce the bug?

Run the following code with node --test test.js:

"use strict";
const { describe, test } = require("node:test");
const assert = require("node:assert");

describe("describe wrapper", () => {
  test("callback test", (t, done) => {
    setTimeout(() => {
      assert.ok(false, "oh no an assert failed");
      done();
    });
  });

  test("promise test", async () => {
    assert.ok(true, "this assert will pass");
  });
});

describe("another describe block", () => {
  test("sync test", () => {
    assert.ok(true, "this assert will pass 2");
  });
});

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

Always

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

It should tell me that "callback test" alone is failing

What do you see instead?

It shows four failure messages: one for callback test (correct), one for describe wrapper, one for sync test, and one for another describe block. The latter three have a (green??) 'Promise resolution is still pending but the event loop has already resolved' failure reason.

$ node --test test.js
▶ describe wrapper
  ✖ callback test (2.4042ms)
    AssertionError [ERR_ASSERTION]: oh no an assert failed
        at Timeout._onTimeout (C:\Users\d\OneDrive - domenic.me\Code\GitHub\jsdom\jsdom\test.js:8:14)
        at listOnTimeout (node:internal/timers:573:17)
        at process.processTimers (node:internal/timers:514:7) {
      generatedMessage: false,
      code: 'ERR_ASSERTION',
      actual: false,
      expected: true,
      operator: '=='
    }

  ✔ promise test (0.2519ms)
▶ describe wrapper (5.4167ms)

  'Promise resolution is still pending but the event loop has already resolved'

▶ another describe block
  ✖ sync test
    'Promise resolution is still pending but the event loop has already resolved'

▶ another describe block

  'Promise resolution is still pending but the event loop has already resolved'

ℹ tests 3
ℹ suites 2
ℹ pass 1
ℹ fail 1
ℹ cancelled 1
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 47.7459

✖ failing tests:

test at test.js:6:3
✖ callback test (2.4042ms)
  AssertionError [ERR_ASSERTION]: oh no an assert failed
      at Timeout._onTimeout (C:\Users\d\OneDrive - domenic.me\Code\GitHub\jsdom\jsdom\test.js:8:14)
      at listOnTimeout (node:internal/timers:573:17)
      at process.processTimers (node:internal/timers:514:7) {
    generatedMessage: false,
    code: 'ERR_ASSERTION',
    actual: false,
    expected: true,
    operator: '=='
  }

test at test.js:5:1
✖ describe wrapper (5.4167ms)
  'Promise resolution is still pending but the event loop has already resolved'

test at test.js:19:3
✖ sync test
  'Promise resolution is still pending but the event loop has already resolved'

test at test.js:18:1
✖ another describe block
  'Promise resolution is still pending but the event loop has already resolved'

Additional information

There isn't a lot of documentation about callback-style tests...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues and PRs for confirmed bugs.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