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: migrate test runner message tests to snapshot #47392

Merged
merged 1 commit into from
Apr 10, 2023

Conversation

MoLow
Copy link
Member

@MoLow MoLow commented Apr 3, 2023

Ref: #47370 (comment)
this PR introduces an internal tool for snapshot testing.
today we use python for that and regenerate snapshots manually.

this is not a full-blown snapshot testing solution and has a few limitations that can be resolved/improved in the future if we have any more use cases or if we want to re-introduce assert.snapshot:

  • it only accepts strings as an input
  • each snapshot file stores a single snapshot, multiple snapshot points require multiple files

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test Issues and PRs related to the tests. labels Apr 3, 2023
@MoLow
Copy link
Member Author

MoLow commented Apr 3, 2023

CC @GeoffreyBooth @nodejs/test_runner

@MoLow MoLow force-pushed the test-runner-output branch 2 times, most recently from cd45963 to 1c28b68 Compare April 3, 2023 22:22
@GeoffreyBooth
Copy link
Member

@MoLow Thank you for doing this! This is much more robust than I was envisioning. On quick skim, it seems like this takes care not only of my concern about moving the regex comparison into JavaScript and out of Python, but it also automates the snapshot generation?

One thing I had to deal with with the message tests (part of the reason I dislike them so much) is that people would often include full stack traces when those were unnecessary, and those stack traces would include the call stack of the module loader which was very annoying whenever we wanted to change anything in the module loader. See https://github.com/orgs/nodejs/discussions/44168. In #44197 I added Error.stackTraceLimit to many of these tests to shrink down the generated stack traces to just the number of frames relevant to the system being tested, so that the module loader files weren’t output in the first place. I don’t know if this could be automated at all in what you’ve built here (and it certainly doesn’t need to happen in this PR) but I wanted to plant the idea in your head in case any solutions are obvious to you. Maybe something as simple as Error.stackTraceLimit = 0 as a default value in the snapshot generation code, so that stack traces are excluded from the snapshots unless the limit is explicitly set?

@@ -134,7 +134,6 @@

# Test runner

/test/message/test_runner_* @nodejs/test_runner
/test/parallel/test-runner-* @nodejs/test_runner
Copy link
Member

Choose a reason for hiding this comment

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

Not in this PR, but perhaps we should move all the test runner stuff into /test/test-runner?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm +0 on that

test/common/README.md Outdated Show resolved Hide resolved
test/common/README.md Outdated Show resolved Hide resolved
test/common/index.js Show resolved Hide resolved
test/common/snap.js Outdated Show resolved Hide resolved
@MoLow
Copy link
Member Author

MoLow commented Apr 3, 2023

On quick skim, it seems like this takes care not only of my concern about moving the regex comparison into JavaScript and out of Python, but it also automates the snapshot generation?

correct

One thing I had to deal with with the message tests (part of the reason I dislike them so much) is that people would often include full stack traces when those were unnecessary, and those stack traces would include the call stack of the module loader which was very annoying whenever we wanted to change anything in the module loader. See github.com/orgs/nodejs/discussions/44168. In #44197 I added Error.stackTraceLimit to many of these tests to shrink down the generated stack traces to just the number of frames relevant to the system being tested, so that the module loader files weren’t output in the first place. I don’t know if this could be automated at all in what you’ve built here (and it certainly doesn’t need to happen in this PR) but I wanted to plant the idea in your head in case any solutions are obvious to you. Maybe something as simple as Error.stackTraceLimit = 0 as a default value in the snapshot generation code, so that stack traces are excluded from the snapshots unless the limit is explicitly set?

this PR uses a transformer function replacing anything detected as a stack trace with an asterisk

test/common/README.md Outdated Show resolved Hide resolved
@MoLow MoLow force-pushed the test-runner-output branch 2 times, most recently from 669aa40 to cada058 Compare April 4, 2023 09:35
@MoLow MoLow requested a review from cjihrig April 4, 2023 19:20
Copy link
Member

@tniessen tniessen left a comment

Choose a reason for hiding this comment

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

There's already a snapshot.js file in test/common, and the file name snap.js does not really help distinguish between the two. Maybe just put these new functions into test/common/fixtures.js? All the actual snapshots are stored in test/fixtures anyway, as far as I can tell, so that seems appropriate.

test/common/README.md Outdated Show resolved Hide resolved
test/common/snap.js Outdated Show resolved Hide resolved
test/common/snap.js Outdated Show resolved Hide resolved
@@ -181,7 +181,7 @@ not ok 4 - beforeEach throws
*
*
*
*
async Promise.all (index 0)
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I don't really know what the test runner is doing. But why does this particular stack frame exist now? What's going on here?

Copy link
Member Author

Choose a reason for hiding this comment

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

this diff is here since previously the .out files where generated manually, and now they are generated automatically.
so stack trace lines are detected using a regex and replaced with *.
these specific lines are not detected as stack trace lines and thus are not replaces which is ok (since what usually should be ignored is file paths and location in the file etc)

@MoLow MoLow force-pushed the test-runner-output branch 2 times, most recently from eef9e86 to 346ce00 Compare April 9, 2023 18:06
test/common/assertSnapshot.js Outdated Show resolved Hide resolved
@MoLow MoLow added commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. request-ci Add this label to start a Jenkins CI on a PR. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. labels Apr 9, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 9, 2023
@nodejs-github-bot
Copy link
Collaborator

@MoLow MoLow added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 9, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 9, 2023
@nodejs-github-bot
Copy link
Collaborator

@MoLow MoLow added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 9, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 9, 2023
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot
Copy link
Collaborator

PR-URL: nodejs#47392
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
@MoLow MoLow merged commit 57508fb into nodejs:main Apr 10, 2023
@MoLow
Copy link
Member Author

MoLow commented Apr 10, 2023

Landed in 57508fb

@MoLow MoLow deleted the test-runner-output branch April 10, 2023 00:07
RafaelGSS pushed a commit that referenced this pull request Apr 13, 2023
PR-URL: #47392
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
danielleadams pushed a commit that referenced this pull request Jul 6, 2023
PR-URL: #47392
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
MoLow added a commit to MoLow/node that referenced this pull request Jul 6, 2023
PR-URL: nodejs#47392
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-ci PRs that need a full CI run. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants