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

test_runner: changing spec from class to function #48208

Closed

Conversation

shubham9411
Copy link
Contributor

Fixes: #48112

The reporters module currently exports three items: tap, dot, and spec. However, while tap and dot are functional exports, spec is implemented as a class, requiring the use of the new keyword. This discrepancy can introduce inconsistency and make the usage less streamlined.

This PR aims to update the spec export in the reporters module to a functional implementation, similar to tap and dot.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem. labels May 27, 2023
@shubham9411
Copy link
Contributor Author

I see there is another PR #48202 which fixes this by changing the reporters.js file where the spec api gets exposed. Let me know if this PR needs to be closed.

@aduh95 aduh95 added the semver-major PRs that contain breaking changes and should be released in the next major version. label May 28, 2023
@@ -35,114 +35,116 @@ const symbols = {
'arrow:right': '\u25B6 ',
'hyphen:minus': '\uFE63 ',
};
class SpecReporter extends Transform {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MoLow @cjihrig Do we still want/need this?

if (reporter?.prototype && ObjectGetOwnPropertyDescriptor(reporter.prototype, 'constructor')) {
reporter = new reporter();
}

The docs do not show passing a constructor as an option...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, for custom reporters I guess

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I guess we might want to add an example for that to the docs?

const stack = [];
const reported = [];
const indentMemo = new SafeMap();
const failedTests = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this mean that calling run twice with spec now shares the failures between runs? (whereas previously you could instantiate a new reporter as per need)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would expect const spec to be a function creating these vars and return the new Transform. Does that make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense 👍🏻 will change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @atlowChemi, I have updated the PR with the lates changes. Instead of using the new Transform, I have modified it to an async generator, similar to dot and tap reporters.

constructor() {
super({ writableObjectMode: true });
}
async function* specReporter(source) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want new specReporter to keep working (and I think we do, otherwise it's a breaking change), we cannot use a generator here, it has to be a function specReporter(source), async functions and (async) generators are not "constructable".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just thinking out load, Is it possible to make specReporter function work consistently whether we use new specReporter() or just specReporter? I tried by it but it only works one way, can you suggest anything?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I meant, you need to use function specReporter(source) { /* … */ }, AFAIK it's the only thing is JS that is both callable and constructible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sorry, I got confused, so I did made it like function specReporter(source) { /* … */ } and it works with new spec() and also work as spec(), but does not work standalone like the dot and tap. viz:

run(...).compose(new spec()); // this works
run(...).compose(spec()); // this works
run(...).compose(spec); // this does not work
run(...).compose(tap); // <- tap and dot work like this

the third one above is used like the dot and tap. If spec() is also acceptable, let me know I'll push the change. Or let me know if my understanding is correct or not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you share what's the error you're getting? That would help understand what might be the problem.

@cjihrig
Copy link
Contributor

cjihrig commented Aug 11, 2023

Is this still being worked on, or can this be closed?

@cjihrig
Copy link
Contributor

cjihrig commented Aug 15, 2023

No follow up. Closing. Feel free to reopen if you want to pick this back up though.

@cjihrig cjihrig closed this Aug 15, 2023
atlowChemi added a commit to atlowChemi/node that referenced this pull request Aug 15, 2023
atlowChemi added a commit to atlowChemi/node that referenced this pull request Aug 15, 2023
atlowChemi added a commit to atlowChemi/node that referenced this pull request Aug 15, 2023
atlowChemi added a commit to atlowChemi/node that referenced this pull request Aug 16, 2023
nodejs-github-bot pushed a commit that referenced this pull request Aug 17, 2023
Fixes: #48112
Ref: #48208
PR-URL: #49184
Refs: #48208
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
UlisesGascon pushed a commit that referenced this pull request Sep 10, 2023
Fixes: #48112
Ref: #48208
PR-URL: #49184
Refs: #48208
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
targos pushed a commit that referenced this pull request Nov 27, 2023
Fixes: #48112
Ref: #48208
PR-URL: #49184
Refs: #48208
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
sercher added a commit to sercher/graaljs that referenced this pull request Apr 25, 2024
Fixes: nodejs/node#48112
Ref: nodejs/node#48208
PR-URL: nodejs/node#49184
Refs: nodejs/node#48208
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
sercher added a commit to sercher/graaljs that referenced this pull request Apr 25, 2024
Fixes: nodejs/node#48112
Ref: nodejs/node#48208
PR-URL: nodejs/node#49184
Refs: nodejs/node#48208
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ci PRs that need a full CI run. semver-major PRs that contain breaking changes and should be released in the next major version. test_runner Issues and PRs related to the test runner subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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