Skip to content

test_runner: allow special characters in snapshot keys - #57017

Merged
nodejs-github-bot merged 3 commits into
nodejs:mainfrom
Ceres6:feat/test-snapshot-special-characters
Feb 19, 2025
Merged

test_runner: allow special characters in snapshot keys#57017
nodejs-github-bot merged 3 commits into
nodejs:mainfrom
Ceres6:feat/test-snapshot-special-characters

Conversation

@Ceres6

Copy link
Copy Markdown
Contributor

Use JSONStringify to serialise snapshot keys to allow special characters such as \r to be used in test names

Fixes: #56836

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/test_runner

@nodejs-github-botnodejs-github-bot added needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem. labels Feb 12, 2025
@Ceres6

Copy link
Copy Markdown
ContributorAuthor

@codecov

codecovBot commented Feb 12, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.07%. Comparing base (1671921) to head (02bbd1d).
Report is 100 commits behind head on main.

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 
Files with missing linesCoverage Δ
lib/internal/test_runner/snapshot.js98.08% <100.00%> (+0.04%)⬆️

... and 72 files with indirect coverage changes

Comment threadlib/internal/test_runner/snapshot.js Outdated
Comment threadlib/internal/test_runner/snapshot.js Outdated

Copy link
Copy Markdown
Contributor

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))

Copy link
Copy Markdown
ContributorAuthor

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

Comment on lines 161 to 162

Copy link
Copy Markdown
Contributor

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).

Copy link
Copy Markdown
ContributorAuthor

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

Copy link
Copy Markdown
ContributorAuthor

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

@targos

Copy link
Copy Markdown
Member

There's a typo in the commit message: especial -> special

@aduh95

Copy link
Copy Markdown
Contributor

Also, the subsystem should be test_runner:, not test:

@Ceres6
Ceres6force-pushed the feat/test-snapshot-special-characters branch from b91c14b to 06b3b94CompareFebruary 17, 2025 18:00
Comment threadtest/fixtures/test-runner/snapshots/special-character.js Outdated
Comment threadtest/parallel/test-runner-snapshot-tests.js Outdated
@Ceres6
Ceres6force-pushed the feat/test-snapshot-special-characters branch from db614e3 to 02bbd1dCompareFebruary 18, 2025 09:18

@pmarchinipmarchini left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@pmarchinipmarchini added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 18, 2025
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 18, 2025
@nodejs-github-bot

This comment was marked as outdated.

@aduh95aduh95 changed the title test: allow especial characters in snapshot keystest_runner: allow special characters in snapshot keysFeb 18, 2025
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@pmarchinipmarchini added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 18, 2025
@atlowChemiatlowChemi added the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 19, 2025
@nodejs-github-botnodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 19, 2025
@nodejs-github-bot
nodejs-github-bot merged commit baa60ce into nodejs:mainFeb 19, 2025
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in baa60ce

acidiney pushed a commit to acidiney/node that referenced this pull request Feb 23, 2025
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>
targos pushed a commit that referenced this pull request Feb 24, 2025
Fixes: #56836
PR-URL: #57017
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
targos pushed a commit that referenced this pull request Feb 25, 2025
Fixes: #56836
PR-URL: #57017
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
aduh95 pushed a commit that referenced this pull request Apr 2, 2025
Fixes: #56836
PR-URL: #57017
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
aduh95 pushed a commit that referenced this pull request Apr 3, 2025
Fixes: #56836
PR-URL: #57017
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
RafaelGSS pushed a commit that referenced this pull request Apr 16, 2025
Fixes: #56836
PR-URL: #57017
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
RafaelGSS pushed a commit that referenced this pull request Apr 17, 2025
Fixes: #56836
PR-URL: #57017
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.needs-ciPRs that need a full CI run.test_runnerIssues and PRs related to the test runner subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test runner cannot find snapshot with \r in title

7 participants

@Ceres6@nodejs-github-bot@targos@aduh95@cjihrig@pmarchini@atlowChemi