Skip to content

Programmatically using the spec reporter from node:test/reporters doesn't output anything. #48585

Description

@nohehf

Version

v20.3.0

Platform

Darwin mbp-nohehf.local 22.5.0 Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000 arm64

Subsystem

No response

What steps will reproduce the bug?

Having the following minimal reproduction files:

// index.js
import { run } from "node:test";
import process from "node:process";
import { spec } from "node:test/reporters";

run({
  files: ["./test.js"],
})
  .compose(spec)
  .pipe(process.stdout);
// test.js
import { it } from "node:test";
import assert from "node:assert";

it("should work", () => {
  assert.equal(1, 1);
});

Running test.js file via the cli using node --test test.js outputs (as expected):
image

Running test.js file programmatically via index.js, using node index.js outputs nothing and exits with status code 1.
image

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

No response

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

Using spec reporter should work programmatically, as tap reporter does.

What do you see instead?

Using spec reporter programmatically outputs nothing and exits with status code 1.

Additional information

No response

Activity

  1. targos commented on Jun 28, 2023

    @targos
    Member

    I think it's a duplicate of #48112

  2. atlowChemi commented on Jun 28, 2023

    @atlowChemi
    Member

    Yup 🙂
    @nohehf the TL;DR is that spec is a class and need to be instantiated for this to work:

    // index.js
    import { run } from "node:test";
    import process from "node:process";
    import { spec } from "node:test/reporters";
    
    run({
      files: ["./test.js"],
    })
    -  .compose(spec)
    +  .compose(new spec())
      .pipe(process.stdout);
  3. added
    duplicateIssues and PRs that are duplicates of other issues or PRs.
    test_runnerIssues and PRs related to the test runner subsystem.
    on Jun 28, 2023
  4. nohehf commented on Jun 29, 2023

    @nohehf
    Author

    Oh thank you. I can open a PR for this in the docs if you want.
    PS: sorry I missed the other issue, I did a research but didn't find it.

  5. atlowChemi commented on Jun 30, 2023

    @atlowChemi
    Member

    Oh thank you. I can open a PR for this in the docs if you want. PS: sorry I missed the other issue, I did a research but didn't find it.

    I am not sure about opening a PR to fix the docs, as there are already 2 PRs (both seem inactive for a while) to expose spec as a function: #48202, #48208

  6. atlowChemi commented on Jul 6, 2023

    @atlowChemi
    Member

    Closing as we agreed this is a duplicate 🙂

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

    duplicateIssues and PRs that are duplicates of other issues or PRs.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