Skip to content

feat(runtime-utils): support once option in registerEndpoint#1475

Merged
danielroe merged 2 commits intomainfrom
feat/once-register-endpoint
Oct 30, 2025
Merged

feat(runtime-utils): support once option in registerEndpoint#1475
danielroe merged 2 commits intomainfrom
feat/once-register-endpoint

Conversation

@wattanx
Copy link
Copy Markdown
Collaborator

@wattanx wattanx commented Oct 29, 2025

🔗 Linked issue

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Add once option to registerEndpoint function that automatically removes the handler after the first matching request,
similar to msw's once behavior.
With the "once" option, you can configure it to return different responses for the same endpoint.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Oct 29, 2025

Open in StackBlitz

npm i https://pkg.pr.new/@nuxt/test-utils@1475

commit: 096c5a8

type Awaitable<T> = T | Promise<T>
type OptionalFunction<T> = T | (() => Awaitable<T>)

const endpointRegistry: Record<string, Array<{ handler: EventHandler, method?: HTTPMethod, once?: boolean }>> = {}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I moved it because it wasn’t a comment for registerEndpoint.

@wattanx wattanx marked this pull request as ready for review October 29, 2025 14:25
@wattanx wattanx requested a review from danielroe as a code owner October 29, 2025 14:25
Copy link
Copy Markdown
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

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

nice idea! 👌

@danielroe danielroe merged commit 4f04851 into main Oct 30, 2025
7 checks passed
@danielroe danielroe deleted the feat/once-register-endpoint branch October 30, 2025 16:16
@github-actions github-actions bot mentioned this pull request Oct 30, 2025
@github-actions github-actions bot mentioned this pull request Dec 4, 2025
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.

2 participants