-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
test_runner: add snapshot testing #53169
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
Conversation
Review requested:
|
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.
Nice work, good tests, left some comments, want to see how people feel about this but personally I'm +1
I believe snapshot does not belong in core because it's too specific to a domain. |
exports[`suite of snapshot tests > snapshot test 1`] = ` | ||
{ | ||
"value1": 1, | ||
"value2": 2 |
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.
@cjihrig It seems like this is missing backtick consistency for string values in snapshots.
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'm not sure what you mean.
I think this is a little too vague. What domain? What can't we do that most other test runners have figured out how to do? |
@cjihrig is there any reason JSON.stringify was chosen here over Seems like it'd be a good fit here? |
Yes. Per the
It's not a suitable default for Node core, but you can use it for your own serialization if you want. |
Ah, lame. Alright, thanks for the heads up! It'd be nice if the stance was changed on that api to only change output across majors. It seems reasonable to me that you might have to update your snapshots when upgrading to a new major. Oh well! |
I would also love to see someone get a better and reliable serialization format in place! |
util.inspect was actually used in the past iteration of snapshot testing we had and it caused problems people complained about (about how it defines equality and semverness) |
Looking at that code, this method appears duplicated: node/lib/internal/test_runner/test.js Lines 1236 to 1244 in e08a654
node/lib/internal/test_runner/test.js Lines 228 to 230 in e08a654
Could be simplified with node/lib/internal/test_runner/test.js Lines 546 to 550 in e08a654
I.e. the test could have just had a |
test_runner: add context.fullName
This commit adds a fullName getter to the TestContext and
SuiteContext classes. This is similar to the existing name getter,
but also includes the name of all ancestor tests/suites.
doc: add context.assert docs
When context.assert was added, no docs were added. This commit
adds initial documentation for context.assert because the
snapshot() function requires them.
Refs: #52860
test_runner: add snapshot testing
This commit adds a t.assert.snapshot() method that implements
snapshot testing. Serialization uses JSON.stringify() by default,
but users can configure the serialization to meet their needs.
Fixes: #48260