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

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

Closed
nohehf opened this issue Jun 28, 2023 · 5 comments
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs. test_runner Issues and PRs related to the test runner subsystem.

Comments

@nohehf
Copy link

nohehf commented Jun 28, 2023

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

@targos
Copy link
Member

targos commented Jun 28, 2023

I think it's a duplicate of #48112

@atlowChemi
Copy link
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);

@atlowChemi atlowChemi added duplicate Issues and PRs that are duplicates of other issues or PRs. test_runner Issues and PRs related to the test runner subsystem. labels Jun 28, 2023
@nohehf
Copy link
Author

nohehf commented Jun 29, 2023

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.

@atlowChemi
Copy link
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

@atlowChemi
Copy link
Member

Closing as we agreed this is a duplicate 🙂

@atlowChemi atlowChemi closed this as not planned Won't fix, can't repro, duplicate, stale Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs. test_runner Issues and PRs related to the test runner subsystem.
Projects
None yet
Development

No branches or pull requests

3 participants