-
Notifications
You must be signed in to change notification settings - Fork 30k
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
test_runner: changing spec from class to function #48208
Conversation
Review requested:
|
…11/node into making-specReporter-functional
I see there is another PR #48202 which fixes this by changing the reporters.js file where the |
@@ -35,114 +35,116 @@ const symbols = { | |||
'arrow:right': '\u25B6 ', | |||
'hyphen:minus': '\uFE63 ', | |||
}; | |||
class SpecReporter extends Transform { |
There was a problem hiding this comment.
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?
node/lib/internal/test_runner/utils.js
Lines 142 to 144 in c462147
if (reporter?.prototype && ObjectGetOwnPropertyDescriptor(reporter.prototype, 'constructor')) { | |
reporter = new reporter(); | |
} |
The docs do not show passing a constructor as an option...
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 = []; |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense 👍🏻 will change
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Is this still being worked on, or can this be closed? |
No follow up. Closing. Feel free to reopen if you want to pick this back up though. |
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>
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>
Fixes: #48112
The reporters module currently exports three items:
tap
,dot
, andspec
. However, while tap and dot are functional exports, spec is implemented as a class, requiring the use of thenew
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.