Skip to content

Test runner run docs example will always exit with exit code 0 #48752

Description

@Filipoliko

Affected URL(s)

https://nodejs.org/api/test.html#runoptions

Description of the problem

Implementing run function from node:test module as described in docs will lead to incorrect exit code handling for failing tests.

Example from doc:

// runner.mjsimport{run}from'node:test';importpathfrom'node:path';import{tap}from'node:test/reporters';importprocessfrom'node:process';run({files: [path.resolve('./tests/test.mjs')]}).compose(tap).pipe(process.stdout);// ./tests/test.mjsimport{test}from'node:test';test('test',()=>{throw'error';})

Running node runner.mjs will lead to following output.

TAP version 13
# Subtest: test
not ok 1 - test
---
duration_ms: 0.614625
failureType: 'testCodeFailure'
error: 'error'
code: 'ERR_TEST_FAILURE'
...
1..1
# tests 1
# suites 0
# pass 0
# fail 1
# cancelled 0
# skipped 0
# todo 0
# duration_ms 56.791208

with exit code 0, but since the test failed, it should be 1.

Running node --test --test-reporter=tap ./tests/test.mjs leads to same output, but exit code 1 as expected.

I am not sure if this is a docs issue, or an actual bug, but I wasn't able to figure out, how to handle exit code when implementing test runner programmatically. If there is a way, could somebody please elaborate on how to do this? And maybe even update the documentation in case somebody else runs into the same issue?

Thanks in advance for any answers :)

MacOS 13.4.1
Node.js 20.4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to Node.js documentation.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