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: refactor spec reporter to generator function #50177

Closed
wants to merge 3 commits into from

Conversation

himself65
Copy link
Member

@himself65 himself65 commented Oct 13, 2023

Fixes: #50176

Upstream: #48112 #48202

Even if the original code is 100% correct, the spec reporter was a class but the other nodejs internal reporters are all async functions. This will be a little misleading like stream.compose(spec) is incorrect because spec is a class, not a generator.

I think all the internal implementation should be in the same way to make the user side more clear and easy

/cc @mcollina

@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 Oct 13, 2023
@himself65 himself65 force-pushed the himself65/spec branch 2 times, most recently from 0520c59 to c67f4fb Compare October 13, 2023 19:18
@himself65 himself65 marked this pull request as ready for review October 13, 2023 19:25
Copy link
Member Author

@himself65 himself65 left a comment

Choose a reason for hiding this comment

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

I will add test cases later, just wanna see if old test suites all pass now

@himself65 himself65 changed the title refactor(test): rewrite spec reporter into async generator function test_runner: refactor spec reporter to generator function Oct 13, 2023
lib/internal/test_runner/reporter/spec.js Outdated Show resolved Hide resolved
let failedTests = [];
let cwd = process.cwd();

function indent(nesting) {
Copy link
Member

Choose a reason for hiding this comment

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

this means all of these functions are defined anew every time this reporter is called, instead of just once at module startup.

Copy link
Member Author

Choose a reason for hiding this comment

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

these functions require closure variables

Copy link
Member

Choose a reason for hiding this comment

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

then if you're switching to a non-class-based model, the functions should take everything as arguments, so they can be defined at module level.

@mcollina
Copy link
Member

Are reporters stable? If so, this is semver-major and we should document the current behavior.

Note That I think it's possible to make it a non-semver major change by using a function and old school inheritance (like Transform itself).

@aduh95
Copy link
Contributor

aduh95 commented Oct 14, 2023

FWIW I think fixing the documentation would be preferable

@himself65
Copy link
Member Author

FWIW I think fixing the documentation would be preferable

FWIW I think fixing the documentation would be preferable

I think also should throw error when compose a non-stream variable instead of just do nothing

@himself65
Copy link
Member Author

I read the whole code flow, I think some type of mismatch error is ignored in the internal module. Fixing that


#indent(nesting) {
let value = this.#indentMemo.get(nesting);
module.exports = async function *specReporter(source) {
Copy link
Member

Choose a reason for hiding this comment

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

This would still need to be a transform stream, API wise (can be from a generator)

@himself65
Copy link
Member Author

Closing this as I think this is a document issue(we didn't mention this) or node/stream issue(stream.compose will just ignore if the first parameter is a non-expected value)

For more, see: #50187

@himself65 himself65 closed this Oct 14, 2023
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. test_runner Issues and PRs related to the test runner subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

impossible to use spec test reporter without new
6 participants