-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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: allow special characters in snapshot keys #57017
test_runner: allow special characters in snapshot keys #57017
Conversation
Review requested:
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #57017 +/- ##
==========================================
- Coverage 89.15% 89.07% -0.09%
==========================================
Files 665 665
Lines 192798 193312 +514
Branches 37130 37263 +133
==========================================
+ Hits 171886 172187 +301
- Misses 13673 13829 +156
- Partials 7239 7296 +57
|
lib/internal/test_runner/snapshot.js
Outdated
@@ -77,7 +77,7 @@ class SnapshotFile { | |||
} | |||
|
|||
setSnapshot(id, value) { | |||
this.snapshots[templateEscape(id)] = value; | |||
this.snapshots[keyEscape(id)] = value; |
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.
Since this appears to duplicate much of templateEscape()
, couldn't we do this instead: keyEscape(templateEscape(id))
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 tried it but then it starts failing as we over-escape things, the problem is with the \\
to \\\\
replace
file.setSnapshot('\r 1', 'test'); | ||
t.assert.strictEqual(file.getSnapshot('\\r 1'), 'test'); |
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 the bug happens while reading the snapshots back. I think for this case, it would be better to test a full round trip (write the file and then read it back) using the public APIs. It would probably be good to check a couple more cases besides just \r
since in #56836 (comment), it was reported that this happens for a range of inputs (not saying we should test every single input though).
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.
The test was failing before the check, but I will add an e2e test
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.
AFAICS the range in that comment is the block of high surrogate and low surrogate pairs which are reserved for utf-16 and shouldn't appear, but I'm not an expert on this, so not sure
There's a typo in the commit message: especial -> special |
Also, the subsystem should be |
b91c14b
to
06b3b94
Compare
db614e3
to
02bbd1d
Compare
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.
LGTM
This comment was marked as outdated.
This comment was marked as outdated.
Landed in baa60ce |
Fixes: nodejs#56836 PR-URL: nodejs#57017 Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Use
JSONStringify
to serialise snapshot keys to allow special characters such as\r
to be used in test namesFixes: #56836