Skip to content

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

Description

@Twipped

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');constassert=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 - 1from this line, the test works as expected.

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