Skip to content

Commit 56941ca

Browse files
committed
Bypassing native FormData bug in 18.0.0.
1 parent 574921c commit 56941ca

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

example/endpoints/upload-avatar.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@ export const uploadAvatarEndpoint = taggedEndpointsFactory.build({
99
description: "Handles a file upload.",
1010
input: z
1111
.object({
12-
avatar: ez.upload().refine(
13-
(file) => file.mimetype.match(/image\/.+/),
14-
(file) => ({
15-
message: `Should be an image, received ${file.mimetype}`,
16-
}),
17-
),
12+
avatar: ez.upload(),
1813
})
1914
.passthrough(),
2015
output: z.object({

tests/system/example.spec.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ describe("Example", async () => {
196196
const data = new FormData();
197197
data.append(
198198
"avatar",
199-
new Blob([logo], { type: "image/svg+xml" }),
199+
new Blob([logo], { type: "image/svg+xml" }), // FormData mime is buggy in Node 18.0.0
200200
filename,
201201
);
202202
data.append("str", "test string value");
@@ -209,7 +209,26 @@ describe("Example", async () => {
209209
{ method: "POST", body: data },
210210
);
211211
const json = await response.json();
212-
expect(json).toMatchSnapshot();
212+
expect(json).toEqual({
213+
data: {
214+
hash: "f39beeff92379dc935586d726211c2620be6f879",
215+
mime:
216+
process.versions.node === "18.0.0"
217+
? "application/octet-stream" // Node 18.0.0 FormData bug // @todo remove it when dropped
218+
: "image/svg+xml",
219+
name: "logo.svg",
220+
otherInputs: {
221+
arr: ["456", "789"],
222+
num: "123",
223+
obj: {
224+
some: "thing",
225+
},
226+
str: "test string value",
227+
},
228+
size: 48687,
229+
},
230+
status: "success",
231+
});
213232
});
214233

215234
test.each([readFileSync("logo.svg"), createReadStream("logo.svg")])(

0 commit comments

Comments
 (0)