test_runner: allow special characters in snapshot keys#57017
test_runner: allow special characters in snapshot keys#57017nodejs-github-bot merged 3 commits intonodejs:mainfrom
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
|
|
||
| setSnapshot(id, value) { | ||
| this.snapshots[templateEscape(id)] = value; | ||
| this.snapshots[keyEscape(id)] = value; |
There was a problem hiding this comment.
Since this appears to duplicate much of templateEscape(), couldn't we do this instead: keyEscape(templateEscape(id))
There was a problem hiding this comment.
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.
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.
The test was failing before the check, but I will add an e2e test
There was a problem hiding this comment.
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
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
JSONStringifyto serialise snapshot keys to allow special characters such as\rto be used in test namesFixes: #56836