Repository navigation
fix(runtime-utils): support registerEndpoint with FormData in jsdom #1846
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
Merged
danielroe
merged 14 commits into
nuxt:main
from
yamachi4416:test/register-endpoint-form-request
Oct 15, 2026
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ea7002b
test: add tests for registerEndpoint with FormData
yamachi4416 3a54e3b
support FormData in jsdom registerEndpoint
yamachi4416 a1cdb03
Merge branch 'main' into test/register-endpoint-form-request
yamachi4416 e79e924
cleanup and add test to nitro-v3
yamachi4416 925fe8e
rename local func name
yamachi4416 f3ea847
pass teardownTimeout to `AfterAll` in cucumber
yamachi4416 98fde30
Merge branch 'main' into test/register-endpoint-form-request
yamachi4416 a9c9c9c
add blob file testcase to fetch.spec
yamachi4416 a02cf75
add typeof check for implForWrapper
yamachi4416 9414705
add warn when failing to get jsdom impl
yamachi4416 e46564d
reword warning message
yamachi4416 edea80e
Merge branch 'main' into test/register-endpoint-form-request
yamachi4416 e27cb20
to fail on invalid state
yamachi4416 69d9ea6
Merge branch 'main' into test/register-endpoint-form-request
yamachi4416 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <script setup lang="ts"> | ||
| const file = useTemplateRef('file') | ||
| const output = ref('') | ||
|
|
||
| async function submit() { | ||
| const data = await $fetch('/api/forms/blob', { | ||
| method: 'post', | ||
| body: file.value?.files?.item(0), | ||
| }) | ||
| output.value = JSON.stringify(data, null, 2) | ||
| } | ||
| </script> | ||
|
|
||
| <template> | ||
| <div> | ||
| <form @submit.prevent> | ||
| <label for="file">File</label> | ||
| <input | ||
| id="file" | ||
| ref="file" | ||
| name="file" | ||
| type="file" | ||
| > | ||
| <button @click="submit"> | ||
| Submit | ||
| </button> | ||
| </form> | ||
| <pre id="output">{{ output }}</pre> | ||
| </div> | ||
| </template> |
37 changes: 37 additions & 0 deletions
37
examples/app-vitest-full/components/FormMultipartSubmit.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <script setup lang="ts"> | ||
| const form = useTemplateRef('form') | ||
| const output = ref('') | ||
|
|
||
| async function submit() { | ||
| const data = await $fetch('/api/forms/mutlipart', { | ||
| method: 'post', | ||
| body: new FormData(form.value!), | ||
| }) | ||
| output.value = JSON.stringify(data, null, 2) | ||
| } | ||
| </script> | ||
|
|
||
| <template> | ||
| <div> | ||
| <form | ||
| ref="form" | ||
| @submit.prevent | ||
| > | ||
| <label for="name">Name</label> | ||
| <input | ||
| id="name" | ||
| name="name" | ||
| > | ||
| <label for="file">File</label> | ||
| <input | ||
| id="file" | ||
| name="file" | ||
| type="file" | ||
| > | ||
| <button @click="submit"> | ||
| Submit | ||
| </button> | ||
| </form> | ||
| <pre id="output">{{ output }}</pre> | ||
| </div> | ||
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <template> | ||
| <div> | ||
| <section> | ||
| <h1>Multipart</h1> | ||
| <FormMultipartSubmit /> | ||
| </section> | ||
| <section> | ||
| <h1>Blob</h1> | ||
| <FormBlobSubmit /> | ||
| </section> | ||
| </div> | ||
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { defineEventHandler, getHeader, readRawBody } from 'h3' | ||
|
|
||
| export default defineEventHandler(async (event) => { | ||
| const body = await readRawBody(event, 'utf8') | ||
| return { body, contentType: getHeader(event, 'content-type') } | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { defineEventHandler, readMultipartFormData } from 'h3' | ||
|
|
||
| export default defineEventHandler(async (event) => { | ||
| const parts = await readMultipartFormData(event) | ||
| return parts?.map(part => ({ ...part, data: part.data.toString('utf8') })) ?? [] | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Preserve uploaded file bytes in both responses. Both endpoints decode file data as UTF-8, although the new file inputs accept non-text files. Invalid UTF-8 bytes become replacement characters, so the response cannot represent the submitted file. (nodejs.org)
examples/app-vitest-full/server/api/forms/blob.post.ts#L4-L4: read raw bytes and return a byte-safe encoding for the body.examples/app-vitest-full/server/api/forms/mutlipart.post.ts#L5-L5: encode file-part bytes without loss; retain text decoding only for text fields.📍 Affects 2 files
examples/app-vitest-full/server/api/forms/blob.post.ts#L4-L4(this comment)examples/app-vitest-full/server/api/forms/mutlipart.post.ts#L5-L5🤖 Prompt for AI Agents