From 0b4c50587ee1d77582e4702b1fec2af1ef0e9d86 Mon Sep 17 00:00:00 2001 From: Cameron Robey Date: Fri, 9 Sep 2022 15:12:32 +0100 Subject: [PATCH] Add test for busboy emitting error --- test/fetch/client-fetch.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/fetch/client-fetch.js b/test/fetch/client-fetch.js index 00680d5fef8..631f0137232 100644 --- a/test/fetch/client-fetch.js +++ b/test/fetch/client-fetch.js @@ -203,6 +203,37 @@ test('multipart formdata not base64', async (t) => { }) }) +test('busboy emit error', async (t) => { + t.plan(1) + + const formData = new FormData() + formData.append('field1', 'value1') + + const tempRes = new Response(formData) + const formRaw = await tempRes.text() + + const server = createServer((req, res) => { + res.setHeader('content-type', 'multipart/form-data; boundary=wrongboundary') + res.write(formRaw) + res.end() + }) + t.teardown(server.close.bind(server)) + + await new Promise((resolve) => { + server.listen(0, async () => { + const response = await fetch(`http://localhost:${server.address().port}`) + + try { + await response.formData() + } catch (err) { + t.equal(err.message, 'Unexpected end of form') + } + + resolve() + }) + }) +}) + test('multipart formdata base64', async (t) => { t.plan(1)