Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node:test always throws a "passed a callback but also returned a promise" error if async function used with context #47069

Closed
Twipped opened this issue Mar 13, 2023 · 2 comments
Labels
test_runner Issues and PRs related to the test runner subsystem.

Comments

@Twipped
Copy link

Twipped commented Mar 13, 2023

Version

18.15.0 (also affects the userland "test" module in 16.16)

Platform

Darwin J1.local 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 arm64

Subsystem

test_harness

What steps will reproduce the bug?

const { describe, it } = require('node:test');
const assert = require('assert');
describe('thing', () => {
  it('subthing', async (t) => {
    // always throws "passed a callback but also returned a Promise"
    assert(true);
  });
});

CodeSandbox Demo

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

Always.

What is the expected behavior?

I expect the test to run.

What do you see instead?

If you remove the t argument, the test works, but with t present the test always throws with ERR_TEST_FAILURE and a message of passed a callback but also returned a Promise.

TAP version 13
# Subtest: thing
    # Subtest: subthing
    not ok 1 - subthing
      ---
      duration_ms: 0.248708
      failureType: 'callbackAndPromisePresent'
      error: 'passed a callback but also returned a Promise'
      code: 'ERR_TEST_FAILURE'
      stack: |-
        new Promise (<anonymous>)
        Array.map (<anonymous>)
        new Promise (<anonymous>)
      ...
    1..1
not ok 1 - thing
  ---
  duration_ms: 1.341708
  failureType: 'subtestsFailed'
  error: '1 subtest failed'
  code: 'ERR_TEST_FAILURE'
  ...

Additional information

I think this might be an off by one error? If I remove the - 1 from this line, the test works as expected.

@marco-ippolito marco-ippolito added the test_runner Issues and PRs related to the test runner subsystem. label Mar 13, 2023
@cjihrig
Copy link
Contributor

cjihrig commented Mar 13, 2023

This appears to be fixed on main.

@MoLow
Copy link
Member

MoLow commented Mar 13, 2023

it used to have no t parameter so that was actually a callback never called.
however, this behavior has changed at #46889 to avoid such confusions

@MoLow MoLow closed this as completed Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test_runner Issues and PRs related to the test runner subsystem.
Projects
None yet
Development

No branches or pull requests

4 participants