Skip to content

test_runner: escape carriage returns in snapshot values - #66040

Open
hanityx wants to merge 1 commit into
nodejs:mainfrom
hanityx:test-runner-snapshot-cr
Open

hanityx wants to merge 1 commit into
nodejs:mainfrom
hanityx:test-runner-snapshot-cr

Conversation

@hanityx

@hanityx hanityx commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

CR and CRLF from custom serializers such as String are written unescaped into
snapshot template literals and normalized to LF when the file is evaluated.
The default JSON serializer is unaffected.

For example, in JavaScript string notation:

Before saving: "a\r\nb"
After loading: "a\nb"

An unchanged value therefore fails comparison, while changing only the line
endings to LF can incorrectly pass.

Escape carriage returns in snapshot values and add CR/CRLF round-trip tests.

Existing snapshots containing unescaped CR values will still have those CRs
normalized to LF when evaluated until they are regenerated with --test-update-snapshots

Signed-off-by: hanityx <hanityx@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem. labels Sep 15, 2026
@codecov

codecov Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.22%. Comparing base (c1e2478) to head (d01b5a6).
⚠️ Report is 21 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66040      +/-   ##
==========================================
- Coverage   90.23%   90.22%   -0.01%     
==========================================
  Files         785      789       +4     
  Lines      269670   270614     +944     
  Branches    51589    51798     +209     
==========================================
+ Hits       243325   244150     +825     
- Misses      16825    16933     +108     
- Partials     9520     9531      +11     
Files with missing lines Coverage Δ
lib/internal/test_runner/snapshot.js 98.10% <100.00%> (+<0.01%) ⬆️

... and 56 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants