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

Specify that spec reporter is a class and needs to be instantiate for usage with run #48112

Closed
sushantdhiman opened this issue May 22, 2023 · 18 comments · Fixed by #49184
Closed
Labels
doc Issues and PRs related to the documentations. good first issue Issues that are suitable for first-time contributors. test_runner Issues and PRs related to the test runner subsystem.

Comments

@sushantdhiman
Copy link

Affected URL(s)

https://nodejs.org/api/test.html#test-reporters

Description of the problem

When importing spec test reporter, you need to instantiate it otherwise you will get no output, for example

import { run } from "node:test";
import { tap, spec } from "node:test/reporters";
import { resolve } from "path";

const files = [resolve("./test/test.js")];

run({
  files,
  concurrency: 1,
  timeout: 10000,
})
 --- .compose(spec)
+++.compose(new spec())
  .pipe(process.stdout);

Documentation should indicate that spec reporter is exported as a class unlike tap and dot reporters.

@sushantdhiman sushantdhiman added the doc Issues and PRs related to the documentations. label May 22, 2023
@MoLow
Copy link
Member

MoLow commented May 22, 2023

are you interested in opening a PR for this?

@sushantdhiman
Copy link
Author

Not sure how to get started with PR @MoLow

But I think we also need to discuss if api (and behavior) of all test/reporters exports is correct. Ideally all exported reporters should work in same manner? There should be no need to do new spec().

@MoLow
Copy link
Member

MoLow commented May 22, 2023

But I think we also need to discuss if api (and behavior) of all test/reporters exports is correct. Ideally all exported reporters should work in same manner? There should be no need to do new spec().

why?

@sushantdhiman
Copy link
Author

node:test/reporters has three exports currently, spec, tap and dot (may be more in the future). Two of them can be used directly, but spec needs be instantiate. If you ask me this is an odd api, ideally spec should work directly.

But it is just a matter of preference. I have reported oddity with the API docs, it is up to the maintainers how they wish to fix this :)

@aduh95 aduh95 added the test_runner Issues and PRs related to the test runner subsystem. label May 23, 2023
@aduh95
Copy link
Contributor

aduh95 commented May 23, 2023

All lowercase name usually means a function, classes would typically use PascalCase. I agree this is odd, we should fix it either by renaming it and deprecating the old name, or replace it with a function. The latter has the advantage of being doable without any breaking change (hopefully).

@MoLow MoLow added the good first issue Issues that are suitable for first-time contributors. label May 23, 2023
@shubham9411
Copy link
Contributor

shubham9411 commented May 23, 2023

Hey @MoLow, I see you added good first issue tag to this issue. Can I take this?

@MoLow
Copy link
Member

MoLow commented May 23, 2023

Yeah 👍

@shubham9411
Copy link
Contributor

I am thinking of replacing SpecReporter class with a function, as @aduh95 suggested.

Sumi0 added a commit to Sumi0/node that referenced this issue May 27, 2023
Other reporters (dot, tap) by signature are a function while 'spec' reporter is a ES6 class.

This behaviour of api spec is causing difference in semantics while consumption since it has not been addressed anywhere in the document (it has to be instantiated).

Instead of making changes in the signature of spec.js, i have proposed changes where the 'spec' reporter gets exposed in reporter.js

Fixes: nodejs#48112
Refs: https://github.com/nodejs/node/blob/main/lib/internal/test_runner/reporter/spec.js
Refs: (@line-no:143) https://github.com/nodejs/node/blob/main/lib/internal/test_runner/utils.js
@Sumi0
Copy link

Sumi0 commented May 27, 2023

Hi @MoLow, I was curious to take up this issue.
I checked the codebase thoroughly to see any breaking changes.

They were in two files, according to where we want to make change (signature/ exposure) :

  1. If we make change to reporter/spec.js : (@line-no:143) test_runner/utils.js
  2. If we make change to reporters.js : (@line-no:79) test-runner-run.mjs

So instead of making amends to the original signature of 'spec' reporter, I have made change where it is getting exposed in reporters.js.

Kindly check whether this approach is feasible and correct ?

@shubham9411
Copy link
Contributor

Hi @Sumi0, I didn't see your PR that was opened. Please let me know if I need to close my PR, which changes the spec class to a function.

@Sumi0
Copy link

Sumi0 commented May 27, 2023

That's upon @MoLow and @aduh95 .
My PoV is to not change 'spec' reporter's signature to a function.

@MoLow
Copy link
Member

MoLow commented May 28, 2023

I personally prefer #48202

@Sumi0
Copy link

Sumi0 commented May 30, 2023

I had 2 questions @MoLow, @aduh95 :

  1. How do maintainers come to know that, there is an PR awaiting their approval for CI workflow?
  2. How do you follow this linting guideline --Wrap all other lines at 72 columns (except for long URLs)-- before making a commit from Github GUI ? What's the process to assert this guideline ?

@aduh95
Copy link
Contributor

aduh95 commented May 30, 2023

  1. How do maintainers come to know that, there is an PR awaiting their approval for CI workflow?

There would be a GitHub notification if they are subscribed to that PR (and they would typically be because the bot pings the team "owning" the modified files).

2. How do you follow this linting guideline --Wrap all other lines at 72 columns (except for long URLs)-- before making a commit from Github GUI ? What's the process to assert this guideline ?

You count the chars I guess, and when the line grows larger than 72 chars, you add a line return at the start of the word. If that guideline is not met, the CQ will refuse to land the PR.

@Sumi0
Copy link

Sumi0 commented May 30, 2023

You count the chars I guess, and when the line grows larger than 72 chars, you add a line return at the start of the word. If that guideline is not met, the CQ will refuse to land the PR.

So how should one change the commit message afterwards ?
Since I know, my CI test for my first commit linting failed ..

@MoLow
Copy link
Member

MoLow commented May 30, 2023

git commit --amend allows to edit a commits message and content

@aduh95
Copy link
Contributor

aduh95 commented May 31, 2023

Or you can use git fetch https://github.com/nodejs/node.git && git rebase FETCH_HEAD -i, and there you can replace pick with reword on the first commit. It's also OK if you don't want to fix it yourself, it can be fixed by someone else, but it's of course more convenient for everyone if you are able to do it yourself.

@AryanG210
Copy link

is this issue still open?

atlowChemi added a commit to atlowChemi/node that referenced this issue Aug 15, 2023
atlowChemi added a commit to atlowChemi/node that referenced this issue Aug 15, 2023
atlowChemi added a commit to atlowChemi/node that referenced this issue Aug 15, 2023
atlowChemi added a commit to atlowChemi/node that referenced this issue Aug 16, 2023
nodejs-github-bot pushed a commit that referenced this issue Aug 17, 2023
Fixes: #48112
Ref: #48208
PR-URL: #49184
Refs: #48208
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Moshe Atlow <[email protected]>
UlisesGascon pushed a commit that referenced this issue Sep 10, 2023
Fixes: #48112
Ref: #48208
PR-URL: #49184
Refs: #48208
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Moshe Atlow <[email protected]>
targos pushed a commit that referenced this issue Nov 27, 2023
Fixes: #48112
Ref: #48208
PR-URL: #49184
Refs: #48208
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Moshe Atlow <[email protected]>
sercher added a commit to sercher/graaljs that referenced this issue Apr 25, 2024
sercher added a commit to sercher/graaljs that referenced this issue Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. good first issue Issues that are suitable for first-time contributors. test_runner Issues and PRs related to the test runner subsystem.
Projects
None yet
7 participants
@MoLow @sushantdhiman @aduh95 @shubham9411 @Sumi0 @AryanG210 and others