From 227f94c91bf315242db06af3ffc6f5a109b03f99 Mon Sep 17 00:00:00 2001 From: Federico Date: Mon, 5 Aug 2024 03:06:13 +0700 Subject: [PATCH 1/5] Drop `node-fetch` dependency --- package-lock.json | 21 +++++++++++++++++---- package.json | 2 +- src/util/submit-addon.js | 7 ++++--- tests/unit/test-util/test.submit-addon.js | 4 ++-- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index fb95c19971..ebb99c8b3e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,7 +27,6 @@ "mkdirp": "3.0.1", "multimatch": "6.0.0", "mz": "2.7.0", - "node-fetch": "3.3.2", "node-notifier": "10.0.1", "open": "9.1.0", "parse-json": "7.1.1", @@ -67,6 +66,7 @@ "git-rev-sync": "3.0.2", "html-entities": "2.5.2", "mocha": "10.7.0", + "node-fetch": "3.3.2", "nyc": "17.0.0", "prettier": "3.3.3", "pretty-quick": "4.0.0", @@ -4994,6 +4994,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz", "integrity": "sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==", + "dev": true, "engines": { "node": ">= 12" } @@ -6137,6 +6138,7 @@ "version": "3.2.0", "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", + "dev": true, "funding": [ { "type": "github", @@ -6312,6 +6314,7 @@ "version": "4.0.10", "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "dev": true, "dependencies": { "fetch-blob": "^3.1.2" }, @@ -8684,6 +8687,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "dev": true, "funding": [ { "type": "github", @@ -8702,6 +8706,8 @@ "version": "3.3.2", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", + "dev": true, + "license": "MIT", "dependencies": { "data-uri-to-buffer": "^4.0.0", "fetch-blob": "^3.1.4", @@ -11429,6 +11435,7 @@ "version": "3.2.1", "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==", + "dev": true, "engines": { "node": ">= 8" } @@ -15348,7 +15355,8 @@ "data-uri-to-buffer": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz", - "integrity": "sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==" + "integrity": "sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==", + "dev": true }, "debounce": { "version": "1.2.1", @@ -16176,6 +16184,7 @@ "version": "3.2.0", "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", + "dev": true, "requires": { "node-domexception": "^1.0.0", "web-streams-polyfill": "^3.0.3" @@ -16301,6 +16310,7 @@ "version": "4.0.10", "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "dev": true, "requires": { "fetch-blob": "^3.1.2" } @@ -18010,12 +18020,14 @@ "node-domexception": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", - "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==" + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "dev": true }, "node-fetch": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", + "dev": true, "requires": { "data-uri-to-buffer": "^4.0.0", "fetch-blob": "^3.1.4", @@ -19998,7 +20010,8 @@ "web-streams-polyfill": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", - "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==" + "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==", + "dev": true }, "webidl-conversions": { "version": "3.0.1", diff --git a/package.json b/package.json index e3ed18575e..846f74d594 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,6 @@ "mkdirp": "3.0.1", "multimatch": "6.0.0", "mz": "2.7.0", - "node-fetch": "3.3.2", "node-notifier": "10.0.1", "open": "9.1.0", "parse-json": "7.1.1", @@ -113,6 +112,7 @@ "git-rev-sync": "3.0.2", "html-entities": "2.5.2", "mocha": "10.7.0", + "node-fetch": "3.3.2", "nyc": "17.0.0", "prettier": "3.3.3", "pretty-quick": "4.0.0", diff --git a/src/util/submit-addon.js b/src/util/submit-addon.js index fd72d8aba7..96ad13d004 100644 --- a/src/util/submit-addon.js +++ b/src/util/submit-addon.js @@ -1,9 +1,8 @@ import { createHash } from 'crypto'; -import { createWriteStream, promises as fsPromises } from 'fs'; +import { createWriteStream, promises as fsPromises, readFileSync } from 'fs'; import { promises as streamPromises } from 'stream'; // eslint-disable-next-line no-shadow -import fetch, { FormData, fileFromSync } from 'node-fetch'; import { SignJWT } from 'jose'; import JSZip from 'jszip'; import { HttpsProxyAgent } from 'https-proxy-agent'; @@ -89,7 +88,9 @@ export default class Client { } fileFromSync(path) { - return fileFromSync(path); + // create a blob from a file path + const file = readFileSync(path); + return new Blob([file]); } nodeFetch(url, { method, headers, body, agent }) { diff --git a/tests/unit/test-util/test.submit-addon.js b/tests/unit/test-util/test.submit-addon.js index 72ec3514d4..f7844571ad 100644 --- a/tests/unit/test-util/test.submit-addon.js +++ b/tests/unit/test-util/test.submit-addon.js @@ -8,8 +8,8 @@ import { assert, expect } from 'chai'; import JSZip from 'jszip'; import { afterEach, before, beforeEach, describe, it } from 'mocha'; import * as sinon from 'sinon'; -// eslint-disable-next-line no-shadow -import { File, FormData, Response } from 'node-fetch'; +// eslint-disable-next-line no-shadow -- Testing sub-100 Responses, impossible with native +import { Response } from 'node-fetch'; import { AMO_BASE_URL } from '../../../src/program.js'; import Client, { From 4f736cbc9bde42d4740a9cf8395a7f964ffe6203 Mon Sep 17 00:00:00 2001 From: Federico Date: Mon, 5 Aug 2024 03:09:45 +0700 Subject: [PATCH 2/5] Restore file --- tests/unit/test-util/test.submit-addon.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test-util/test.submit-addon.js b/tests/unit/test-util/test.submit-addon.js index f7844571ad..91ff7e2695 100644 --- a/tests/unit/test-util/test.submit-addon.js +++ b/tests/unit/test-util/test.submit-addon.js @@ -9,7 +9,7 @@ import JSZip from 'jszip'; import { afterEach, before, beforeEach, describe, it } from 'mocha'; import * as sinon from 'sinon'; // eslint-disable-next-line no-shadow -- Testing sub-100 Responses, impossible with native -import { Response } from 'node-fetch'; +import { File, Response } from 'node-fetch'; import { AMO_BASE_URL } from '../../../src/program.js'; import Client, { From c8d0b768539594d29c1ea7c087b204e80b30e86b Mon Sep 17 00:00:00 2001 From: Federico Date: Mon, 5 Aug 2024 03:12:50 +0700 Subject: [PATCH 3/5] ci again please From 366dcd91425e1053f25c9ad46ef35acd452823ea Mon Sep 17 00:00:00 2001 From: Federico Date: Sat, 24 Aug 2024 00:10:49 +0700 Subject: [PATCH 4/5] Mock + test File Co-Authored-By: Luca Greco <11484+rpl@users.noreply.github.com> --- src/util/submit-addon.js | 36 +++++++++++++++++++---- tests/unit/test-util/test.submit-addon.js | 15 ++++++++++ 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/util/submit-addon.js b/src/util/submit-addon.js index 96ad13d004..cfc3c357b6 100644 --- a/src/util/submit-addon.js +++ b/src/util/submit-addon.js @@ -1,8 +1,8 @@ +import { basename } from 'path'; import { createHash } from 'crypto'; import { createWriteStream, promises as fsPromises, readFileSync } from 'fs'; import { promises as streamPromises } from 'stream'; -// eslint-disable-next-line no-shadow import { SignJWT } from 'jose'; import JSZip from 'jszip'; import { HttpsProxyAgent } from 'https-proxy-agent'; @@ -14,6 +14,29 @@ const log = createLogger(import.meta.url); export const defaultAsyncFsReadFile = fsPromises.readFile; +// Used by fileFromSync method to make sure the form-data entry will +// include a filename derived from the file path. +// +// TODO: Get rid of this hack when we will bump the web-ext nodejs +// version required to nodejs v20 (where the native File constructor +// exists). +export class FileBlob extends Blob { + #name = ''; + + constructor(fileBits, fileName, options) { + super(fileBits, options); + this.#name = String(fileName); + } + + get name() { + return this.#name; + } + + get [Symbol.toStringTag]() { + return 'File'; + } +} + export class JwtApiAuth { #apiKey; #apiSecret; @@ -87,10 +110,13 @@ export default class Client { this.userAgentString = userAgentString; } - fileFromSync(path) { - // create a blob from a file path - const file = readFileSync(path); - return new Blob([file]); + fileFromSync(filePath) { + // create a File blob from a file path, and ensure it to have the file path basename + // as the associated filename, the AMO server API will be checking it on the form-data + // submitted and fail with the error message: + // "Unsupported file type, please upload a supported file (.crx, .xpi, .zip)." + const fileData = readFileSync(filePath); + return new FileBlob([fileData], basename(filePath)); } nodeFetch(url, { method, headers, body, agent }) { diff --git a/tests/unit/test-util/test.submit-addon.js b/tests/unit/test-util/test.submit-addon.js index 91ff7e2695..1b3326586a 100644 --- a/tests/unit/test-util/test.submit-addon.js +++ b/tests/unit/test-util/test.submit-addon.js @@ -342,6 +342,21 @@ describe('util.submit-addon', () => { assert.equal(client.apiUrl.href, new URL(`${cleanUrl}/addons/`).href); }); + describe('fileFromSync', () => { + it('should return a File with name set to the file path basename', () => + withTempDir(async (tmpDir) => { + const client = new Client(clientDefaults); + const FILE_BASENAME = 'testfile.txt'; + const FILE_CONTENT = 'somecontent'; + const filePath = path.join(tmpDir.path(), FILE_BASENAME); + await fsPromises.writeFile(filePath, FILE_CONTENT); + const fileRes = client.fileFromSync(filePath); + assert.equal(fileRes.name, FILE_BASENAME); + assert.equal(await fileRes.text(), FILE_CONTENT); + assert.equal(String(fileRes), '[object File]'); + })); + }); + describe('getPreviousUuidOrUploadXpi', () => { it('calls doUploadSubmit if previous hash is different to current', async () => { const oldHash = 'some-hash'; From 62fd0cc777fed3d3c40d745ffa8454853944500a Mon Sep 17 00:00:00 2001 From: Federico Date: Sat, 24 Aug 2024 00:21:09 +0700 Subject: [PATCH 5/5] BadResponse; Drop node-fetch entirely Co-Authored-By: Luca Greco <11484+rpl@users.noreply.github.com> --- package-lock.json | 140 ---------------------- package.json | 1 - tests/unit/test-util/test.submit-addon.js | 21 +++- 3 files changed, 19 insertions(+), 143 deletions(-) diff --git a/package-lock.json b/package-lock.json index 29f4e09575..7a517f5375 100644 --- a/package-lock.json +++ b/package-lock.json @@ -65,7 +65,6 @@ "git-rev-sync": "3.0.2", "html-entities": "2.5.2", "mocha": "10.7.0", - "node-fetch": "3.3.2", "nyc": "17.0.0", "prettier": "3.3.3", "pretty-quick": "4.0.0", @@ -4984,15 +4983,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/data-uri-to-buffer": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz", - "integrity": "sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==", - "dev": true, - "engines": { - "node": ">= 12" - } - }, "node_modules/debounce": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/debounce/-/debounce-1.2.1.tgz", @@ -6128,29 +6118,6 @@ "pend": "~1.2.0" } }, - "node_modules/fetch-blob": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", - "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/jimmywarting" - }, - { - "type": "paypal", - "url": "https://paypal.me/jimmywarting" - } - ], - "dependencies": { - "node-domexception": "^1.0.0", - "web-streams-polyfill": "^3.0.3" - }, - "engines": { - "node": "^12.20 || >= 14.13" - } - }, "node_modules/file-entry-cache": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", @@ -6304,18 +6271,6 @@ "node": ">= 14.17" } }, - "node_modules/formdata-polyfill": { - "version": "4.0.10", - "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", - "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", - "dev": true, - "dependencies": { - "fetch-blob": "^3.1.2" - }, - "engines": { - "node": ">=12.20.0" - } - }, "node_modules/fromentries": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/fromentries/-/fromentries-1.3.2.tgz", @@ -8667,44 +8622,6 @@ "type-detect": "4.0.8" } }, - "node_modules/node-domexception": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", - "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/jimmywarting" - }, - { - "type": "github", - "url": "https://paypal.me/jimmywarting" - } - ], - "engines": { - "node": ">=10.5.0" - } - }, - "node_modules/node-fetch": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", - "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", - "dev": true, - "license": "MIT", - "dependencies": { - "data-uri-to-buffer": "^4.0.0", - "fetch-blob": "^3.1.4", - "formdata-polyfill": "^4.0.10" - }, - "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/node-fetch" - } - }, "node_modules/node-forge": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.1.tgz", @@ -11388,15 +11305,6 @@ "defaults": "^1.0.3" } }, - "node_modules/web-streams-polyfill": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", - "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==", - "dev": true, - "engines": { - "node": ">= 8" - } - }, "node_modules/webidl-conversions": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", @@ -15304,12 +15212,6 @@ "integrity": "sha512-wAV9QHOsNbwnWdNW2FYvE1P56wtgSbM+3SZcdGiWQILwVjACCXDCI3Ai8QlCjMDB8YK5zySiXZYBiwGmNY3lnw==", "dev": true }, - "data-uri-to-buffer": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz", - "integrity": "sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==", - "dev": true - }, "debounce": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/debounce/-/debounce-1.2.1.tgz", @@ -16132,16 +16034,6 @@ "pend": "~1.2.0" } }, - "fetch-blob": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", - "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", - "dev": true, - "requires": { - "node-domexception": "^1.0.0", - "web-streams-polyfill": "^3.0.3" - } - }, "file-entry-cache": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", @@ -16258,15 +16150,6 @@ "resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-2.1.4.tgz", "integrity": "sha512-yDYSgNMraqvnxiEXO4hi88+YZxaHC6QKzb5N84iRCTDeRO7ZALpir/lVmf/uXUhnwUr2O4HU8s/n6x+yNjQkHw==" }, - "formdata-polyfill": { - "version": "4.0.10", - "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", - "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", - "dev": true, - "requires": { - "fetch-blob": "^3.1.2" - } - }, "fromentries": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/fromentries/-/fromentries-1.3.2.tgz", @@ -17959,23 +17842,6 @@ } } }, - "node-domexception": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", - "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", - "dev": true - }, - "node-fetch": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", - "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", - "dev": true, - "requires": { - "data-uri-to-buffer": "^4.0.0", - "fetch-blob": "^3.1.4", - "formdata-polyfill": "^4.0.10" - } - }, "node-forge": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.1.tgz", @@ -19928,12 +19794,6 @@ "defaults": "^1.0.3" } }, - "web-streams-polyfill": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", - "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==", - "dev": true - }, "webidl-conversions": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", diff --git a/package.json b/package.json index c87dd533c6..aade972462 100644 --- a/package.json +++ b/package.json @@ -111,7 +111,6 @@ "git-rev-sync": "3.0.2", "html-entities": "2.5.2", "mocha": "10.7.0", - "node-fetch": "3.3.2", "nyc": "17.0.0", "prettier": "3.3.3", "pretty-quick": "4.0.0", diff --git a/tests/unit/test-util/test.submit-addon.js b/tests/unit/test-util/test.submit-addon.js index 1b3326586a..53dff224a5 100644 --- a/tests/unit/test-util/test.submit-addon.js +++ b/tests/unit/test-util/test.submit-addon.js @@ -8,8 +8,6 @@ import { assert, expect } from 'chai'; import JSZip from 'jszip'; import { afterEach, before, beforeEach, describe, it } from 'mocha'; import * as sinon from 'sinon'; -// eslint-disable-next-line no-shadow -- Testing sub-100 Responses, impossible with native -import { File, Response } from 'node-fetch'; import { AMO_BASE_URL } from '../../../src/program.js'; import Client, { @@ -18,6 +16,9 @@ import Client, { saveIdToFile, saveUploadUuidToFile, signAddon, + + // eslint-disable-next-line no-shadow -- Not actually available under Node 20. Use global once possible. + FileBlob as File, } from '../../../src/util/submit-addon.js'; import { withTempDir } from '../../../src/util/temp-dir.js'; @@ -27,6 +28,19 @@ class JSONResponse extends Response { } } +// Used to test responses with status < 100 (nodejs native constructor +// enforces status to be in the 200-599 range and throws if it is not). +class BadResponse extends Response { + constructor(data, fakeStatus) { + super(data); + this.fakeStatus = fakeStatus; + } + + get status() { + return this.fakeStatus; + } +} + const mockNodeFetch = (nodeFetchStub, url, method, responses) => { // Trust us... You don't want to know why... but if you really do like nightmares // take a look to the details and links kindly provided in this comment @@ -42,6 +56,9 @@ const mockNodeFetch = (nodeFetchStub, url, method, responses) => { for (let i = 0; i < responses.length; i++) { const { body, status } = responses[i]; stubMatcher.onCall(i).callsFake(async () => { + if (status < 200) { + return new BadResponse(body, status); + } if (typeof body === 'string') { return new Response(body, { status }); }