From c9db2fb29e5d2bfd27c32590962fdbaaa16448bb Mon Sep 17 00:00:00 2001 From: bbassie <17990055+bbassie@users.noreply.github.com> Date: Fri, 30 Oct 2026 18:42:59 +0000 Subject: [PATCH] Use native FormData in controller route tests Node's FormData and Blob do what the form-data package did here, and fetch sets the multipart Content-Type header itself. Co-Authored-By: Claude Opus 5.5 --- package.json | 1 - test/controller/routes.js | 26 ++++++++++---------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index b8c32482..8ae0c1d4 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,6 @@ "@types/node": "catalog:", "c8": "^12.0.0", "express": "catalog:", - "form-data": "^4.0.6", "jsonwebtoken": "catalog:", "mocha": "^11.8.0", "oxlint": "^1.88.0", diff --git a/test/controller/routes.js b/test/controller/routes.js index d0af23da..0f60a9d2 100644 --- a/test/controller/routes.js +++ b/test/controller/routes.js @@ -1,6 +1,5 @@ import assert from "node:assert/strict"; import events from "node:events"; -import FormData from "form-data"; import http from "node:http"; import { wait, expositionContentType } from "@clusterio/lib"; @@ -308,27 +307,25 @@ describe("controller/src/routes", function() { let form; form = new FormData(); form.append("instance_id", "123"); - form.append("file", "totally a zip file", { filename: "test.zip", contentType: "text/plain" }); + form.append("file", new Blob(["totally a zip file"], { type: "text/plain" }), "test.zip"); response = await fetch(endpoint, { method: "POST", headers: { "X-Access-Token": testToken, - ...form.getHeaders(), }, - body: form.getBuffer(), + body: form, }); assert.equal(response.status, 400); assert.deepEqual(await response.json(), { request_errors: ["invalid file Content-Type"] }); form = new FormData(); - form.append("file", "totally a zip file", { filename: "test.zip", contentType: "application/zip" }); + form.append("file", new Blob(["totally a zip file"], { type: "application/zip" }), "test.zip"); form.append("instance_id", "123"); response = await fetch(endpoint, { method: "POST", headers: { "X-Access-Token": testToken, - ...form.getHeaders(), }, - body: form.getBuffer(), + body: form, }); assert.equal(response.status, 400); assert.deepEqual( @@ -336,14 +333,13 @@ describe("controller/src/routes", function() { ); form = new FormData(); form.append("instance_id", "123"); - form.append("file", "totally a zip file", { filename: "test.txt", contentType: "application/zip" }); + form.append("file", new Blob(["totally a zip file"], { type: "application/zip" }), "test.txt"); response = await fetch(endpoint, { method: "POST", headers: { "X-Access-Token": testToken, - ...form.getHeaders(), }, - body: form.getBuffer(), + body: form, }); assert.equal(response.status, 400); assert.deepEqual( @@ -351,14 +347,13 @@ describe("controller/src/routes", function() { ); form = new FormData(); form.append("instance_id", "invalid"); - form.append("file", "totally a zip file", { filename: "test.zip", contentType: "application/zip" }); + form.append("file", new Blob(["totally a zip file"], { type: "application/zip" }), "test.zip"); response = await fetch(endpoint, { method: "POST", headers: { "X-Access-Token": testToken, - ...form.getHeaders(), }, - body: form.getBuffer(), + body: form, }); assert.equal(response.status, 400); assert.deepEqual( @@ -410,14 +405,13 @@ describe("controller/src/routes", function() { let form; form = new FormData(); form.append("instance_id", "123"); - form.append("file", "totally a zip file", { filename: "test.zip", contentType: "application/zip" }); + form.append("file", new Blob(["totally a zip file"], { type: "application/zip" }), "test.zip"); response = await fetch(endpoint, { method: "POST", headers: { "X-Access-Token": testToken, - ...form.getHeaders(), }, - body: form.getBuffer(), + body: form, }); assert.equal(response.status, 500); assert.deepEqual(await response.json(), { errors: ["Something went wrong"], request_errors: [] });