Skip to content
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

fix: add option ignoreTrailingSlash to MockAgent and .intercept() #3655

Merged
merged 9 commits into from
Oct 4, 2024

Conversation

Uzlopak
Copy link
Contributor

@Uzlopak Uzlopak commented Sep 30, 2024

fixes #3649

Normalize the path in the mock interceptor

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Oct 1, 2024

@metcoder95

Should we wait for a second opinion/approval?

Copy link
Member

@KhafraDev KhafraDev left a comment

Choose a reason for hiding this comment

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

I don't think this is a good idea.

@metcoder95
Copy link
Member

@KhafraDev can you elaborate on that?

@Uzlopak Uzlopak changed the title fix: mock interceptor should ignore trailing slashes fix: add option ignoreTrailingSlashes for MockAgent Oct 2, 2024
@Uzlopak
Copy link
Contributor Author

Uzlopak commented Oct 2, 2024

@metcoder95

I chattet with @KhafraDev and he sent me following tweet of @mcollina

https://x.com/matteocollina/status/1828802494832705896

Seems like to every issue there is a tweet by matteo :D.

Anyhow:
I reworked on this and added ignoreTrailingSlashes as an option of MockAgent. Where do we document stuff like this?

@Uzlopak Uzlopak changed the title fix: add option ignoreTrailingSlashes for MockAgent fix: add option ignoreTrailingSlashes to MockAgent Oct 2, 2024
@Uzlopak Uzlopak changed the title fix: add option ignoreTrailingSlashes to MockAgent fix: add option ignoreTrailingSlash to MockAgent Oct 2, 2024
Copy link
Member

@KhafraDev KhafraDev left a comment

Choose a reason for hiding this comment

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

Why have it as an option on the client rather than passed in the .intercept options?

Copy link
Member

@metcoder95 metcoder95 left a comment

Choose a reason for hiding this comment

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

lib/mock/mock-utils.js Outdated Show resolved Hide resolved
@Uzlopak Uzlopak changed the title fix: add option ignoreTrailingSlash to MockAgent fix: add option ignoreTrailingSlash to MockAgent and .intercept() Oct 3, 2024
@Uzlopak
Copy link
Contributor Author

Uzlopak commented Oct 3, 2024

@KhafraDev
@metcoder95

Now you can set it globally on agent level and on intercept level.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@metcoder95
Copy link
Member

Shall we backport it?

@KhafraDev KhafraDev merged commit c0be359 into main Oct 4, 2024
38 checks passed
@Uzlopak Uzlopak deleted the fix-3649 branch October 4, 2024 14:53
flakey5 pushed a commit to flakey5/undici that referenced this pull request Oct 8, 2024
…nodejs#3655)

* fix: mock interceptor should ignore trailing slashes

* only normalize path if it is a string

* put tests into mock-interceptors.js

* make ignoreTrailingSlashes an option of MockAgent

* rename to ignoreTrailingSlash

* make ignoreTrailingSlashes an option of .intercept

* Apply suggestions from code review

* add documentation
Copy link
Contributor

github-actions bot commented Oct 8, 2024

The backport to v6.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-v6.x v6.x
# Navigate to the new working tree
cd .worktrees/backport-v6.x
# Create a new branch
git switch --create backport-3655-to-v6.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 c0be359aa5b3f2b8076fbad3413a43e8406f6741
# Push it to GitHub
git push --set-upstream origin backport-3655-to-v6.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-v6.x

Then, create a pull request where the base branch is v6.x and the compare/head branch is backport-3655-to-v6.x.

@github-actions github-actions bot mentioned this pull request Dec 3, 2024
This was referenced Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trailing slash on origin causes interceptors to not match
4 participants