Skip to content

test(mock): cover SnapshotAgent excludeUrls playback#5080

Open
maruthang wants to merge 1 commit intonodejs:mainfrom
maruthang:fix/issue-4663-snapshot-excluded-url-playback
Open

test(mock): cover SnapshotAgent excludeUrls playback#5080
maruthang wants to merge 1 commit intonodejs:mainfrom
maruthang:fix/issue-4663-snapshot-excluded-url-playback

Conversation

@maruthang
Copy link
Copy Markdown
Contributor

This relates to...

Fixes #4663

Rationale

Issue #4663 reported that SnapshotAgent in playback mode threw "No snapshot found" for URLs matched by excludeUrls, even though excluded URLs are meant to pass through to the real network.

The underlying bug was already fixed on main by PR #4670 (commit 5024d1b7), which routes excluded URLs through kRealAgent.dispatch before findSnapshot is consulted (see lib/mock/snapshot-agent.js:85-88). However, the issue was never formally closed and no regression test was added for this specific playback-mode path.

This PR adds a focused regression test so the excludeUrls playback short-circuit cannot silently regress. It reproduces the exact scenario from the issue and also covers a RegExp pattern that only matches during playback, which exercises the dispatch branch end-to-end.

Changes

Add test/mock/issue-4663.js with two cases:

  1. String excludeUrls entry — excluded URL is fetched live during playback.
  2. RegExp excludeUrls entry — excluded URL is fetched live during playback.

Features

N/A

Bug Fixes

N/A — the bug itself was fixed in #4670. This PR adds regression coverage only.

Breaking Changes and Deprecations

N/A

Status

  • I have read and agreed to the Developer's Certificate of Origin
  • Tested (test/mock/issue-4663.js; all snapshot-* and mock-* tests pass)
  • Benchmarked (optional)
  • [S] Documented
  • Review ready
  • In review
  • Merge ready

Add a regression test for the SnapshotAgent playback-mode behaviour
reported in nodejs#4663: a URL matched by an excludeUrls entry must pass
through to the real network during playback instead of throwing
"No snapshot found". The test covers both string and RegExp forms of
excludeUrls, including a regexp that only matches during playback, so
any future regression in the dispatch short-circuit is caught.

Refs nodejs#4663

Signed-off-by: Maruthan G <maruthang4@gmail.com>
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.10%. Comparing base (ec60a7c) to head (2404ffa).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5080   +/-   ##
=======================================
  Coverage   93.10%   93.10%           
=======================================
  Files         110      110           
  Lines       35807    35807           
=======================================
  Hits        33339    33339           
  Misses       2468     2468           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SnapshotAgent in playback mode errors when it encounters an excluded url

2 participants