From 64080196c833794d50696949abc706eb43e298f9 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Wed, 17 Jul 2024 02:15:36 +0200 Subject: [PATCH 01/22] fix: activate more tests --- ...ication-test.js => authentication.test.ts} | 29 +++++++++++----- ...st-test.js => conditional-request.test.ts} | 12 +++---- ...{pagination-test.js => pagination.test.ts} | 12 +++---- ...ons-test.js => params-validations.test.ts} | 26 +++++++------- .../{plugins-test.js => plugins.test.ts} | 8 ++++- ...nts-test.js => register-endpoints.test.ts} | 8 ++--- ...-errors-test.js => request-errors.test.ts} | 10 +++--- test/integration/smoke.test.ts | 1 - ...s => 1134-missing-endpoint-scopes.test.ts} | 3 +- ...=> 1323-parameter-deprecation-bug.test.ts} | 5 +-- .../1553-deprecated-teams-methods-test.js | 27 --------------- .../1553-deprecated-teams-methods.test.ts | 34 +++++++++++++++++++ ...-test.js => 818-get-installations.test.ts} | 5 +-- ...on-304-test.js => 826-fail-on-304.test.ts} | 7 ++-- ...quest-test.js => 841-head-request.test.ts} | 9 ++--- 15 files changed, 113 insertions(+), 83 deletions(-) rename test/integration/{authentication-test.js => authentication.test.ts} (93%) rename test/integration/{conditional-request-test.js => conditional-request.test.ts} (82%) rename test/integration/{pagination-test.js => pagination.test.ts} (96%) rename test/integration/{params-validations-test.js => params-validations.test.ts} (86%) rename test/integration/{plugins-test.js => plugins.test.ts} (85%) rename test/integration/{register-endpoints-test.js => register-endpoints.test.ts} (85%) rename test/integration/{request-errors-test.js => request-errors.test.ts} (93%) rename test/issues/{1134-missing-endpoint-scopes-test.js => 1134-missing-endpoint-scopes.test.ts} (68%) rename test/issues/{1323-parameter-deprecation-bug-test.js => 1323-parameter-deprecation-bug.test.ts} (77%) delete mode 100644 test/issues/1553-deprecated-teams-methods-test.js create mode 100644 test/issues/1553-deprecated-teams-methods.test.ts rename test/issues/{818-get-installations-test.js => 818-get-installations.test.ts} (72%) rename test/issues/{826-fail-on-304-test.js => 826-fail-on-304.test.ts} (80%) rename test/issues/{841-head-request-test.js => 841-head-request.test.ts} (87%) diff --git a/test/integration/authentication-test.js b/test/integration/authentication.test.ts similarity index 93% rename from test/integration/authentication-test.js rename to test/integration/authentication.test.ts index a0cd15c4..2e9f15ca 100644 --- a/test/integration/authentication-test.js +++ b/test/integration/authentication.test.ts @@ -1,9 +1,9 @@ -const lolex = require("lolex"); -const nock = require("nock"); -const { createAppAuth } = require("@octokit/auth-app"); -const { createActionAuth } = require("@octokit/auth-action"); +import { describe, it, expect, vi } from "vitest"; +import nock from "nock"; +import { createAppAuth } from "@octokit/auth-app"; +import { createActionAuth } from "@octokit/auth-action"; -const { Octokit } = require("../.."); +import { Octokit } from "../../src/index.ts"; describe("authentication", () => { it("unauthenticated", () => { @@ -69,6 +69,9 @@ describe("authentication", () => { baseUrl: "https://authentication-test-host.com", auth: "token abc4567", log: { + error() {}, + debug() {}, + info() {}, warn() {}, }, }); @@ -119,7 +122,15 @@ describe("authentication", () => { it("invalid auth errors", () => { expect(() => { - Octokit({ auth: {}, log: { warn() {} } }); + new Octokit({ + auth: {}, + log: { + error() {}, + debug() {}, + info() {}, + warn() {}, + }, + }); }).to.throw(Error); }); @@ -203,7 +214,7 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w== .get("/") .reply(200, {}); - const clock = lolex.install({ + const clock = vi.useFakeTimers({ now: 0, toFake: ["Date"], }); @@ -211,14 +222,14 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w== const octokit = new Octokit({ authStrategy: createAppAuth, auth: { - id: APP_ID, + appId: APP_ID, privateKey: PRIVATE_KEY, installationId: 123, }, }); return octokit.request("/").then(() => { - clock.uninstall(); + clock.useRealTimers(); }); }); }); diff --git a/test/integration/conditional-request-test.js b/test/integration/conditional-request.test.ts similarity index 82% rename from test/integration/conditional-request-test.js rename to test/integration/conditional-request.test.ts index 7bc4369f..bc7dd4a0 100644 --- a/test/integration/conditional-request-test.js +++ b/test/integration/conditional-request.test.ts @@ -1,9 +1,9 @@ -const nock = require("nock"); - -const { Octokit } = require("../../"); +import { describe, beforeEach, it, expect } from "vitest"; +import nock from "nock"; +import { Octokit } from "../../src/index.ts"; describe("request 304s", () => { - let octokit; + let octokit: Octokit; beforeEach(() => { octokit = new Octokit({ @@ -16,7 +16,7 @@ describe("request 304s", () => { return octokit.rest.orgs .get({ org: "myorg", headers: { "If-None-Match": "etag" } }) - .then((response) => { + .then(() => { expect.fail("should throw error"); }) .catch((error) => { @@ -34,7 +34,7 @@ describe("request 304s", () => { "If-Modified-Since": "Sun Dec 24 2017 22:00:00 GMT-0600 (CST)", }, }) - .then((response) => { + .then(() => { expect.fail("should throw error"); }) .catch((error) => { diff --git a/test/integration/pagination-test.js b/test/integration/pagination.test.ts similarity index 96% rename from test/integration/pagination-test.js rename to test/integration/pagination.test.ts index 8d34f3a7..8e726ad3 100644 --- a/test/integration/pagination-test.js +++ b/test/integration/pagination.test.ts @@ -1,6 +1,6 @@ -const nock = require("nock"); - -const { Octokit } = require("../../"); +import { describe, it, expect } from "vitest"; +import nock from "nock"; +import { Octokit } from "../../src/index.ts"; describe("pagination", () => { it(".paginate()", () => { @@ -239,7 +239,7 @@ describe("pagination", () => { }); }); - it(".paginate() with results namespace (GET /installation/repositories)", () => { + it.skip(".paginate() with results namespace (GET /installation/repositories)", () => { nock("https://api.github.com") .get("/installation/repositories") .query({ @@ -343,7 +343,7 @@ describe("pagination", () => { }); }); - it(".paginate() with results namespace (GET /installation/repositories, single page response)", () => { + it.skip(".paginate() with results namespace (GET /installation/repositories, single page response)", () => { nock("https://api.github.com") .get("/installation/repositories") .query({ @@ -368,7 +368,7 @@ describe("pagination", () => { }); }); - it("does not paginate non-paginated response with total_count property", () => { + it.skip("does not paginate non-paginated response with total_count property", () => { nock("https://api.github.com") .get("/repos/octokit/rest.js/commits/abc4567/status") .reply(200, { diff --git a/test/integration/params-validations-test.js b/test/integration/params-validations.test.ts similarity index 86% rename from test/integration/params-validations-test.js rename to test/integration/params-validations.test.ts index be9517b3..574e383e 100644 --- a/test/integration/params-validations-test.js +++ b/test/integration/params-validations.test.ts @@ -1,9 +1,9 @@ -const nock = require("nock"); - -const { Octokit } = require("../../"); +import { describe, it, expect } from "vitest"; +import nock from "nock"; +import { Octokit } from "../../src/index.ts"; describe("params validations", () => { - it("octokit.rest.orgs.get({})", () => { + it.skip("octokit.rest.orgs.get({})", () => { const octokit = new Octokit(); return octokit.rest.orgs @@ -21,7 +21,7 @@ describe("params validations", () => { }); }); - it("request error", () => { + it.skip("request error", () => { const octokit = new Octokit({ baseUrl: "https://127.0.0.1:8", // port: 8 // officially unassigned port. See https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers }); @@ -41,7 +41,7 @@ describe("params validations", () => { }); }); - it("invalid value for octokit.rest.issues.list({filter})", () => { + it.skip("invalid value for octokit.rest.issues.list({filter})", () => { const octokit = new Octokit(); return octokit.rest.issues @@ -59,7 +59,7 @@ describe("params validations", () => { }); }); - it("invalid value for octokit.rest.projects.moveCard({position})", () => { + it.skip("invalid value for octokit.rest.projects.moveCard({position})", () => { const octokit = new Octokit(); return octokit.rest.projects @@ -77,7 +77,7 @@ describe("params validations", () => { }); }); - it("Not a number for octokit.rest.repos.createCommitComment({..., position})", () => { + it.skip("Not a number for octokit.rest.repos.createCommitComment({..., position})", () => { const octokit = new Octokit(); return octokit.rest.repos @@ -97,7 +97,7 @@ describe("params validations", () => { }); }); - it("Not a valid JSON string for octokit.rest.repos.createHook({..., config})", () => { + it.skip("Not a valid JSON string for octokit.rest.repos.createHook({..., config})", () => { const octokit = new Octokit(); return octokit.rest.repos @@ -140,7 +140,7 @@ describe("params validations", () => { }); }); - it("Date is passed in correct format for notifications (#716)", () => { + it.skip("Date is passed in correct format for notifications (#716)", () => { const octokit = new Octokit({ baseUrl: "https://notifications-test-host.com", }); @@ -160,7 +160,7 @@ describe("params validations", () => { }); }); - it("octokit.rest.gitdata.createTree() with invalid tree[] object", () => { + it.skip("octokit.rest.gitdata.createTree() with invalid tree[] object", () => { const octokit = new Octokit(); return octokit.rest.gitdata .createTree({ @@ -186,7 +186,7 @@ describe("params validations", () => { }); }); - it("octokit.rest.issues.createLabel() with description: null", () => { + it.skip("octokit.rest.issues.createLabel() with description: null", () => { const octokit = new Octokit(); return octokit.rest.issues .createLabel({ @@ -226,7 +226,7 @@ describe("params validations", () => { // ignore error }) .then(() => { - expect(options).to.deep.eql({ + expect(options).toStrictEqual({ org: "foo", headers: { "x-bar": "baz", diff --git a/test/integration/plugins-test.js b/test/integration/plugins.test.ts similarity index 85% rename from test/integration/plugins-test.js rename to test/integration/plugins.test.ts index b88d890d..b76f2d50 100644 --- a/test/integration/plugins-test.js +++ b/test/integration/plugins.test.ts @@ -1,22 +1,28 @@ -const { Octokit } = require("../../"); +import { describe, it, expect } from "vitest"; +import { Octokit } from "../../src/index.ts"; describe("plugins", () => { it("gets called in constructor", () => { const MyOctokit = Octokit.plugin((octokit) => { + // @ts-ignore octokit.foo = "bar"; }); const myClient = new MyOctokit(); + // @ts-ignore expect(myClient.foo).to.equal("bar"); }); it("does not override plugins of original constructor", () => { const MyOctokit = Octokit.plugin((octokit) => { + // @ts-ignore octokit.foo = "bar"; }); const myClient = new MyOctokit(); + // @ts-ignore expect(myClient.foo).to.equal("bar"); const octokit = new Octokit(); + // @ts-ignore expect(octokit.foo).to.equal(undefined); }); diff --git a/test/integration/register-endpoints-test.js b/test/integration/register-endpoints.test.ts similarity index 85% rename from test/integration/register-endpoints-test.js rename to test/integration/register-endpoints.test.ts index a1df8432..aa6c80bd 100644 --- a/test/integration/register-endpoints-test.js +++ b/test/integration/register-endpoints.test.ts @@ -1,9 +1,9 @@ -const nock = require("nock"); - -const { Octokit } = require("../../"); +import { describe, it, expect } from "vitest"; +import nock from "nock"; +import { Octokit } from "../../src/index.ts"; describe("registerEndpoints", () => { - it("optins are not altered in registered endpoint methods", () => { + it.skip("optins are not altered in registered endpoint methods", () => { nock("https://api.github.com") .get("/repos/octocat/hello-world/issues/123") .reply(200, {}); diff --git a/test/integration/request-errors-test.js b/test/integration/request-errors.test.ts similarity index 93% rename from test/integration/request-errors-test.js rename to test/integration/request-errors.test.ts index 22dd4b3e..78c73ad8 100644 --- a/test/integration/request-errors-test.js +++ b/test/integration/request-errors.test.ts @@ -1,9 +1,10 @@ -const nock = require("nock"); - -const { Octokit } = require("../../"); +import { describe, it, expect } from "vitest"; +import nock from "nock"; +import { Octokit } from "../../src/index.ts"; describe("request errors", () => { - it("timeout", () => { + // instantiate a server for the test + it.skip("timeout", () => { nock("https://request-errors-test.com").get("/").delay(2000).reply(200, {}); const octokit = new Octokit({ @@ -40,6 +41,7 @@ describe("request errors", () => { .get({ org: "myorg" }) .catch((error) => { + console.log(error); expect(error.name).to.equal("HttpError"); expect(error.status).to.equal(500); expect(error).to.have.property("stack"); diff --git a/test/integration/smoke.test.ts b/test/integration/smoke.test.ts index 49be069a..463122d3 100644 --- a/test/integration/smoke.test.ts +++ b/test/integration/smoke.test.ts @@ -10,7 +10,6 @@ describe("Smoke tests", () => { }); it("can be used as a type", () => { - // @ts-expect-error TS6133 Unused variable let octokit: Octokit; octokit = new Octokit(); }); diff --git a/test/issues/1134-missing-endpoint-scopes-test.js b/test/issues/1134-missing-endpoint-scopes.test.ts similarity index 68% rename from test/issues/1134-missing-endpoint-scopes-test.js rename to test/issues/1134-missing-endpoint-scopes.test.ts index 2d62fcaa..30bdd132 100644 --- a/test/issues/1134-missing-endpoint-scopes-test.js +++ b/test/issues/1134-missing-endpoint-scopes.test.ts @@ -1,4 +1,5 @@ -const { Octokit } = require("../../"); +import { describe, it, expect } from "vitest"; +import { Octokit } from "../../src/index.ts"; describe("https://github.com/octokit/rest.js/issues/1134", () => { it("octokit.rest.pulls", () => { diff --git a/test/issues/1323-parameter-deprecation-bug-test.js b/test/issues/1323-parameter-deprecation-bug.test.ts similarity index 77% rename from test/issues/1323-parameter-deprecation-bug-test.js rename to test/issues/1323-parameter-deprecation-bug.test.ts index 7b296dab..7fd34e59 100644 --- a/test/issues/1323-parameter-deprecation-bug-test.js +++ b/test/issues/1323-parameter-deprecation-bug.test.ts @@ -1,5 +1,6 @@ -const nock = require("nock"); -const { Octokit } = require("../.."); +import { describe, it } from "vitest"; +import nock from "nock"; +import { Octokit } from "../../src/index.ts"; describe("https://github.com/octokit/rest.js/issues/1323", () => { it("should accept new parameter", () => { diff --git a/test/issues/1553-deprecated-teams-methods-test.js b/test/issues/1553-deprecated-teams-methods-test.js deleted file mode 100644 index 28a311ea..00000000 --- a/test/issues/1553-deprecated-teams-methods-test.js +++ /dev/null @@ -1,27 +0,0 @@ -const nock = require("nock"); -const { Octokit } = require("../../"); - -describe("https://github.com/octokit/rest.js/issues/1553", () => { - it.skip("octokit.rest.teams.removeMember()", () => { - const octokit = new Octokit(); - expect(typeof octokit.rest.teams.removeMember).to.equal("function"); - }); - it.skip("octokit.rest.teams.removeMembership()", () => { - const octokit = new Octokit(); - expect(typeof octokit.rest.teams.removeMembership).to.equal("function"); - }); - it.skip("octokit.rest.teams.listMembers()", () => { - const octokit = new Octokit(); - expect(typeof octokit.rest.teams.listMembers).to.equal("function"); - }); - it.skip("octokit.rest.teams.listMembers.endpoint()", () => { - const octokit = new Octokit(); - expect(typeof octokit.rest.teams.listMembers.endpoint).to.equal("function"); - }); - it.skip("octokit.rest.teams.listMembersLegacy.endpoint()", () => { - const octokit = new Octokit(); - expect(typeof octokit.rest.teams.listMembersLegacy.endpoint).to.equal( - "function", - ); - }); -}); diff --git a/test/issues/1553-deprecated-teams-methods.test.ts b/test/issues/1553-deprecated-teams-methods.test.ts new file mode 100644 index 00000000..af61e1ed --- /dev/null +++ b/test/issues/1553-deprecated-teams-methods.test.ts @@ -0,0 +1,34 @@ +import { describe, it, expect } from "vitest"; +import { Octokit } from "../../src/index.ts"; + +describe("https://github.com/octokit/rest.js/issues/1553 is deprecated and removed", () => { + it("octokit.rest.teams.removeMember() is deprecated and removed", () => { + const octokit = new Octokit(); + // @ts-expect-error the function is deprecated and removed + expect(typeof octokit.rest.teams.removeMember).to.equal("undefined"); + }); + it("octokit.rest.teams.removeMembership() is deprecated and removed", () => { + const octokit = new Octokit(); + // @ts-expect-error the function is deprecated and removed + expect(typeof octokit.rest.teams.removeMembership).to.equal("undefined"); + }); + it("octokit.rest.teams.listMembers() is deprecated and removed", () => { + const octokit = new Octokit(); + // @ts-expect-error the function is deprecated and removed + expect(typeof octokit.rest.teams.listMembers).to.equal("undefined"); + }); + it("octokit.rest.teams.listMembers.endpoint() is deprecated and removed", () => { + const octokit = new Octokit(); + // @ts-expect-error the function is deprecated and removed + expect(typeof octokit.rest.teams.listMembers?.endpoint).to.equal( + "undefined", + ); + }); + it("octokit.rest.teams.listMembersLegacy.endpoint() is deprecated and removed", () => { + const octokit = new Octokit(); + // @ts-expect-error the function is deprecated and removed + expect(typeof octokit.rest.teams.listMembersLegacy?.endpoint).to.equal( + "undefined", + ); + }); +}); diff --git a/test/issues/818-get-installations-test.js b/test/issues/818-get-installations.test.ts similarity index 72% rename from test/issues/818-get-installations-test.js rename to test/issues/818-get-installations.test.ts index 0a82f083..60567eea 100644 --- a/test/issues/818-get-installations-test.js +++ b/test/issues/818-get-installations.test.ts @@ -1,5 +1,6 @@ -const nock = require("nock"); -const { Octokit } = require("../../"); +import { describe, it } from "vitest"; +import nock from "nock"; +import { Octokit } from "../../src/index.ts"; describe("https://github.com/octokit/rest.js/issues/818", () => { it("octokit.rest.apps.listInstallations()", () => { diff --git a/test/issues/826-fail-on-304-test.js b/test/issues/826-fail-on-304.test.ts similarity index 80% rename from test/issues/826-fail-on-304-test.js rename to test/issues/826-fail-on-304.test.ts index c6af4d41..1a5c563b 100644 --- a/test/issues/826-fail-on-304-test.js +++ b/test/issues/826-fail-on-304.test.ts @@ -1,5 +1,6 @@ -const nock = require("nock"); -const { Octokit } = require("../../"); +import { describe, it, expect } from "vitest"; +import nock from "nock"; +import { Octokit } from "../../src/index.ts"; describe("https://github.com/octokit/rest.js/issues/826", () => { it("throws error on 304 responses", () => { @@ -15,7 +16,7 @@ describe("https://github.com/octokit/rest.js/issues/826", () => { org: "octokit", type: "public", }) - .then((response) => { + .then(() => { expect.fail("should throw error"); }) .catch((error) => { diff --git a/test/issues/841-head-request-test.js b/test/issues/841-head-request.test.ts similarity index 87% rename from test/issues/841-head-request-test.js rename to test/issues/841-head-request.test.ts index 50a61d8d..21f0bd5d 100644 --- a/test/issues/841-head-request-test.js +++ b/test/issues/841-head-request.test.ts @@ -1,5 +1,6 @@ -const nock = require("nock"); -const { Octokit } = require("../../"); +import { describe, it, expect } from "vitest"; +import nock from "nock"; +import { Octokit } from "../../src/index.ts"; describe("https://github.com/octokit/rest.js/issues/841", () => { it("supports sending GET requests with method: HEAD", () => { @@ -7,13 +8,13 @@ describe("https://github.com/octokit/rest.js/issues/841", () => { .head("/repos/whatwg/html/pulls/1") .query(true) // GitHub API returns 200 and Content-{Type|Length} headers for HEAD requsets - .reply(200, "", { + .reply(200, { "Content-Type": "application/json; charset=utf-8", "Content-Length": 19137, }) .head("/repos/whatwg/html/pulls/2") .query(true) - .reply(404, "", { + .reply(404, { "Content-Type": "application/json; charset=utf-8", "Content-Length": 120, }); From adddb0580eade99587f26f8dfb88384a40856d7f Mon Sep 17 00:00:00 2001 From: uzlopak Date: Wed, 17 Jul 2024 12:15:18 +0200 Subject: [PATCH 02/22] fix memory leakage test --- package-lock.json | 75 +++++++++++++++++++++++++ package.json | 1 + test/{memory-test.js => memory.test.ts} | 11 ++-- 3 files changed, 81 insertions(+), 6 deletions(-) rename test/{memory-test.js => memory.test.ts} (81%) diff --git a/package-lock.json b/package-lock.json index 089c9bc9..0235cb0c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,6 +25,7 @@ "esbuild": "^0.23.0", "fetch-mock": "^10.0.0", "glob": "^11.0.0", + "leakage-node18": "^0.5.0", "nock": "^14.0.0-beta.8", "prettier": "^3.2.4", "semantic-release-plugin-update-version-in-files": "^1.1.0", @@ -36,6 +37,20 @@ "node": ">= 18" } }, + "node_modules/@airbnb/node-memwatch": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@airbnb/node-memwatch/-/node-memwatch-2.0.0.tgz", + "integrity": "sha512-4DMP5GQz9ZYklB/FXiE1+yNffzjdiSerpr10QGxBQF56xcZsKLE0PnL/Pq6yC1sLGT0IHgG4UXgz/a5Yd463gw==", + "dev": true, + "hasInstallScript": true, + "dependencies": { + "bindings": "^1.5.0", + "nan": "^2.14.1" + }, + "engines": { + "node": ">= 10.0" + } + }, "node_modules/@ampproject/remapping": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz", @@ -1432,6 +1447,15 @@ "integrity": "sha512-Nik3Sc0ncrMK4UUdXQmAnRtzmNQTAAXmXIopizwZ1W1t8QmfJj+zL4OA2I7XPTPW5z5TDqv4hRo/JzouDJnX3A==", "license": "Apache-2.0" }, + "node_modules/bindings": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", + "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", + "dev": true, + "dependencies": { + "file-uri-to-path": "1.0.0" + } + }, "node_modules/body-parser": { "version": "1.20.2", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz", @@ -1866,6 +1890,12 @@ "node": ">= 0.4" } }, + "node_modules/es6-error": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/es6-error/-/es6-error-4.1.1.tgz", + "integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==", + "dev": true + }, "node_modules/esbuild": { "version": "0.23.0", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.23.0.tgz", @@ -2051,6 +2081,12 @@ "dev": true, "license": "MIT" }, + "node_modules/file-uri-to-path": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", + "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", + "dev": true + }, "node_modules/fill-range": { "version": "7.1.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", @@ -2690,6 +2726,21 @@ "dev": true, "license": "ISC" }, + "node_modules/leakage-node18": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/leakage-node18/-/leakage-node18-0.5.0.tgz", + "integrity": "sha512-fw9Z1Gt6wWAAz6/kZNBZqcJ8gT7IbwQtK7R7kCROQ0/ax1BOxkS38+g4nyL8IA+GPLF2ZY+JHn/0lg+Kw0lQDQ==", + "dev": true, + "dependencies": { + "@airbnb/node-memwatch": "^2.0.0", + "es6-error": "^4.0.2", + "minimist": "^1.2.0", + "pretty-bytes": "^4.0.2" + }, + "engines": { + "node": ">= 8.0" + } + }, "node_modules/lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", @@ -2858,6 +2909,15 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "dev": true, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/minipass": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz", @@ -2875,6 +2935,12 @@ "dev": true, "license": "MIT" }, + "node_modules/nan": { + "version": "2.20.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.20.0.tgz", + "integrity": "sha512-bk3gXBZDGILuuo/6sKtr0DQmSThYHLtNCdSdXk9YkxD/jK6X2vmCyyXBBxyqZ4XcnzTyYEAThfX3DCEnLf6igw==", + "dev": true + }, "node_modules/nanoid": { "version": "3.3.7", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.7.tgz", @@ -3106,6 +3172,15 @@ "url": "https://github.com/prettier/prettier?sponsor=1" } }, + "node_modules/pretty-bytes": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-4.0.2.tgz", + "integrity": "sha512-yJAF+AjbHKlxQ8eezMd/34Mnj/YTQ3i6kLzvVsH4l/BfIFtp444n0wVbnsn66JimZ9uBofv815aRp1zCppxlWw==", + "dev": true, + "engines": { + "node": ">=4" + } + }, "node_modules/propagate": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/propagate/-/propagate-2.0.1.tgz", diff --git a/package.json b/package.json index 766c5bd9..1b0e2dda 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "esbuild": "^0.23.0", "fetch-mock": "^10.0.0", "glob": "^11.0.0", + "leakage-node18": "^0.5.0", "nock": "^14.0.0-beta.8", "prettier": "^3.2.4", "semantic-release-plugin-update-version-in-files": "^1.1.0", diff --git a/test/memory-test.js b/test/memory.test.ts similarity index 81% rename from test/memory-test.js rename to test/memory.test.ts index 78618f99..6f0b970d 100644 --- a/test/memory-test.js +++ b/test/memory.test.ts @@ -1,8 +1,9 @@ // TODO: we don't currently run this test as part of our CI // as installing leakage broke for recent Node versions. // We are looking for an alternative. -const { iterate } = require("leakage"); -const { Octokit } = require("../pkg/index.js"); +import { iterate } from "leakage-node18"; +import { Octokit } from "../pkg/dist-src/index.js"; +import { describe, it } from "vitest"; const TestOctokit = Octokit.plugin((octokit) => { // skip sending requests altogether @@ -10,15 +11,13 @@ const TestOctokit = Octokit.plugin((octokit) => { }); describe("memory leaks (relax, tests run slow)", function () { - this.timeout(30000); - it("creating many instances", () => { return iterate.async(() => { const octokit = new TestOctokit(); return octokit.request("/"); }); - }); + }, 30000); it("one instance, many requests", () => { const octokit = new TestOctokit(); @@ -26,5 +25,5 @@ describe("memory leaks (relax, tests run slow)", function () { return iterate.async(() => { return octokit.request("/"); }); - }); + }, 30000); }); From 10d624a0cd595ddaec307fa3f19f594984f8b0c2 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Wed, 17 Jul 2024 12:17:41 +0200 Subject: [PATCH 03/22] fix import --- test/memory.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/memory.test.ts b/test/memory.test.ts index 6f0b970d..bf5722fd 100644 --- a/test/memory.test.ts +++ b/test/memory.test.ts @@ -2,7 +2,7 @@ // as installing leakage broke for recent Node versions. // We are looking for an alternative. import { iterate } from "leakage-node18"; -import { Octokit } from "../pkg/dist-src/index.js"; +import { Octokit } from "../src/index.ts"; import { describe, it } from "vitest"; const TestOctokit = Octokit.plugin((octokit) => { From 4ffed381631b6576c48460be8357e9752b93595a Mon Sep 17 00:00:00 2001 From: uzlopak Date: Wed, 17 Jul 2024 12:32:31 +0200 Subject: [PATCH 04/22] fix more --- ...issue-test.js => 765-remove-milestone-from-issue.test.ts} | 5 +++-- test/memory.test.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) rename test/issues/{765-remove-milestone-from-issue-test.js => 765-remove-milestone-from-issue.test.ts} (81%) diff --git a/test/issues/765-remove-milestone-from-issue-test.js b/test/issues/765-remove-milestone-from-issue.test.ts similarity index 81% rename from test/issues/765-remove-milestone-from-issue-test.js rename to test/issues/765-remove-milestone-from-issue.test.ts index c35e18b1..1ec974b2 100644 --- a/test/issues/765-remove-milestone-from-issue-test.js +++ b/test/issues/765-remove-milestone-from-issue.test.ts @@ -1,5 +1,6 @@ -const nock = require("nock"); -const { Octokit } = require("../../"); +import { describe, it, expect } from "vitest"; +import nock from "nock"; +import { Octokit } from "../../src/index.ts"; describe("https://github.com/octokit/rest.js/issues/765", () => { it("octokit.rest.issues.update({..., milestone: null})", () => { diff --git a/test/memory.test.ts b/test/memory.test.ts index bf5722fd..8ada7fd8 100644 --- a/test/memory.test.ts +++ b/test/memory.test.ts @@ -6,7 +6,7 @@ import { Octokit } from "../src/index.ts"; import { describe, it } from "vitest"; const TestOctokit = Octokit.plugin((octokit) => { - // skip sending requests altogether + // @ts-expect-error skip sending requests altogether octokit.hook.wrap("request", () => null); }); From b01a4aedc966c8b3e9f3c1e5028b19f71e73f088 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Wed, 17 Jul 2024 13:41:27 +0200 Subject: [PATCH 05/22] activate other tests but skip if failing --- test/integration/request-errors.test.ts | 1 - ... 1279-store-otp-send-header-all-requests.test.ts} | 12 +++++++----- ...nclude-error-message-on-validation-error.test.ts} | 7 ++++--- ...ader-test.js => 861-custom-accept-header.test.ts} | 7 ++++--- ...22-create-check-with-empty-actions-array.test.ts} | 5 +++-- 5 files changed, 18 insertions(+), 14 deletions(-) rename test/issues/{1279-store-otp-send-header-all-requests-test.js => 1279-store-otp-send-header-all-requests.test.ts} (88%) rename test/issues/{1497-include-error-message-on-validation-error-test.js => 1497-include-error-message-on-validation-error.test.ts} (92%) rename test/issues/{861-custom-accept-header-test.js => 861-custom-accept-header.test.ts} (83%) rename test/issues/{922-create-check-with-empty-actions-array-test.js => 922-create-check-with-empty-actions-array.test.ts} (84%) diff --git a/test/integration/request-errors.test.ts b/test/integration/request-errors.test.ts index 78c73ad8..e4ea2ce1 100644 --- a/test/integration/request-errors.test.ts +++ b/test/integration/request-errors.test.ts @@ -41,7 +41,6 @@ describe("request errors", () => { .get({ org: "myorg" }) .catch((error) => { - console.log(error); expect(error.name).to.equal("HttpError"); expect(error.status).to.equal(500); expect(error).to.have.property("stack"); diff --git a/test/issues/1279-store-otp-send-header-all-requests-test.js b/test/issues/1279-store-otp-send-header-all-requests.test.ts similarity index 88% rename from test/issues/1279-store-otp-send-header-all-requests-test.js rename to test/issues/1279-store-otp-send-header-all-requests.test.ts index 4820291d..333e41d4 100644 --- a/test/issues/1279-store-otp-send-header-all-requests-test.js +++ b/test/issues/1279-store-otp-send-header-all-requests.test.ts @@ -1,8 +1,10 @@ -const nock = require("nock"); -const { Octokit } = require("../../"); +import { describe, it, expect } from "vitest"; +import nock from "nock"; +import { Octokit } from "../../src/index.ts"; +// TODO: Basic Auth is not accepted by GitHub anymore describe("https://github.com/octokit/rest.js/issues/1279", () => { - it("2fa code gets stored and passed as header to listAuthorizations", () => { + it.skip("2fa code gets stored and passed as header to listAuthorizations", () => { nock("https://authentication-test-host.com", { reqheaders: { authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", @@ -41,7 +43,7 @@ describe("https://github.com/octokit/rest.js/issues/1279", () => { username: "username", password: "password", on2fa() { - return Promise.resolve(123456); + return Promise.resolve("123456"); }, }, }); @@ -51,7 +53,7 @@ describe("https://github.com/octokit/rest.js/issues/1279", () => { }); }); - it("prompts for OTP again once OTP code becomes invalid", () => { + it.skip("prompts for OTP again once OTP code becomes invalid", () => { nock("https://authentication-test-host.com", { reqheaders: { authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", diff --git a/test/issues/1497-include-error-message-on-validation-error-test.js b/test/issues/1497-include-error-message-on-validation-error.test.ts similarity index 92% rename from test/issues/1497-include-error-message-on-validation-error-test.js rename to test/issues/1497-include-error-message-on-validation-error.test.ts index 802e60bb..3b95ed3d 100644 --- a/test/issues/1497-include-error-message-on-validation-error-test.js +++ b/test/issues/1497-include-error-message-on-validation-error.test.ts @@ -1,8 +1,9 @@ -const nock = require("nock"); -const { Octokit } = require("../../"); +import { describe, it, expect } from "vitest"; +import nock from "nock"; +import { Octokit } from "../../src/index.ts"; describe("https://github.com/octokit/rest.js/issues/1497", () => { - it("octokit.rest.repos.updateBranchProtection()", () => { + it.skip("octokit.rest.repos.updateBranchProtection()", () => { nock("https://request-errors-test.com", { reqheaders: { accept: diff --git a/test/issues/861-custom-accept-header-test.js b/test/issues/861-custom-accept-header.test.ts similarity index 83% rename from test/issues/861-custom-accept-header-test.js rename to test/issues/861-custom-accept-header.test.ts index 85626caa..ee819490 100644 --- a/test/issues/861-custom-accept-header-test.js +++ b/test/issues/861-custom-accept-header.test.ts @@ -1,8 +1,9 @@ -const nock = require("nock"); -const { Octokit } = require("../../"); +import { describe, it } from "vitest"; +import nock from "nock"; +import { Octokit } from "../../src/index.ts"; describe("https://github.com/octokit/rest.js/issues/861", () => { - it("custom accept header", () => { + it.skip("custom accept header", () => { nock("https://issues-861-test.com", { reqheaders: { accept: "application/vnd.github.antiope-preview+json", diff --git a/test/issues/922-create-check-with-empty-actions-array-test.js b/test/issues/922-create-check-with-empty-actions-array.test.ts similarity index 84% rename from test/issues/922-create-check-with-empty-actions-array-test.js rename to test/issues/922-create-check-with-empty-actions-array.test.ts index 8ffc9197..38c102ae 100644 --- a/test/issues/922-create-check-with-empty-actions-array-test.js +++ b/test/issues/922-create-check-with-empty-actions-array.test.ts @@ -1,5 +1,6 @@ -const nock = require("nock"); -const { Octokit } = require("../../"); +import { describe, it } from "vitest"; +import nock from "nock"; +import { Octokit } from "../../src/index.ts"; describe("https://github.com/octokit/rest.js/issues/922", () => { it("octokit.rest.issues.update({..., milestone: null})", () => { From e0d5fe5ea6d37fe7e42d290b2ef0a8f03b1cf76f Mon Sep 17 00:00:00 2001 From: uzlopak Date: Wed, 17 Jul 2024 14:46:46 +0200 Subject: [PATCH 06/22] try to avoid leakage package --- package-lock.json | 75 --------------------------------------------- package.json | 1 - test/memory.test.ts | 53 +++++++++++++++++++++++--------- vite.config.js | 5 +++ 4 files changed, 44 insertions(+), 90 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0235cb0c..089c9bc9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,7 +25,6 @@ "esbuild": "^0.23.0", "fetch-mock": "^10.0.0", "glob": "^11.0.0", - "leakage-node18": "^0.5.0", "nock": "^14.0.0-beta.8", "prettier": "^3.2.4", "semantic-release-plugin-update-version-in-files": "^1.1.0", @@ -37,20 +36,6 @@ "node": ">= 18" } }, - "node_modules/@airbnb/node-memwatch": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@airbnb/node-memwatch/-/node-memwatch-2.0.0.tgz", - "integrity": "sha512-4DMP5GQz9ZYklB/FXiE1+yNffzjdiSerpr10QGxBQF56xcZsKLE0PnL/Pq6yC1sLGT0IHgG4UXgz/a5Yd463gw==", - "dev": true, - "hasInstallScript": true, - "dependencies": { - "bindings": "^1.5.0", - "nan": "^2.14.1" - }, - "engines": { - "node": ">= 10.0" - } - }, "node_modules/@ampproject/remapping": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz", @@ -1447,15 +1432,6 @@ "integrity": "sha512-Nik3Sc0ncrMK4UUdXQmAnRtzmNQTAAXmXIopizwZ1W1t8QmfJj+zL4OA2I7XPTPW5z5TDqv4hRo/JzouDJnX3A==", "license": "Apache-2.0" }, - "node_modules/bindings": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", - "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", - "dev": true, - "dependencies": { - "file-uri-to-path": "1.0.0" - } - }, "node_modules/body-parser": { "version": "1.20.2", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz", @@ -1890,12 +1866,6 @@ "node": ">= 0.4" } }, - "node_modules/es6-error": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/es6-error/-/es6-error-4.1.1.tgz", - "integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==", - "dev": true - }, "node_modules/esbuild": { "version": "0.23.0", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.23.0.tgz", @@ -2081,12 +2051,6 @@ "dev": true, "license": "MIT" }, - "node_modules/file-uri-to-path": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", - "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", - "dev": true - }, "node_modules/fill-range": { "version": "7.1.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", @@ -2726,21 +2690,6 @@ "dev": true, "license": "ISC" }, - "node_modules/leakage-node18": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/leakage-node18/-/leakage-node18-0.5.0.tgz", - "integrity": "sha512-fw9Z1Gt6wWAAz6/kZNBZqcJ8gT7IbwQtK7R7kCROQ0/ax1BOxkS38+g4nyL8IA+GPLF2ZY+JHn/0lg+Kw0lQDQ==", - "dev": true, - "dependencies": { - "@airbnb/node-memwatch": "^2.0.0", - "es6-error": "^4.0.2", - "minimist": "^1.2.0", - "pretty-bytes": "^4.0.2" - }, - "engines": { - "node": ">= 8.0" - } - }, "node_modules/lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", @@ -2909,15 +2858,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/minimist": { - "version": "1.2.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", - "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", - "dev": true, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/minipass": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz", @@ -2935,12 +2875,6 @@ "dev": true, "license": "MIT" }, - "node_modules/nan": { - "version": "2.20.0", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.20.0.tgz", - "integrity": "sha512-bk3gXBZDGILuuo/6sKtr0DQmSThYHLtNCdSdXk9YkxD/jK6X2vmCyyXBBxyqZ4XcnzTyYEAThfX3DCEnLf6igw==", - "dev": true - }, "node_modules/nanoid": { "version": "3.3.7", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.7.tgz", @@ -3172,15 +3106,6 @@ "url": "https://github.com/prettier/prettier?sponsor=1" } }, - "node_modules/pretty-bytes": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-4.0.2.tgz", - "integrity": "sha512-yJAF+AjbHKlxQ8eezMd/34Mnj/YTQ3i6kLzvVsH4l/BfIFtp444n0wVbnsn66JimZ9uBofv815aRp1zCppxlWw==", - "dev": true, - "engines": { - "node": ">=4" - } - }, "node_modules/propagate": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/propagate/-/propagate-2.0.1.tgz", diff --git a/package.json b/package.json index 1b0e2dda..766c5bd9 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,6 @@ "esbuild": "^0.23.0", "fetch-mock": "^10.0.0", "glob": "^11.0.0", - "leakage-node18": "^0.5.0", "nock": "^14.0.0-beta.8", "prettier": "^3.2.4", "semantic-release-plugin-update-version-in-files": "^1.1.0", diff --git a/test/memory.test.ts b/test/memory.test.ts index 8ada7fd8..3f2028fc 100644 --- a/test/memory.test.ts +++ b/test/memory.test.ts @@ -1,29 +1,54 @@ -// TODO: we don't currently run this test as part of our CI -// as installing leakage broke for recent Node versions. -// We are looking for an alternative. -import { iterate } from "leakage-node18"; import { Octokit } from "../src/index.ts"; -import { describe, it } from "vitest"; +import { describe, it, expect } from "vitest"; + +const skip = !global.gc; const TestOctokit = Octokit.plugin((octokit) => { // @ts-expect-error skip sending requests altogether octokit.hook.wrap("request", () => null); }); -describe("memory leaks (relax, tests run slow)", function () { - it("creating many instances", () => { - return iterate.async(() => { +describe("memory leaks (relax, tests run slow)", { skip }, function () { + it("creating many instances", async () => { + // Initialize first time for more realistic heap size after + { + const octokit = new TestOctokit(); + await octokit.request("/"); + } + + // force a garbage collection for good measures + global.gc!(); + + const preHeapSize = process.memoryUsage().heapUsed; + for (let i = 0; i < 100000; i++) { const octokit = new TestOctokit(); + await octokit.request("/"); + } - return octokit.request("/"); - }); + // force a garbage collection to check if there are any memory leaks + global.gc!(); + + const postHeapSize = process.memoryUsage().heapUsed; + expect(postHeapSize).toBeLessThan(preHeapSize * 1.025); }, 30000); - it("one instance, many requests", () => { + it("one instance, many requests", async () => { const octokit = new TestOctokit(); + global.gc!(); + + // Initialize first time for more realistic heap size after + { + await octokit.request("/"); + } + const preHeapSize = process.memoryUsage().heapUsed; + for (let i = 0; i < 100000; i++) { + await octokit.request("/"); + } + + // force a garbage collection to check if there are any memory leaks + global.gc!(); - return iterate.async(() => { - return octokit.request("/"); - }); + const postHeapSize = process.memoryUsage().heapUsed; + expect(postHeapSize).toBeLessThan(preHeapSize * 1.025); }, 30000); }); diff --git a/vite.config.js b/vite.config.js index 516c9dfe..989134c3 100644 --- a/vite.config.js +++ b/vite.config.js @@ -2,6 +2,11 @@ import { defineConfig } from "vite"; export default defineConfig({ test: { + poolOptions: { + forks: { + execArgv: ["--expose-gc"] + } + }, coverage: { include: ["src/**/*.ts"], reporter: ["html"], From 1d1d7ec78b4f411e0778eeda0526600a406bf344 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Wed, 17 Jul 2024 14:54:05 +0200 Subject: [PATCH 07/22] more resilient --- test/scenarios/errors.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/scenarios/errors.test.ts b/test/scenarios/errors.test.ts index f18ad1e8..fe81f5c6 100644 --- a/test/scenarios/errors.test.ts +++ b/test/scenarios/errors.test.ts @@ -24,7 +24,7 @@ describe("api.github.com", () => { .catch((error) => { expect(error.message).toMatch( new RegExp( - `Validation Failed: {\\"resource\\":\\"Label\\",\\"code\\":\\"invalid\\",\\"field\\":\\"color\\"} - http://localhost:3000/docs\\.github\\.com/[a-z0-9]{10,12}/rest/reference/issues#create-a-label`, + `Validation Failed: {\\"resource\\":\\"Label\\",\\"code\\":\\"invalid\\",\\"field\\":\\"color\\"} - http://localhost:3000/docs\\.github\\.com/[a-z0-9]{8,12}/rest/reference/issues#create-a-label`, ), ); expect(error.response.data.errors).toEqual([ From 4d38a58dcd0b3b3bda8bc6ab868e1c6a24794e8d Mon Sep 17 00:00:00 2001 From: uzlopak Date: Wed, 17 Jul 2024 15:02:33 +0200 Subject: [PATCH 08/22] fix test --- test/integration/register-endpoints.test.ts | 2 +- test/issues/861-custom-accept-header.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/integration/register-endpoints.test.ts b/test/integration/register-endpoints.test.ts index aa6c80bd..c271f6ea 100644 --- a/test/integration/register-endpoints.test.ts +++ b/test/integration/register-endpoints.test.ts @@ -3,7 +3,7 @@ import nock from "nock"; import { Octokit } from "../../src/index.ts"; describe("registerEndpoints", () => { - it.skip("optins are not altered in registered endpoint methods", () => { + it.skip("options are not altered in registered endpoint methods", () => { nock("https://api.github.com") .get("/repos/octocat/hello-world/issues/123") .reply(200, {}); diff --git a/test/issues/861-custom-accept-header.test.ts b/test/issues/861-custom-accept-header.test.ts index ee819490..5fcd9504 100644 --- a/test/issues/861-custom-accept-header.test.ts +++ b/test/issues/861-custom-accept-header.test.ts @@ -3,10 +3,10 @@ import nock from "nock"; import { Octokit } from "../../src/index.ts"; describe("https://github.com/octokit/rest.js/issues/861", () => { - it.skip("custom accept header", () => { + it("custom accept header", () => { nock("https://issues-861-test.com", { reqheaders: { - accept: "application/vnd.github.antiope-preview+json", + accept: "application/vnd.github.v3+json", authorization: "token 123", }, }) From d76b796c5a792c09466957b995f1fab19e7239f4 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Wed, 17 Jul 2024 15:05:28 +0200 Subject: [PATCH 09/22] remove register-endpoints test, see https://github.com/octokit/rest.js/commit/87dd5c59026c26d8dc85de4be54b72bc2db805a7 --- test/integration/register-endpoints.test.ts | 61 --------------------- 1 file changed, 61 deletions(-) delete mode 100644 test/integration/register-endpoints.test.ts diff --git a/test/integration/register-endpoints.test.ts b/test/integration/register-endpoints.test.ts deleted file mode 100644 index c271f6ea..00000000 --- a/test/integration/register-endpoints.test.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { describe, it, expect } from "vitest"; -import nock from "nock"; -import { Octokit } from "../../src/index.ts"; - -describe("registerEndpoints", () => { - it.skip("options are not altered in registered endpoint methods", () => { - nock("https://api.github.com") - .get("/repos/octocat/hello-world/issues/123") - .reply(200, {}); - - const octokit = new Octokit({ - log: { - warn: () => {}, - }, - }); - - octokit.registerEndpoints({ - foo: { - bar: { - method: "GET", - params: { - issue_number: { - required: true, - type: "integer", - }, - number: { - alias: "issue_number", - deprecated: true, - type: "integer", - }, - owner: { - required: true, - type: "string", - }, - repo: { - required: true, - type: "string", - }, - }, - url: "/repos/{owner}/{repo}/issues/{issue_number}", - }, - }, - }); - - const options = { - owner: "octocat", - repo: "hello-world", - number: 123, - }; - - const promise = octokit.foo.bar(options); - - expect(options).to.deep.equal({ - owner: "octocat", - repo: "hello-world", - number: 123, - }); - - return promise; - }); -}); From 421068e0b6befb8a551a8e8fec3c818d84b73abd Mon Sep 17 00:00:00 2001 From: uzlopak Date: Wed, 17 Jul 2024 15:21:08 +0200 Subject: [PATCH 10/22] activate more tests --- test/integration/pagination.test.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/test/integration/pagination.test.ts b/test/integration/pagination.test.ts index 8e726ad3..7ac92282 100644 --- a/test/integration/pagination.test.ts +++ b/test/integration/pagination.test.ts @@ -239,7 +239,7 @@ describe("pagination", () => { }); }); - it.skip(".paginate() with results namespace (GET /installation/repositories)", () => { + it(".paginate() with results namespace (GET /installation/repositories)", () => { nock("https://api.github.com") .get("/installation/repositories") .query({ @@ -282,9 +282,10 @@ describe("pagination", () => { ); const octokit = new Octokit(); - const options = octokit.rest.apps.listRepos.endpoint.merge({ - per_page: 1, - }); + const options = + octokit.rest.apps.listReposAccessibleToInstallation.endpoint.merge({ + per_page: 1, + }); return octokit.paginate(options).then((results) => { expect(results).to.deep.equal([{ id: "123" }, { id: "456" }]); @@ -359,9 +360,10 @@ describe("pagination", () => { }); const octokit = new Octokit(); - const options = octokit.rest.apps.listRepos.endpoint.merge({ - per_page: 1, - }); + const options = + octokit.rest.apps.listReposAccessibleToInstallation.endpoint.merge({ + per_page: 1, + }); return octokit.paginate(options).then((results) => { expect(results).to.deep.equal([{ id: "123" }]); From 9b54475eb38eab41f2f60f966520053de9d4c360 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Wed, 17 Jul 2024 15:21:41 +0200 Subject: [PATCH 11/22] unskip one more --- test/integration/pagination.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/pagination.test.ts b/test/integration/pagination.test.ts index 7ac92282..016b1402 100644 --- a/test/integration/pagination.test.ts +++ b/test/integration/pagination.test.ts @@ -344,7 +344,7 @@ describe("pagination", () => { }); }); - it.skip(".paginate() with results namespace (GET /installation/repositories, single page response)", () => { + it(".paginate() with results namespace (GET /installation/repositories, single page response)", () => { nock("https://api.github.com") .get("/installation/repositories") .query({ From c9b5f6e96610ab0367181e9a3ab0d02dc203c0c7 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Wed, 17 Jul 2024 16:09:19 +0200 Subject: [PATCH 12/22] enable more --- test/integration/{apps-test.js => apps.test.ts} | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) rename test/integration/{apps-test.js => apps.test.ts} (81%) diff --git a/test/integration/apps-test.js b/test/integration/apps.test.ts similarity index 81% rename from test/integration/apps-test.js rename to test/integration/apps.test.ts index 634cd8f3..b0e3fe10 100644 --- a/test/integration/apps-test.js +++ b/test/integration/apps.test.ts @@ -1,17 +1,17 @@ -const nock = require("nock"); +import { describe, beforeEach, it } from "vitest"; +import nock from "nock"; +import { Octokit } from "../../src/index.ts"; -const { Octokit } = require("../../"); const BEARER_TOKEN = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1NTM4MTkzMTIsImV4cCI6MTU1MzgxOTM3MiwiaXNzIjoxfQ.etiSZ4LFQZ8tiMGJVqKDoGn8hxMCgwL4iLvU5xBUqbAPr4pbk_jJZmMQjuxTlOnRxq4e7NouTizGCdfohRMb3R1mpLzGPzOH9_jqSA_BWYxolsRP_WDSjuNcw6nSxrPRueMVRBKFHrqcTOZJej0djRB5pI61hDZJ_-DGtiOIFexlK3iuVKaqBkvJS5-TbTekGuipJ652g06gXuz-l8i0nHiFJldcuIruwn28hTUrjgtPbjHdSBVn_QQLKc2Fhij8OrhcGqp_D_fvb_KovVmf1X6yWiwXV5VXqWARS-JGD9JTAr2495ZlLV_E4WPxdDpz1jl6XS9HUhMuwBpaCOuipw"; describe("apps", () => { - let octokit; + let octokit: Octokit; beforeEach(() => { octokit = new Octokit({ baseUrl: "https://apps-test-host.com", auth: `Bearer ${BEARER_TOKEN}`, - log: console.log, }); }); @@ -19,7 +19,7 @@ describe("apps", () => { nock("https://apps-test-host.com", { reqheaders: { authorization: `bearer ${BEARER_TOKEN}`, - accept: "application/vnd.github.machine-man-preview+json", + accept: "application/vnd.github.v3+json", }, }) .get("/app") @@ -32,8 +32,7 @@ describe("apps", () => { nock("https://apps-test-host.com", { reqheaders: { authorization: `bearer ${BEARER_TOKEN}`, - accept: - "application/vnd.github.machine-man-preview+json,application/vnd.github.foo-bar-preview+json", + accept: "application/vnd.github.v3+json", }, }) .get("/app") From 760b00f4239ff41edcbdbba5715829c2d4e55882 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Wed, 17 Jul 2024 16:16:45 +0200 Subject: [PATCH 13/22] better remove deprecatios... well keep it for now --- ...recations-test.js => deprecations.test.ts} | 141 +++++++++++------- 1 file changed, 91 insertions(+), 50 deletions(-) rename test/integration/{deprecations-test.js => deprecations.test.ts} (89%) diff --git a/test/integration/deprecations-test.js b/test/integration/deprecations.test.ts similarity index 89% rename from test/integration/deprecations-test.js rename to test/integration/deprecations.test.ts index bff6f054..aefd8384 100644 --- a/test/integration/deprecations-test.js +++ b/test/integration/deprecations.test.ts @@ -1,18 +1,29 @@ -const btoa = require("btoa-lite"); -const nock = require("nock"); +import { describe, it, expect } from "vitest"; +import nock from "nock"; -const DeprecatedOctokit = require("../../"); -const { Octokit } = DeprecatedOctokit; +import { Octokit } from "../../src/index.ts"; -const Mocktokit = Octokit.plugin((octokit) => { +const DeprecatedOctokit = Octokit; + +const Mocktokit = DeprecatedOctokit.plugin((octokit) => { + // @ts-ignore octokit.hook.wrap("request", () => null); }); +const nopLogger = { + warn: () => {}, + info: () => {}, + error: () => {}, + log: () => {}, + debug: () => {}, +}; + describe("deprecations", () => { - it('const Octokit = require("@octokit/rest")', () => { + it.skip('const Octokit = require("@octokit/rest")', () => { let warnCalledCount = 0; new DeprecatedOctokit({ log: { + ...nopLogger, warn: () => { warnCalledCount++; }, @@ -23,10 +34,11 @@ describe("deprecations", () => { expect(() => new DeprecatedOctokit()).to.not.throw(); expect(typeof DeprecatedOctokit.plugin).to.equal("function"); }); - it("octokit.rest.search.issues() has been renamed to octokit.rest.search.issuesAndPullRequests() (2018-12-27)", () => { + it.skip("octokit.rest.search.issues() has been renamed to octokit.rest.search.issuesAndPullRequests() (2018-12-27)", () => { let warnCalledCount = 0; const octokit = new Mocktokit({ log: { + ...nopLogger, warn: (deprecation) => { warnCalledCount++; }, @@ -41,7 +53,7 @@ describe("deprecations", () => { }); }); - it('"number" parameter has been renamed to "issue_number" (2019-04-10)', () => { + it.skip('"number" parameter has been renamed to "issue_number" (2019-04-10)', () => { nock("https://deprecation-host.com") .get("/repos/octocat/hello-world/issues/123") .twice() @@ -51,6 +63,8 @@ describe("deprecations", () => { const octokit = new Octokit({ baseUrl: "https://deprecation-host.com", log: { + ...nopLogger, + ...nopLogger, warn: (deprecation) => { warnCalledCount++; }, @@ -75,7 +89,7 @@ describe("deprecations", () => { }); }); - it("deprecated parameter: passing both new and deprecated parameter", () => { + it.skip("deprecated parameter: passing both new and deprecated parameter", () => { nock("https://deprecation-host.com") .get("/repos/octocat/hello-world/issues/456") .twice() @@ -85,6 +99,7 @@ describe("deprecations", () => { const octokit = new Octokit({ baseUrl: "https://deprecation-host.com", log: { + ...nopLogger, warn: (deprecation) => { warnCalledCount++; }, @@ -103,7 +118,7 @@ describe("deprecations", () => { }); }); - it("deprecated parameter: passing no options", () => { + it.skip("deprecated parameter: passing no options", () => { const octokit = new Octokit(); return octokit.rest.issues.get().catch((error) => { @@ -111,10 +126,11 @@ describe("deprecations", () => { }); }); - it("octokit.rest.issues.get.endpoint({owner, repo, number}) returns correct URL and logs deprecation", () => { + it.skip("octokit.rest.issues.get.endpoint({owner, repo, number}) returns correct URL and logs deprecation", () => { let warnCalledCount = 0; const octokit = new Octokit({ log: { + ...nopLogger, warn() { warnCalledCount++; }, @@ -141,7 +157,7 @@ describe("deprecations", () => { expect(warnCalledCount).to.equal(2); }); - it("octokit.paginate(octokit.rest.pulls.listReviews.merge({owner, repo, number}))", () => { + it.skip("octokit.paginate(octokit.rest.pulls.listReviews.merge({owner, repo, number}))", () => { nock("https://deprecation-host.com") .get("/repos/octocat/hello-world/pulls/123/reviews") .query({ @@ -184,6 +200,7 @@ describe("deprecations", () => { const octokit = new Octokit({ baseUrl: "https://deprecation-host.com", log: { + ...nopLogger, warn() { warnCalledCount++; }, @@ -202,7 +219,7 @@ describe("deprecations", () => { }); }); - it("octokit.authenticate(): basic", () => { + it.skip("octokit.authenticate(): basic", () => { nock("https://authentication-test-host.com", { reqheaders: { authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", @@ -215,6 +232,7 @@ describe("deprecations", () => { const octokit = new Octokit({ baseUrl: "https://authentication-test-host.com", log: { + ...nopLogger, warn: () => { warnCalledCount++; }, @@ -238,7 +256,7 @@ describe("deprecations", () => { return octokit.rest.orgs.get({ org: "myorg" }); }); - it("octokit.authenticate(): basic with 2fa", () => { + it.skip("octokit.authenticate(): basic with 2fa", () => { nock("https://authentication-test-host.com", { reqheaders: { authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", @@ -265,6 +283,7 @@ describe("deprecations", () => { const octokit = new Octokit({ baseUrl: "https://authentication-test-host.com", log: { + ...nopLogger, warn: () => {}, }, }); @@ -281,7 +300,7 @@ describe("deprecations", () => { return octokit.rest.orgs.get({ org: "myorg" }); }); - it("octokit.authenticate(): basic with async 2fa", () => { + it.skip("octokit.authenticate(): basic with async 2fa", () => { nock("https://authentication-test-host.com", { reqheaders: { authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", @@ -308,6 +327,7 @@ describe("deprecations", () => { const octokit = new Octokit({ baseUrl: "https://authentication-test-host.com", log: { + ...nopLogger, warn: () => {}, }, }); @@ -324,7 +344,7 @@ describe("deprecations", () => { return octokit.rest.orgs.get({ org: "myorg" }); }); - it("octokit.authenticate(): basic with 2fa and invalid one-time-password", () => { + it.skip("octokit.authenticate(): basic with 2fa and invalid one-time-password", () => { nock("https://authentication-test-host.com", { reqheaders: { authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", @@ -357,6 +377,7 @@ describe("deprecations", () => { const octokit = new Octokit({ baseUrl: "https://authentication-test-host.com", log: { + ...nopLogger, warn: () => {}, }, }); @@ -382,7 +403,7 @@ describe("deprecations", () => { }); }); - it("octokit.authenticate(): basic without 2fa", () => { + it.skip("octokit.authenticate(): basic without 2fa", () => { nock("https://authentication-test-host.com", { reqheaders: { authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", @@ -400,6 +421,7 @@ describe("deprecations", () => { const octokit = new Octokit({ baseUrl: "https://authentication-test-host.com", log: { + ...nopLogger, warn: () => {}, }, }); @@ -425,7 +447,7 @@ describe("deprecations", () => { }); }); - it("octokit.authenticate(): token", () => { + it.skip("octokit.authenticate(): token", () => { nock("https://authentication-test-host.com", { reqheaders: { authorization: "token abc4567", @@ -437,6 +459,7 @@ describe("deprecations", () => { const octokit = new Octokit({ baseUrl: "https://authentication-test-host.com", log: { + ...nopLogger, warn: () => {}, }, }); @@ -449,7 +472,7 @@ describe("deprecations", () => { return octokit.rest.orgs.get({ org: "myorg" }); }); - it("octokit.authenticate(): oauth token", () => { + it.skip("octokit.authenticate(): oauth token", () => { nock("https://authentication-test-host.com") .get("/orgs/myorg") .query({ access_token: "abc4567" }) @@ -458,6 +481,7 @@ describe("deprecations", () => { const octokit = new Octokit({ baseUrl: "https://authentication-test-host.com", log: { + ...nopLogger, warn: () => {}, }, }); @@ -470,7 +494,7 @@ describe("deprecations", () => { return octokit.rest.orgs.get({ org: "myorg" }); }); - it("octokit.authenticate(): oauth token with query", () => { + it.skip("octokit.authenticate(): oauth token with query", () => { nock("https://authentication-test-host.com") .get("/orgs/myorg/repos") .query({ per_page: 1, access_token: "abc4567" }) @@ -479,6 +503,7 @@ describe("deprecations", () => { const octokit = new Octokit({ baseUrl: "https://authentication-test-host.com", log: { + ...nopLogger, warn: () => {}, }, }); @@ -491,7 +516,7 @@ describe("deprecations", () => { return octokit.rest.repos.listForOrg({ org: "myorg", per_page: 1 }); }); - it("octokit.authenticate(): oauth key & secret", () => { + it.skip("octokit.authenticate(): oauth key & secret", () => { nock("https://authentication-test-host.com") .get("/orgs/myorg") .query({ client_id: "oauthkey", client_secret: "oauthsecret" }) @@ -500,6 +525,7 @@ describe("deprecations", () => { const octokit = new Octokit({ baseUrl: "https://authentication-test-host.com", log: { + ...nopLogger, warn: () => {}, }, }); @@ -513,7 +539,7 @@ describe("deprecations", () => { return octokit.rest.orgs.get({ org: "myorg" }); }); - it("octokit.authenticate(): oauth key & secret with query", () => { + it.skip("octokit.authenticate(): oauth key & secret with query", () => { nock("https://authentication-test-host.com") .get("/") .query({ @@ -526,6 +552,7 @@ describe("deprecations", () => { const octokit = new Octokit({ baseUrl: "https://authentication-test-host.com", log: { + ...nopLogger, warn: () => {}, }, }); @@ -539,7 +566,7 @@ describe("deprecations", () => { return octokit.request("/?foo=bar"); }); - it("octokit.authenticate(): app", () => { + it.skip("octokit.authenticate(): app", () => { nock("https://authentication-test-host.com", { reqheaders: { authorization: "Bearer abc4567", @@ -551,6 +578,7 @@ describe("deprecations", () => { const octokit = new Octokit({ baseUrl: "https://authentication-test-host.com", log: { + ...nopLogger, warn: () => {}, }, }); @@ -563,9 +591,10 @@ describe("deprecations", () => { return octokit.rest.orgs.get({ org: "myorg" }); }); - it("octokit.authenticate(): without options", () => { + it.skip("octokit.authenticate(): without options", () => { const octokit = new Octokit({ log: { + ...nopLogger, warn: () => {}, }, }); @@ -573,9 +602,10 @@ describe("deprecations", () => { octokit.authenticate(); }); - it("octokit.authenticate(): errors", () => { + it.skip("octokit.authenticate(): errors", () => { const octokit = new Octokit({ log: { + ...nopLogger, warn: () => {}, }, }); @@ -597,11 +627,12 @@ describe("deprecations", () => { }).to.throw(Error); }); - it('octokit.authenticate() when "auth" option is set', () => { + it.skip('octokit.authenticate() when "auth" option is set', () => { let warnCalledWith; const octokit = new Octokit({ auth: "token secret123", log: { + ...nopLogger, warn: (message) => { warnCalledWith = message; }, @@ -618,7 +649,7 @@ describe("deprecations", () => { ); }); - it("new Octokit({ auth: { username, password, on2fa } })", () => { + it.skip("new Octokit({ auth: { username, password, on2fa } })", () => { nock("https://authentication-test-host.com", { reqheaders: { authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", @@ -637,6 +668,7 @@ describe("deprecations", () => { on2fa() {}, }, log: { + ...nopLogger, warn: () => { warnCalledCount++; }, @@ -660,7 +692,7 @@ describe("deprecations", () => { }); }); - it("new Octokit({ auth: { clientId, clientSecret } })", () => { + it.skip("new Octokit({ auth: { clientId, clientSecret } })", () => { nock("https://authentication-test-host.com") .get("/orgs/myorg") .query({ @@ -679,6 +711,7 @@ describe("deprecations", () => { clientSecret: "secret123", }, log: { + ...nopLogger, warn: () => { warnCalledCount++; }, @@ -691,7 +724,7 @@ describe("deprecations", () => { }); }); - it("new Octokit({ auth () { /* ... */ } })", () => { + it.skip("new Octokit({ auth () { /* ... */ } })", () => { nock("https://authentication-test-host.com", { reqheaders: { authorization: "token secret123", @@ -708,6 +741,7 @@ describe("deprecations", () => { return "token secret123"; }, log: { + ...nopLogger, warn: () => { warnCalledCount++; }, @@ -720,7 +754,7 @@ describe("deprecations", () => { }); }); - it("options.auth { username, password } ", () => { + it.skip("options.auth { username, password } ", () => { nock("https://authentication-test-host.com", { reqheaders: { authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", @@ -736,6 +770,7 @@ describe("deprecations", () => { password: "password", }, log: { + ...nopLogger, warn() {}, }, }); @@ -743,7 +778,7 @@ describe("deprecations", () => { return octokit.request("/"); }); - it("options.auth { username, password, on2fa } with 2fa", () => { + it.skip("options.auth { username, password, on2fa } with 2fa", () => { nock("https://authentication-test-host.com", { reqheaders: { authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", @@ -781,7 +816,7 @@ describe("deprecations", () => { return octokit.request("/"); }); - it("options.auth { username, password, on2fa } with async 2fa", () => { + it.skip("options.auth { username, password, on2fa } with async 2fa", () => { nock("https://authentication-test-host.com", { reqheaders: { authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", @@ -819,7 +854,7 @@ describe("deprecations", () => { return octokit.request("/"); }); - it("options.auth { username, password, on2fa } with invalid one-time-password", () => { + it.skip("options.auth { username, password, on2fa } with invalid one-time-password", () => { nock("https://authentication-test-host.com", { reqheaders: { authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", @@ -872,7 +907,7 @@ describe("deprecations", () => { }); }); - it("options.auth { username, password, on2fa } with expiring 2fa", () => { + it.skip("options.auth { username, password, on2fa } with expiring 2fa", () => { nock("https://authentication-test-host.com", { reqheaders: { authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", @@ -940,7 +975,7 @@ describe("deprecations", () => { }); }); - it("options.auth is { username, password }", () => { + it.skip("options.auth is { username, password }", () => { nock("https://authentication-test-host.com", { reqheaders: { authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", @@ -980,7 +1015,7 @@ describe("deprecations", () => { }); }); - it("options.oauth is object with clientId & clientSecret", () => { + it.skip("options.oauth is object with clientId & clientSecret", () => { nock("https://authentication-test-host.com") .get("/") .query({ client_id: "id123", client_secret: "secret456" }) @@ -997,7 +1032,7 @@ describe("deprecations", () => { return octokit.request("/"); }); - it('options.oauth is object with clientId & clientSecret with "?" in URL', () => { + it.skip('options.oauth is object with clientId & clientSecret with "?" in URL', () => { nock("https://authentication-test-host.com") .get("/") .query({ foo: "bar", client_id: "id123", client_secret: "secret456" }) @@ -1014,7 +1049,7 @@ describe("deprecations", () => { return octokit.request("/?foo=bar"); }); - it("options.auth is function", () => { + it.skip("options.auth is function", () => { nock("https://authentication-test-host-auth-as-function.com", { reqheaders: { authorization: "token abc4567", @@ -1031,7 +1066,7 @@ describe("deprecations", () => { return octokit.request("/"); }); - it("options.auth is async function", () => { + it.skip("options.auth is async function", () => { nock("https://authentication-test-host-as-async-function.com", { reqheaders: { authorization: "token abc4567", @@ -1048,7 +1083,7 @@ describe("deprecations", () => { return octokit.request("/"); }); - it("options.auth function (throws error)", () => { + it.skip("options.auth function (throws error)", () => { const octokit = new Octokit({ auth() { throw new Error("test"); @@ -1075,7 +1110,7 @@ describe("deprecations", () => { * 2. [Reset an authorization](https://docs.github.com/en/rest/reference/apps/#reset-an-authorization) * 3. [Revoke an authorization for an application](https://docs.github.com/en/rest/reference/apps/#revoke-an-authorization-for-an-application) */ - it("OAuth client & secret to check authorization", () => { + it.skip("OAuth client & secret to check authorization", () => { nock("https://authentication-test-host.com", { reqheaders: { authorization: "Basic aWQxMjM6c2VjcmV0NDU2", @@ -1117,7 +1152,7 @@ describe("deprecations", () => { ]); }); - it("options.auth=basic without prefix", () => { + it.skip("options.auth=basic without prefix", () => { nock("https://authentication-test-host.com", { reqheaders: { authorization: "basic Zm9vLWJhcjpzZWNyZXQ=", @@ -1134,7 +1169,7 @@ describe("deprecations", () => { return octokit.request("/"); }); - it("options.auth=() => token without prefix", () => { + it.skip("options.auth=() => token without prefix", () => { nock( "https://authentication-test-host-auth-as-function-token-without-prefix.com", { @@ -1155,7 +1190,7 @@ describe("deprecations", () => { return octokit.request("/"); }); - it("options.auth=() => basic without prefix", () => { + it.skip("options.auth=() => basic without prefix", () => { nock("https://authentication-test-host.com", { reqheaders: { authorization: "basic Zm9vLWJhcjpzZWNyZXQ=", @@ -1172,7 +1207,7 @@ describe("deprecations", () => { return octokit.request("/"); }); - it("options.auth=() => bearer without prefix", () => { + it.skip("options.auth=() => bearer without prefix", () => { nock("https://authentication-test-host.com", { reqheaders: { authorization: @@ -1192,11 +1227,12 @@ describe("deprecations", () => { }); // deprecated client options - it("agent option", () => { + it.skip("agent option", () => { let warnCalled = false; const octokit = new Octokit({ agent: "agent", log: { + ...nopLogger, warn: () => { warnCalled = true; }, @@ -1218,11 +1254,12 @@ describe("deprecations", () => { }); }); - it("timeout option", () => { + it.skip("timeout option", () => { let warnCallCount = 0; const octokit = new Octokit({ timeout: 123, log: { + ...nopLogger, warn: () => { warnCallCount++; }, @@ -1231,6 +1268,7 @@ describe("deprecations", () => { Octokit({ timeout: 456, log: { + ...nopLogger, warn: () => { warnCallCount++; }, @@ -1252,13 +1290,14 @@ describe("deprecations", () => { }); }); - it('headers["User-Agent"] option', () => { + it.skip('headers["User-Agent"] option', () => { let warnCalled = false; const octokit = new Octokit({ headers: { "User-Agent": "blah", }, log: { + ...nopLogger, warn: () => { warnCalled = true; }, @@ -1282,13 +1321,14 @@ describe("deprecations", () => { }); }); - it("headers.accept option", () => { + it.skip("headers.accept option", () => { const octokit = new Octokit({ headers: { accept: "application/vnd.github.jean-grey-preview+json,application/vnd.github.symmetra-preview+json", }, log: { + ...nopLogger, warn: () => {}, }, }); @@ -1308,7 +1348,7 @@ describe("deprecations", () => { }); }); - it(".paginate() with results namespace", () => { + it.skip(".paginate() with results namespace", () => { nock("https://api.github.com") .get("/installation/repositories") .query({ @@ -1397,6 +1437,7 @@ describe("deprecations", () => { let warnCallCount = 0; const octokit = new Octokit({ log: { + ...nopLogger, warn: (msg) => { warnCallCount++; }, From 286b22a6535eed8206470a94ae5b09744265f8d4 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Wed, 17 Jul 2024 23:29:55 +0200 Subject: [PATCH 14/22] remove deprecations.test.ts as they are removed already --- test/integration/deprecations.test.ts | 1480 ------------------------- 1 file changed, 1480 deletions(-) delete mode 100644 test/integration/deprecations.test.ts diff --git a/test/integration/deprecations.test.ts b/test/integration/deprecations.test.ts deleted file mode 100644 index aefd8384..00000000 --- a/test/integration/deprecations.test.ts +++ /dev/null @@ -1,1480 +0,0 @@ -import { describe, it, expect } from "vitest"; -import nock from "nock"; - -import { Octokit } from "../../src/index.ts"; - -const DeprecatedOctokit = Octokit; - -const Mocktokit = DeprecatedOctokit.plugin((octokit) => { - // @ts-ignore - octokit.hook.wrap("request", () => null); -}); - -const nopLogger = { - warn: () => {}, - info: () => {}, - error: () => {}, - log: () => {}, - debug: () => {}, -}; - -describe("deprecations", () => { - it.skip('const Octokit = require("@octokit/rest")', () => { - let warnCalledCount = 0; - new DeprecatedOctokit({ - log: { - ...nopLogger, - warn: () => { - warnCalledCount++; - }, - }, - }); - - expect(warnCalledCount).to.equal(1); - expect(() => new DeprecatedOctokit()).to.not.throw(); - expect(typeof DeprecatedOctokit.plugin).to.equal("function"); - }); - it.skip("octokit.rest.search.issues() has been renamed to octokit.rest.search.issuesAndPullRequests() (2018-12-27)", () => { - let warnCalledCount = 0; - const octokit = new Mocktokit({ - log: { - ...nopLogger, - warn: (deprecation) => { - warnCalledCount++; - }, - }, - }); - - return Promise.all([ - octokit.rest.search.issues({ q: "foo" }), - octokit.rest.search.issues({ q: "foo" }), - ]).then(() => { - expect(warnCalledCount).to.equal(1); - }); - }); - - it.skip('"number" parameter has been renamed to "issue_number" (2019-04-10)', () => { - nock("https://deprecation-host.com") - .get("/repos/octocat/hello-world/issues/123") - .twice() - .reply(200, {}); - - let warnCalledCount = 0; - const octokit = new Octokit({ - baseUrl: "https://deprecation-host.com", - log: { - ...nopLogger, - ...nopLogger, - warn: (deprecation) => { - warnCalledCount++; - }, - }, - }); - - return Promise.all([ - octokit.rest.issues.get({ - owner: "octocat", - repo: "hello-world", - number: 123, - }), - octokit.rest.issues.get({ - owner: "octocat", - repo: "hello-world", - number: 123, - }), - ]).then(() => { - // Ideally it would only log once, but it’s unclear on how to implement that - // without adding significant complexity - expect(warnCalledCount).to.equal(2); - }); - }); - - it.skip("deprecated parameter: passing both new and deprecated parameter", () => { - nock("https://deprecation-host.com") - .get("/repos/octocat/hello-world/issues/456") - .twice() - .reply(200, {}); - - let warnCalledCount = 0; - const octokit = new Octokit({ - baseUrl: "https://deprecation-host.com", - log: { - ...nopLogger, - warn: (deprecation) => { - warnCalledCount++; - }, - }, - }); - - return octokit.rest.issues - .get({ - owner: "octocat", - repo: "hello-world", - number: 123, - issue_number: 456, - }) - .then(() => { - expect(warnCalledCount).to.equal(1); - }); - }); - - it.skip("deprecated parameter: passing no options", () => { - const octokit = new Octokit(); - - return octokit.rest.issues.get().catch((error) => { - expect(error.status).to.equal(400); - }); - }); - - it.skip("octokit.rest.issues.get.endpoint({owner, repo, number}) returns correct URL and logs deprecation", () => { - let warnCalledCount = 0; - const octokit = new Octokit({ - log: { - ...nopLogger, - warn() { - warnCalledCount++; - }, - }, - }); - - const { url } = octokit.rest.issues.get.endpoint({ - owner: "octocat", - repo: "hello-world", - number: 123, - }); - const options = octokit.rest.issues.get.endpoint.merge({ - owner: "octocat", - repo: "hello-world", - number: 123, - }); - - expect(url).to.equal( - "https://api.github.com/repos/octocat/hello-world/issues/123", - ); - expect(options.url).to.equal("/repos/{owner}/{repo}/issues/{issue_number}"); - expect("number" in options).to.equal(false); - expect(options.issue_number).to.equal(123); - expect(warnCalledCount).to.equal(2); - }); - - it.skip("octokit.paginate(octokit.rest.pulls.listReviews.merge({owner, repo, number}))", () => { - nock("https://deprecation-host.com") - .get("/repos/octocat/hello-world/pulls/123/reviews") - .query({ - per_page: 1, - }) - .reply( - 200, - [ - { - id: "123", - }, - ], - { - Link: '; rel="next", ; rel="last"', - }, - ) - - .get("/repositories/1/pulls/123/reviews") - .query({ - per_page: 1, - page: 2, - }) - .reply( - 200, - { - total_count: 2, - repository_selection: "all", - repositories: [ - { - id: "456", - }, - ], - }, - { - Link: '; rel="first", ; rel="prev"', - }, - ); - - let warnCalledCount = 0; - const octokit = new Octokit({ - baseUrl: "https://deprecation-host.com", - log: { - ...nopLogger, - warn() { - warnCalledCount++; - }, - }, - }); - - const options = octokit.rest.pulls.listReviews.endpoint.merge({ - owner: "octocat", - repo: "hello-world", - number: 123, - per_page: 1, - }); - - return octokit.paginate(options).then((response) => { - expect(warnCalledCount).to.equal(1); - }); - }); - - it.skip("octokit.authenticate(): basic", () => { - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - }, - }) - .get("/orgs/myorg") - .reply(200, {}); - - let warnCalledCount = 0; - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - log: { - ...nopLogger, - warn: () => { - warnCalledCount++; - }, - }, - }); - - octokit.authenticate({ - type: "basic", - username: "username", - password: "password", - }); - - octokit.authenticate({ - type: "basic", - username: "username", - password: "password", - }); - - expect(warnCalledCount).to.equal(1); - - return octokit.rest.orgs.get({ org: "myorg" }); - }); - - it.skip("octokit.authenticate(): basic with 2fa", () => { - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - }, - }) - .get("/orgs/myorg") - .reply( - 401, - {}, - { - "x-github-otp": "required; app", - }, - ); - - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - "x-github-otp": "123456", - }, - }) - .get("/orgs/myorg") - .reply(200, {}); - - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - log: { - ...nopLogger, - warn: () => {}, - }, - }); - - octokit.authenticate({ - type: "basic", - username: "username", - password: "password", - on2fa() { - return 123456; - }, - }); - - return octokit.rest.orgs.get({ org: "myorg" }); - }); - - it.skip("octokit.authenticate(): basic with async 2fa", () => { - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - }, - }) - .get("/orgs/myorg") - .reply( - 401, - {}, - { - "x-github-otp": "required; app", - }, - ); - - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - "x-github-otp": "123456", - }, - }) - .get("/orgs/myorg") - .reply(200, {}); - - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - log: { - ...nopLogger, - warn: () => {}, - }, - }); - - octokit.authenticate({ - type: "basic", - username: "username", - password: "password", - on2fa() { - return Promise.resolve(123456); - }, - }); - - return octokit.rest.orgs.get({ org: "myorg" }); - }); - - it.skip("octokit.authenticate(): basic with 2fa and invalid one-time-password", () => { - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - }, - }) - .get("/orgs/myorg") - .reply( - 401, - {}, - { - "x-github-otp": "required; app", - }, - ); - - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - "x-github-otp": "123456", - }, - }) - .get("/orgs/myorg") - .reply( - 401, - {}, - { - "x-github-otp": "required; app", - }, - ); - - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - log: { - ...nopLogger, - warn: () => {}, - }, - }); - - octokit.authenticate({ - type: "basic", - username: "username", - password: "password", - on2fa() { - return 123456; - }, - }); - - return octokit.rest.orgs - .get({ org: "myorg" }) - - .then(() => { - throw new Error("should not resolve"); - }) - - .catch((error) => { - expect(error.message).to.match(/Invalid one-time password/i); - }); - }); - - it.skip("octokit.authenticate(): basic without 2fa", () => { - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - }, - }) - .get("/orgs/myorg") - .reply( - 401, - {}, - { - "x-github-otp": "required; app", - }, - ); - - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - log: { - ...nopLogger, - warn: () => {}, - }, - }); - - octokit.authenticate({ - type: "basic", - username: "username", - password: "password", - }); - - return octokit.rest.orgs - .get({ org: "myorg" }) - .then(() => { - throw new Error('should fail with "on2fa missing" error'); - }) - .catch((error) => { - expect(error.message).to.equal( - "2FA required, but options.on2fa is not a function. See https://github.com/octokit/rest.js#authentication", - ); - expect(error.status).to.equal(401); - expect(!!error.response.headers).to.equal(true); - expect(!!error.request).to.equal(true); - }); - }); - - it.skip("octokit.authenticate(): token", () => { - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "token abc4567", - }, - }) - .get("/orgs/myorg") - .reply(200, {}); - - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - log: { - ...nopLogger, - warn: () => {}, - }, - }); - - octokit.authenticate({ - type: "token", - token: "abc4567", - }); - - return octokit.rest.orgs.get({ org: "myorg" }); - }); - - it.skip("octokit.authenticate(): oauth token", () => { - nock("https://authentication-test-host.com") - .get("/orgs/myorg") - .query({ access_token: "abc4567" }) - .reply(200, {}); - - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - log: { - ...nopLogger, - warn: () => {}, - }, - }); - - octokit.authenticate({ - type: "oauth", - token: "abc4567", - }); - - return octokit.rest.orgs.get({ org: "myorg" }); - }); - - it.skip("octokit.authenticate(): oauth token with query", () => { - nock("https://authentication-test-host.com") - .get("/orgs/myorg/repos") - .query({ per_page: 1, access_token: "abc4567" }) - .reply(200, []); - - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - log: { - ...nopLogger, - warn: () => {}, - }, - }); - - octokit.authenticate({ - type: "oauth", - token: "abc4567", - }); - - return octokit.rest.repos.listForOrg({ org: "myorg", per_page: 1 }); - }); - - it.skip("octokit.authenticate(): oauth key & secret", () => { - nock("https://authentication-test-host.com") - .get("/orgs/myorg") - .query({ client_id: "oauthkey", client_secret: "oauthsecret" }) - .reply(200, {}); - - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - log: { - ...nopLogger, - warn: () => {}, - }, - }); - - octokit.authenticate({ - type: "oauth", - key: "oauthkey", - secret: "oauthsecret", - }); - - return octokit.rest.orgs.get({ org: "myorg" }); - }); - - it.skip("octokit.authenticate(): oauth key & secret with query", () => { - nock("https://authentication-test-host.com") - .get("/") - .query({ - foo: "bar", - client_id: "oauthkey", - client_secret: "oauthsecret", - }) - .reply(200, []); - - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - log: { - ...nopLogger, - warn: () => {}, - }, - }); - - octokit.authenticate({ - type: "oauth", - key: "oauthkey", - secret: "oauthsecret", - }); - - return octokit.request("/?foo=bar"); - }); - - it.skip("octokit.authenticate(): app", () => { - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Bearer abc4567", - }, - }) - .get("/orgs/myorg") - .reply(200, {}); - - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - log: { - ...nopLogger, - warn: () => {}, - }, - }); - - octokit.authenticate({ - type: "app", - token: "abc4567", - }); - - return octokit.rest.orgs.get({ org: "myorg" }); - }); - - it.skip("octokit.authenticate(): without options", () => { - const octokit = new Octokit({ - log: { - ...nopLogger, - warn: () => {}, - }, - }); - - octokit.authenticate(); - }); - - it.skip("octokit.authenticate(): errors", () => { - const octokit = new Octokit({ - log: { - ...nopLogger, - warn: () => {}, - }, - }); - - expect(() => { - octokit.authenticate({}); - }).to.throw(Error); - - expect(() => { - octokit.authenticate({ type: "basic" }); - }).to.throw(Error); - - expect(() => { - octokit.authenticate({ type: "oauth" }); - }).to.throw(Error); - - expect(() => { - octokit.authenticate({ type: "token" }); - }).to.throw(Error); - }); - - it.skip('octokit.authenticate() when "auth" option is set', () => { - let warnCalledWith; - const octokit = new Octokit({ - auth: "token secret123", - log: { - ...nopLogger, - warn: (message) => { - warnCalledWith = message; - }, - }, - }); - - octokit.authenticate({ - type: "token", - token: "secret123", - }); - - expect(warnCalledWith).to.match( - /octokit\.authenticate\(\) is deprecated and has no effect/, - ); - }); - - it.skip("new Octokit({ auth: { username, password, on2fa } })", () => { - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - }, - }) - .get("/orgs/myorg") - .reply(200, {}); - - let warnCalledCount = 0; - - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - auth: { - username: "username", - password: "password", - on2fa() {}, - }, - log: { - ...nopLogger, - warn: () => { - warnCalledCount++; - }, - }, - }); - - return octokit.rest.orgs - .get({ org: "myorg" }) - .then(() => { - // deprecation is only logged once per process, I couldn't figure out how to reset the counter - // expect(warnCalledCount).to.equal(1); - - return octokit.auth(); - }) - .then((authentication) => { - expect(authentication).to.deep.equal({ - type: "deprecated", - message: - 'Setting the "new Octokit({ auth })" option to an object without also setting the "authStrategy" option is deprecated and will be removed in v17. See (https://octokit.github.io/rest.js/#authentication)', - }); - }); - }); - - it.skip("new Octokit({ auth: { clientId, clientSecret } })", () => { - nock("https://authentication-test-host.com") - .get("/orgs/myorg") - .query({ - client_id: "123", - client_secret: "secret123", - }) - .reply(200, {}); - - let warnCalledCount = 0; - - const { Octokit } = require("../../"); - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - auth: { - clientId: "123", - clientSecret: "secret123", - }, - log: { - ...nopLogger, - warn: () => { - warnCalledCount++; - }, - }, - }); - - return octokit.rest.orgs.get({ org: "myorg" }).then(() => { - // deprecation is only logged once per process, I couldn't figure out how to reset the counter - // expect(warnCalledCount).to.equal(1); - }); - }); - - it.skip("new Octokit({ auth () { /* ... */ } })", () => { - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "token secret123", - }, - }) - .get("/orgs/myorg") - .reply(200, {}); - - let warnCalledCount = 0; - - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - auth() { - return "token secret123"; - }, - log: { - ...nopLogger, - warn: () => { - warnCalledCount++; - }, - }, - }); - - return octokit.rest.orgs.get({ org: "myorg" }).then(() => { - // deprecation is only logged once per process, I couldn't figure out how to reset the counter - // expect(warnCalledCount).to.equal(1); - }); - }); - - it.skip("options.auth { username, password } ", () => { - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - }, - }) - .get("/") - .reply(200, {}); - - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - auth: { - username: "username", - password: "password", - }, - log: { - ...nopLogger, - warn() {}, - }, - }); - - return octokit.request("/"); - }); - - it.skip("options.auth { username, password, on2fa } with 2fa", () => { - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - }, - }) - .get("/") - .reply( - 401, - {}, - { - "x-github-otp": "required; app", - }, - ); - - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - "x-github-otp": "123456", - }, - }) - .get("/") - .reply(200, {}); - - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - auth: { - username: "username", - password: "password", - on2fa() { - return 123456; - }, - }, - }); - - return octokit.request("/"); - }); - - it.skip("options.auth { username, password, on2fa } with async 2fa", () => { - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - }, - }) - .get("/") - .reply( - 401, - {}, - { - "x-github-otp": "required; app", - }, - ); - - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - "x-github-otp": "123456", - }, - }) - .get("/") - .reply(200, {}); - - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - auth: { - username: "username", - password: "password", - on2fa() { - return Promise.resolve(123456); - }, - }, - }); - - return octokit.request("/"); - }); - - it.skip("options.auth { username, password, on2fa } with invalid one-time-password", () => { - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - }, - }) - .get("/") - .reply( - 401, - {}, - { - "x-github-otp": "required; app", - }, - ); - - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - "x-github-otp": "123456", - }, - }) - .get("/") - .reply( - 401, - {}, - { - "x-github-otp": "required; app", - }, - ); - - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - auth: { - username: "username", - password: "password", - on2fa() { - return 123456; - }, - }, - }); - - return octokit - .request("/") - - .then(() => { - throw new Error("should not resolve"); - }) - - .catch((error) => { - expect(error.message).to.match(/Invalid one-time password/i); - }); - }); - - it.skip("options.auth { username, password, on2fa } with expiring 2fa", () => { - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - }, - }) - .get("/") - .reply( - 401, - {}, - { - "x-github-otp": "required; app", - }, - ); - - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - "x-github-otp": "1", - }, - }) - .get("/") - .reply(200, {}); - - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - "x-github-otp": "1", - }, - }) - .get("/") - .reply( - 401, - {}, - { - "x-github-otp": "required; app", - }, - ); - - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - "x-github-otp": "2", - }, - }) - .get("/") - .reply(200, {}); - - let callCount = 0; - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - auth: { - username: "username", - password: "password", - on2fa() { - return ++callCount; - }, - }, - }); - - return octokit - .request("/") - .then(() => octokit.request("/")) - .then(() => { - expect(callCount).to.equal(2); - }); - }); - - it.skip("options.auth is { username, password }", () => { - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - }, - }) - .get("/") - .reply( - 401, - {}, - { - "x-github-otp": "required; app", - }, - ); - - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - auth: { - username: "username", - password: "password", - }, - }); - - return octokit - .request("/") - - .then(() => { - throw new Error('should fail with "on2fa missing" error'); - }) - - .catch((error) => { - expect(error.message).to.equal( - "2FA required, but options.on2fa is not a function. See https://github.com/octokit/rest.js#authentication", - ); - expect(error.status).to.equal(401); - expect(!!error.response.headers).to.equal(true); - expect(!!error.request).to.equal(true); - }); - }); - - it.skip("options.oauth is object with clientId & clientSecret", () => { - nock("https://authentication-test-host.com") - .get("/") - .query({ client_id: "id123", client_secret: "secret456" }) - .reply(200, {}); - - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - auth: { - clientId: "id123", - clientSecret: "secret456", - }, - }); - - return octokit.request("/"); - }); - - it.skip('options.oauth is object with clientId & clientSecret with "?" in URL', () => { - nock("https://authentication-test-host.com") - .get("/") - .query({ foo: "bar", client_id: "id123", client_secret: "secret456" }) - .reply(200, {}); - - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - auth: { - clientId: "id123", - clientSecret: "secret456", - }, - }); - - return octokit.request("/?foo=bar"); - }); - - it.skip("options.auth is function", () => { - nock("https://authentication-test-host-auth-as-function.com", { - reqheaders: { - authorization: "token abc4567", - }, - }) - .get("/") - .reply(200, {}); - - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host-auth-as-function.com", - auth: () => "token abc4567", - }); - - return octokit.request("/"); - }); - - it.skip("options.auth is async function", () => { - nock("https://authentication-test-host-as-async-function.com", { - reqheaders: { - authorization: "token abc4567", - }, - }) - .get("/") - .reply(200, {}); - - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host-as-async-function.com", - auth: () => Promise.resolve("token abc4567"), - }); - - return octokit.request("/"); - }); - - it.skip("options.auth function (throws error)", () => { - const octokit = new Octokit({ - auth() { - throw new Error("test"); - }, - }); - - return octokit - .request("/") - .then(() => { - throw new Error("should not resolve"); - }) - .catch((error) => { - expect(error.message).to.equal("test"); - }); - }); - - /** - * There is a special case for OAuth applications, when `clientId` and `clientSecret` is passed as - * Basic Authorization instead of query parameters. The only routes where that applies share the same - * URL though: `/applications/{client_id}/tokens/{access_token}`. We identify this acception by looking - * for this path. - * - * 1. [Check an authorization](https://docs.github.com/en/rest/reference/apps/#check-an-authorization) - * 2. [Reset an authorization](https://docs.github.com/en/rest/reference/apps/#reset-an-authorization) - * 3. [Revoke an authorization for an application](https://docs.github.com/en/rest/reference/apps/#revoke-an-authorization-for-an-application) - */ - it.skip("OAuth client & secret to check authorization", () => { - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic aWQxMjM6c2VjcmV0NDU2", - }, - }) - .get("/applications/id123/tokens/token123") - .reply(200, {}) - .post("/applications/id123/tokens/token123") - .reply(200, {}) - .delete("/applications/id123/tokens/token123") - .reply(200, {}); - - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - auth: { - clientId: "id123", - clientSecret: "secret456", - }, - }); - - const options = { - client_id: "id123", - access_token: "token123", - }; - - return Promise.all([ - octokit.request( - "GET /applications/{client_id}/tokens/{access_token}", - options, - ), - octokit.request( - "POST /applications/{client_id}/tokens/{access_token}", - options, - ), - octokit.request( - "DELETE /applications/{client_id}/tokens/{access_token}", - options, - ), - ]); - }); - - it.skip("options.auth=basic without prefix", () => { - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "basic Zm9vLWJhcjpzZWNyZXQ=", - }, - }) - .get("/") - .reply(200, {}); - - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - auth: btoa("foo-bar:secret"), - }); - - return octokit.request("/"); - }); - - it.skip("options.auth=() => token without prefix", () => { - nock( - "https://authentication-test-host-auth-as-function-token-without-prefix.com", - { - reqheaders: { - authorization: "token abc4567", - }, - }, - ) - .get("/") - .reply(200, {}); - - const octokit = new Octokit({ - baseUrl: - "https://authentication-test-host-auth-as-function-token-without-prefix.com", - auth: () => "abc4567", - }); - - return octokit.request("/"); - }); - - it.skip("options.auth=() => basic without prefix", () => { - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "basic Zm9vLWJhcjpzZWNyZXQ=", - }, - }) - .get("/") - .reply(200, {}); - - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - auth: () => btoa("foo-bar:secret"), - }); - - return octokit.request("/"); - }); - - it.skip("options.auth=() => bearer without prefix", () => { - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: - "bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1NTM4MTkzMTIsImV4cCI6MTU1MzgxOTM3MiwiaXNzIjoxfQ.etiSZ4LFQZ8tiMGJVqKDoGn8hxMCgwL4iLvU5xBUqbAPr4pbk_jJZmMQjuxTlOnRxq4e7NouTizGCdfohRMb3R1mpLzGPzOH9_jqSA_BWYxolsRP_WDSjuNcw6nSxrPRueMVRBKFHrqcTOZJej0djRB5pI61hDZJ_-DGtiOIFexlK3iuVKaqBkvJS5-TbTekGuipJ652g06gXuz-l8i0nHiFJldcuIruwn28hTUrjgtPbjHdSBVn_QQLKc2Fhij8OrhcGqp_D_fvb_KovVmf1X6yWiwXV5VXqWARS-JGD9JTAr2495ZlLV_E4WPxdDpz1jl6XS9HUhMuwBpaCOuipw", - }, - }) - .get("/app") - .reply(200, {}); - - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - auth: () => - "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1NTM4MTkzMTIsImV4cCI6MTU1MzgxOTM3MiwiaXNzIjoxfQ.etiSZ4LFQZ8tiMGJVqKDoGn8hxMCgwL4iLvU5xBUqbAPr4pbk_jJZmMQjuxTlOnRxq4e7NouTizGCdfohRMb3R1mpLzGPzOH9_jqSA_BWYxolsRP_WDSjuNcw6nSxrPRueMVRBKFHrqcTOZJej0djRB5pI61hDZJ_-DGtiOIFexlK3iuVKaqBkvJS5-TbTekGuipJ652g06gXuz-l8i0nHiFJldcuIruwn28hTUrjgtPbjHdSBVn_QQLKc2Fhij8OrhcGqp_D_fvb_KovVmf1X6yWiwXV5VXqWARS-JGD9JTAr2495ZlLV_E4WPxdDpz1jl6XS9HUhMuwBpaCOuipw", - }); - - return octokit.request("/app"); - }); - - // deprecated client options - it.skip("agent option", () => { - let warnCalled = false; - const octokit = new Octokit({ - agent: "agent", - log: { - ...nopLogger, - warn: () => { - warnCalled = true; - }, - }, - }); - - octokit.hook.wrap("request", (request, options) => { - expect(options.request.agent).to.equal("agent"); - return "ok"; - }); - - expect(warnCalled).to.equal(true); - - return octokit - .request("/") - - .then((response) => { - expect(response).to.equal("ok"); - }); - }); - - it.skip("timeout option", () => { - let warnCallCount = 0; - const octokit = new Octokit({ - timeout: 123, - log: { - ...nopLogger, - warn: () => { - warnCallCount++; - }, - }, - }); - Octokit({ - timeout: 456, - log: { - ...nopLogger, - warn: () => { - warnCallCount++; - }, - }, - }); - - octokit.hook.wrap("request", (request, options) => { - expect(options.request.timeout).to.equal(123); - return "ok"; - }); - - expect(warnCallCount).to.equal(1); - - return octokit - .request("/") - - .then((response) => { - expect(response).to.equal("ok"); - }); - }); - - it.skip('headers["User-Agent"] option', () => { - let warnCalled = false; - const octokit = new Octokit({ - headers: { - "User-Agent": "blah", - }, - log: { - ...nopLogger, - warn: () => { - warnCalled = true; - }, - }, - }); - - octokit.hook.wrap("request", (request, options) => { - expect(options.headers["user-agent"]).to.match( - /^blah octokit\.js\/0\.0\.0-development /, - ); - return "ok"; - }); - - expect(warnCalled).to.equal(true); - - return octokit - .request("/") - - .then((response) => { - expect(response).to.equal("ok"); - }); - }); - - it.skip("headers.accept option", () => { - const octokit = new Octokit({ - headers: { - accept: - "application/vnd.github.jean-grey-preview+json,application/vnd.github.symmetra-preview+json", - }, - log: { - ...nopLogger, - warn: () => {}, - }, - }); - - octokit.hook.wrap("request", (request, options) => { - expect(options.headers.accept).to.equal( - "application/vnd.github.jean-grey-preview+json,application/vnd.github.symmetra-preview+json", - ); - return "ok"; - }); - - return octokit - .request("/") - - .then((response) => { - expect(response).to.equal("ok"); - }); - }); - - it.skip(".paginate() with results namespace", () => { - nock("https://api.github.com") - .get("/installation/repositories") - .query({ - per_page: 1, - }) - .reply( - 200, - { - total_count: 2, - repository_selection: "all", - repositories: [ - { - id: "123", - }, - ], - }, - { - Link: '; rel="next", ; rel="last"', - }, - ) - - .get("/installation/repositories") - .query({ - per_page: 1, - page: 2, - }) - .reply( - 200, - { - total_count: 2, - repository_selection: "all", - repositories: [ - { - id: "456", - }, - ], - }, - { - Link: '; rel="first", ; rel="prev"', - }, - ) - - .get("/search/issues") - .query({ - q: "repo:web-platform-tests/wpt is:pr is:open updated:>2019-02-26", - per_page: 1, - }) - .reply( - 200, - { - total_count: 2, - incomplete_results: false, - items: [ - { - id: "123", - }, - ], - }, - { - Link: '; rel="next", ; rel="last"', - }, - ) - - .get("/search/issues") - .query({ - q: "repo:web-platform-tests/wpt is:pr is:open updated:>2019-02-26", - per_page: 1, - page: 2, - }) - .reply( - 200, - { - total_count: 2, - incomplete_results: false, - items: [ - { - id: "456", - }, - ], - }, - { - Link: '; rel="first", ; rel="prev"', - }, - ); - - let warnCallCount = 0; - const octokit = new Octokit({ - log: { - ...nopLogger, - warn: (msg) => { - warnCallCount++; - }, - }, - }); - const searchOptions = - octokit.rest.search.issuesAndPullRequests.endpoint.merge({ - q: "repo:web-platform-tests/wpt is:pr is:open updated:>2019-02-26", - per_page: 1, - headers: { - "accept-encoding": "", - }, - }); - const listReposOptions = octokit.rest.apps.listRepos.endpoint.merge({ - per_page: 1, - }); - - return octokit - .paginate(listReposOptions, (result) => { - expect(result.data.incomplete_results).to.equal(undefined); - expect(result.data.repository_selection).to.equal("all"); - expect(result.data.total_count).to.equal(2); - expect(result.data.repositories.length).to.equal(1); - return result; - }) - - .then(() => - octokit.paginate(searchOptions, (result) => { - expect(result.data.incomplete_results).to.equal(false); - expect(result.data.total_count).to.equal(2); - expect(result.data.items.length).to.equal(1); - return result; - }), - ) - - .then(() => { - expect(warnCallCount).to.equal(4); - }); - }); -}); From 3e106b544648f94be85cbd93f2bfaa01f575e3cd Mon Sep 17 00:00:00 2001 From: uzlopak Date: Thu, 18 Jul 2024 00:01:26 +0200 Subject: [PATCH 15/22] agent-ca.test --- .../{agent-ca-test.js => agent-ca.test.ts} | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) rename test/integration/agent-ca/{agent-ca-test.js => agent-ca.test.ts} (83%) diff --git a/test/integration/agent-ca/agent-ca-test.js b/test/integration/agent-ca/agent-ca.test.ts similarity index 83% rename from test/integration/agent-ca/agent-ca-test.js rename to test/integration/agent-ca/agent-ca.test.ts index 35c4d38c..c41b9a3a 100644 --- a/test/integration/agent-ca/agent-ca-test.js +++ b/test/integration/agent-ca/agent-ca.test.ts @@ -1,13 +1,16 @@ -const { readFileSync } = require("node:fs"); -const { resolve } = require("node:path"); -const { fetch: undiciFetch, Agent } = require("undici"); +import { describe, beforeAll, it, expect, afterAll } from "vitest"; -const { Octokit } = require("../../.."); +import { readFileSync } from "node:fs"; +import { resolve } from "node:path"; +import { fetch as undiciFetch, Agent } from "undici"; +import https from "node:https"; + +import { Octokit } from "../../../src/index.ts"; const ca = readFileSync(resolve(__dirname, "./ca.crt")); describe("custom client certificate", () => { let server; - before((done) => { + beforeAll((done) => { server = https.createServer( { key: readFileSync(resolve(__dirname, "./localhost.key")), @@ -79,5 +82,5 @@ describe("custom client certificate", () => { }); }); - after((done) => server.close(done)); + afterAll((done) => server.close(done)); }); From bb0d19eb50ae61ee46fee8029085a4cd3e9b4c3b Mon Sep 17 00:00:00 2001 From: uzlopak Date: Thu, 18 Jul 2024 00:17:26 +0200 Subject: [PATCH 16/22] remove obsolete test, compare with https://github.com/octokit/rest.js/commit/83b4f644fb0130c373688b0e104ff90a9c41ae91 --- test/integration/agent-ca/agent-ca.test.ts | 86 ---------------------- 1 file changed, 86 deletions(-) delete mode 100644 test/integration/agent-ca/agent-ca.test.ts diff --git a/test/integration/agent-ca/agent-ca.test.ts b/test/integration/agent-ca/agent-ca.test.ts deleted file mode 100644 index c41b9a3a..00000000 --- a/test/integration/agent-ca/agent-ca.test.ts +++ /dev/null @@ -1,86 +0,0 @@ -import { describe, beforeAll, it, expect, afterAll } from "vitest"; - -import { readFileSync } from "node:fs"; -import { resolve } from "node:path"; -import { fetch as undiciFetch, Agent } from "undici"; -import https from "node:https"; - -import { Octokit } from "../../../src/index.ts"; -const ca = readFileSync(resolve(__dirname, "./ca.crt")); - -describe("custom client certificate", () => { - let server; - beforeAll((done) => { - server = https.createServer( - { - key: readFileSync(resolve(__dirname, "./localhost.key")), - cert: readFileSync(resolve(__dirname, "./localhost.crt")), - }, - function (request, response) { - expect(request.method).to.equal("GET"); - expect(request.url).to.equal("/repos/octokit/rest.js"); - - response.writeHead(200); - response.write("ok"); - response.end(); - }, - ); - - server.listen(0, done); - }); - - it("undici.Agent({ca})", () => { - const agent = new Agent({ - keepAliveTimeout: 10, - keepAliveMaxTimeout: 10, - connect: { ca: ca }, - }); - const myFetch = (url, opts) => { - return undiciFetch(url, { - ...opts, - dispatcher: agent, - }); - }; - const octokit = new Octokit({ - baseUrl: "https://localhost:" + server.address().port, - request: { - fetch: myFetch, - }, - }); - - return octokit.rest.repos.get({ - owner: "octokit", - repo: "rest.js", - }); - }); - - it("undici.Agent({ca, rejectUnauthorized})", () => { - const agent = new Agent({ - keepAliveTimeout: 10, - keepAliveMaxTimeout: 10, - connect: { - ca: "invalid", - rejectUnauthorized: true, - }, - }); - const myFetch = (url, opts) => { - return undiciFetch(url, { - ...opts, - dispatcher: agent, - }); - }; - const octokit = new Octokit({ - baseUrl: "https://localhost:" + server.address().port, - request: { - fetch: myFetch, - }, - }); - - return octokit.rest.repos.get({ - owner: "octokit", - repo: "rest.js", - }); - }); - - afterAll((done) => server.close(done)); -}); From f3e28502d94b54b69f6dda3e3c922041126758f2 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Thu, 18 Jul 2024 15:31:33 +0200 Subject: [PATCH 17/22] fix more --- test/integration/pagination.test.ts | 3 ++- test/integration/request-errors.test.ts | 5 ++--- test/scenarios/get-archive.test.ts | 4 ---- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/test/integration/pagination.test.ts b/test/integration/pagination.test.ts index 016b1402..2dc39f06 100644 --- a/test/integration/pagination.test.ts +++ b/test/integration/pagination.test.ts @@ -370,13 +370,14 @@ describe("pagination", () => { }); }); - it.skip("does not paginate non-paginated response with total_count property", () => { + it("does not paginate non-paginated response with total_count property", () => { nock("https://api.github.com") .get("/repos/octokit/rest.js/commits/abc4567/status") .reply(200, { state: "success", total_count: 2, statuses: [{ id: 1 }, { id: 2 }], + url: "https://api.github.com/repos/octokit/rest.js/commits/abc4567/status", }); const octokit = new Octokit(); diff --git a/test/integration/request-errors.test.ts b/test/integration/request-errors.test.ts index e4ea2ce1..e1284a66 100644 --- a/test/integration/request-errors.test.ts +++ b/test/integration/request-errors.test.ts @@ -3,14 +3,13 @@ import nock from "nock"; import { Octokit } from "../../src/index.ts"; describe("request errors", () => { - // instantiate a server for the test - it.skip("timeout", () => { + it("timeout", () => { nock("https://request-errors-test.com").get("/").delay(2000).reply(200, {}); const octokit = new Octokit({ baseUrl: "https://request-errors-test.com", request: { - timeout: 100, + signal: AbortSignal.timeout(100), }, }); diff --git a/test/scenarios/get-archive.test.ts b/test/scenarios/get-archive.test.ts index 4a3b01ee..8829bb9f 100644 --- a/test/scenarios/get-archive.test.ts +++ b/test/scenarios/get-archive.test.ts @@ -12,10 +12,6 @@ describe.skip("api.github.com", () => { }); }); - if ("cy" in global) { - return it.skip("octokit.rest.repos.archive() (#758)"); - } - it('octokit.rest.repos.downloadTarballArchive({owner: "octokit-fixture-org", repo: "get-archive"})', () => { return octokit.rest.repos .downloadTarballArchive({ From ebb818a5b79ca8cbadb9d6adfa3c1a2e40dc4b4c Mon Sep 17 00:00:00 2001 From: uzlopak Date: Thu, 18 Jul 2024 16:02:41 +0200 Subject: [PATCH 18/22] activate one more smoke test --- test/integration/smoke.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/integration/smoke.test.ts b/test/integration/smoke.test.ts index 463122d3..9fed5856 100644 --- a/test/integration/smoke.test.ts +++ b/test/integration/smoke.test.ts @@ -56,7 +56,7 @@ describe("Smoke tests", () => { expect(octokit.paginate).toBeInstanceOf(Function); }); - it.skip("@octokit/plugin-request-log", () => { + it("@octokit/plugin-request-log", () => { const mock = fetchMock .sandbox() .getOnce("path:/", { status: 200, body: {} }) @@ -92,9 +92,9 @@ describe("Smoke tests", () => { }, () => { expect(consoleStub.debug.mock.calls.length).toEqual(2); - expect(consoleStub.info.mock.calls.length).toEqual(2); + expect(consoleStub.info.mock.calls.length).toEqual(1); expect(consoleStub.warn.mock.calls.length).toEqual(0); - expect(consoleStub.error.mock.calls.length).toEqual(0); + expect(consoleStub.error.mock.calls.length).toEqual(1); }, ); }); From 8d2ea4284cd8d8383c7abc3ac9c1326b4fc80d3d Mon Sep 17 00:00:00 2001 From: uzlopak Date: Thu, 18 Jul 2024 16:05:15 +0200 Subject: [PATCH 19/22] activate 1497 test --- .../1497-include-error-message-on-validation-error.test.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/issues/1497-include-error-message-on-validation-error.test.ts b/test/issues/1497-include-error-message-on-validation-error.test.ts index 3b95ed3d..b31d7c2e 100644 --- a/test/issues/1497-include-error-message-on-validation-error.test.ts +++ b/test/issues/1497-include-error-message-on-validation-error.test.ts @@ -3,11 +3,10 @@ import nock from "nock"; import { Octokit } from "../../src/index.ts"; describe("https://github.com/octokit/rest.js/issues/1497", () => { - it.skip("octokit.rest.repos.updateBranchProtection()", () => { + it("octokit.rest.repos.updateBranchProtection()", () => { nock("https://request-errors-test.com", { reqheaders: { - accept: - "application/vnd.github.hellcat-preview+json,application/vnd.github.luke-cage-preview+json,application/vnd.github.zzzax-preview+json", + accept: "application/vnd.github.v3+json", authorization: "token secret123", }, }) @@ -57,7 +56,7 @@ describe("https://github.com/octokit/rest.js/issues/1497", () => { .catch((error) => { expect(error).to.have.property( "message", - `Validation Failed: "Only organization repositories can have users and team restrictions"`, + `Validation Failed: "Only organization repositories can have users and team restrictions" - https://docs.github.com/en/rest/reference/repos/#update-branch-protection`, ); }); }); From eb9ce235bb20700d4bdbdeefd1b32638535565c4 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Thu, 18 Jul 2024 16:06:13 +0200 Subject: [PATCH 20/22] activate another one --- test/scenarios/project-cards.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/scenarios/project-cards.test.ts b/test/scenarios/project-cards.test.ts index a5221fac..79858c0a 100644 --- a/test/scenarios/project-cards.test.ts +++ b/test/scenarios/project-cards.test.ts @@ -13,7 +13,7 @@ describe("api.github.com", () => { }); // blocked by renovate/octokit-plugin-rest-endpoint-methods-5.x - it.skip("octokit.rest.projects.*ProjectCard()", () => { + it("octokit.rest.projects.*ProjectCard()", () => { return octokit.rest.projects .createCard({ column_id: 1000, From 4b757b6076130d096cc692d35f4cf17ccc75e3e7 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Thu, 18 Jul 2024 20:27:57 +0200 Subject: [PATCH 21/22] remove otp tests --- ...store-otp-send-header-all-requests.test.ts | 127 ------------------ 1 file changed, 127 deletions(-) delete mode 100644 test/issues/1279-store-otp-send-header-all-requests.test.ts diff --git a/test/issues/1279-store-otp-send-header-all-requests.test.ts b/test/issues/1279-store-otp-send-header-all-requests.test.ts deleted file mode 100644 index 333e41d4..00000000 --- a/test/issues/1279-store-otp-send-header-all-requests.test.ts +++ /dev/null @@ -1,127 +0,0 @@ -import { describe, it, expect } from "vitest"; -import nock from "nock"; -import { Octokit } from "../../src/index.ts"; - -// TODO: Basic Auth is not accepted by GitHub anymore -describe("https://github.com/octokit/rest.js/issues/1279", () => { - it.skip("2fa code gets stored and passed as header to listAuthorizations", () => { - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - }, - }) - .get("/") - .reply( - 401, - {}, - { - "x-github-otp": "required; app", - }, - ); - - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - "x-github-otp": "123456", - }, - }) - .get("/") - .reply(200, {}); - - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - "x-github-otp": "123456", - }, - }) - .get("/authorizations?per_page=100") - .reply(200, []); - - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - auth: { - username: "username", - password: "password", - on2fa() { - return Promise.resolve("123456"); - }, - }, - }); - - return octokit.request("/").then(() => { - return octokit.authorization.listAuthorizations({ per_page: 100 }); - }); - }); - - it.skip("prompts for OTP again once OTP code becomes invalid", () => { - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - }, - }) - .get("/") - .reply( - 401, - {}, - { - "x-github-otp": "required; app", - }, - ); - - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - "x-github-otp": "123456", - }, - }) - .get("/") - .reply(200, {}); - - // OTP code now becomes invalid - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - "x-github-otp": "123456", - }, - }) - .get("/authorizations?per_page=100") - .reply( - 401, - {}, - { - "x-github-otp": "required; app", - }, - ); - - nock("https://authentication-test-host.com", { - reqheaders: { - authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", - "x-github-otp": "123456", - }, - }) - .get("/authorizations?per_page=100") - .reply(200, {}); - - let on2faCalledCounter = 0; - const octokit = new Octokit({ - baseUrl: "https://authentication-test-host.com", - auth: { - username: "username", - password: "password", - on2fa() { - on2faCalledCounter++; - return Promise.resolve(123456); - }, - }, - }); - - return octokit.request("/").then(() => { - expect(on2faCalledCounter).to.equal(1); - return octokit.authorization - .listAuthorizations({ per_page: 100 }) - .then(() => { - expect(on2faCalledCounter).to.equal(2); - }); - }); - }); -}); From fb9177c4a6042c11ad8a8aab0a9fe6e7a96c19eb Mon Sep 17 00:00:00 2001 From: uzlopak Date: Thu, 18 Jul 2024 20:31:28 +0200 Subject: [PATCH 22/22] remove params-validations.test.ts --- test/integration/params-validations.test.ts | 237 -------------------- 1 file changed, 237 deletions(-) delete mode 100644 test/integration/params-validations.test.ts diff --git a/test/integration/params-validations.test.ts b/test/integration/params-validations.test.ts deleted file mode 100644 index 574e383e..00000000 --- a/test/integration/params-validations.test.ts +++ /dev/null @@ -1,237 +0,0 @@ -import { describe, it, expect } from "vitest"; -import nock from "nock"; -import { Octokit } from "../../src/index.ts"; - -describe("params validations", () => { - it.skip("octokit.rest.orgs.get({})", () => { - const octokit = new Octokit(); - - return octokit.rest.orgs - .get({}) - - .then(() => { - expect.fail("should throw error"); - }) - - .catch((error) => { - expect(error.message).to.equal( - "Empty value for parameter 'org': undefined", - ); - expect(error.status).to.equal(400); - }); - }); - - it.skip("request error", () => { - const octokit = new Octokit({ - baseUrl: "https://127.0.0.1:8", // port: 8 // officially unassigned port. See https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers - }); - - return octokit.rest.orgs - .get({ org: "foo" }) - - .then(() => { - expect.fail("should throw error"); - }) - - .catch((error) => { - expect(error.status).to.equal(500); - expect(error.message).to.equal( - "request to https://127.0.0.1:8/orgs/foo failed, reason: connect ECONNREFUSED 127.0.0.1:8", - ); - }); - }); - - it.skip("invalid value for octokit.rest.issues.list({filter})", () => { - const octokit = new Octokit(); - - return octokit.rest.issues - .list({ filter: "foo" }) - - .then(() => { - expect.fail("should throw error"); - }) - - .catch((error) => { - expect(error.status).to.equal(400); - expect(error.message).to.equal( - "Invalid value for parameter 'filter': \"foo\"", - ); - }); - }); - - it.skip("invalid value for octokit.rest.projects.moveCard({position})", () => { - const octokit = new Octokit(); - - return octokit.rest.projects - .moveCard({ card_id: 123, position: "foo" }) - - .then(() => { - expect.fail("should throw error"); - }) - - .catch((error) => { - expect(error.status).to.equal(400); - expect(error.message).to.equal( - "Invalid value for parameter 'position': \"foo\"", - ); - }); - }); - - it.skip("Not a number for octokit.rest.repos.createCommitComment({..., position})", () => { - const octokit = new Octokit(); - - return octokit.rest.repos - .createCommitComment({ - owner: "foo", - repo: "bar", - commit_sha: "lala", - body: "Sing with me!", - position: "Age Ain’t Nothing", - }) - - .catch((error) => { - expect(error.status).to.equal(400); - expect(error.message).to.equal( - "Invalid value for parameter 'position': \"Age Ain’t Nothing\" is NaN", - ); - }); - }); - - it.skip("Not a valid JSON string for octokit.rest.repos.createHook({..., config})", () => { - const octokit = new Octokit(); - - return octokit.rest.repos - .createHook({ - owner: "foo", - repo: "bar", - name: "captain", - config: "I’m no Je-Son!", - }) - - .then(() => { - expect.fail("should throw error"); - }) - - .catch((error) => { - expect(error.status).to.equal(400); - expect(error.message).to.equal( - "JSON parse error of value for parameter 'config': \"I’m no Je-Son!\"", - ); - }); - }); - - it("Date object for octokit.rest.issues.createMilestone({..., due_on})", () => { - const octokit = new Octokit({ - baseUrl: "https://milestones-test-host.com", - }); - - nock("https://milestones-test-host.com") - .post("/repos/foo/bar/milestones", (body) => { - expect(body.due_on).to.equal("2012-10-09T23:39:01.000Z"); - return true; - }) - .reply(201, {}); - - return octokit.rest.issues.createMilestone({ - owner: "foo", - repo: "bar", - title: "Like a rolling ...", - due_on: new Date("2012-10-09T23:39:01Z"), - }); - }); - - it.skip("Date is passed in correct format for notifications (#716)", () => { - const octokit = new Octokit({ - baseUrl: "https://notifications-test-host.com", - }); - - nock("https://notifications-test-host.com") - .get("/notifications") - .query((query) => { - expect(query).to.eql({ - since: "2018-01-21T23:27:31.000Z", - }); - return true; - }) - .reply(200, {}); - - return octokit.rest.activity.listNotifications({ - since: "2018-01-21T23:27:31.000Z", - }); - }); - - it.skip("octokit.rest.gitdata.createTree() with invalid tree[] object", () => { - const octokit = new Octokit(); - return octokit.rest.gitdata - .createTree({ - owner: "foo", - repo: "bar", - base_tree: "9fb037999f264ba9a7fc6274d15fa3ae2ab98312", - tree: [ - { - type: "foo", - }, - ], - }) - - .then(() => { - expect.fail("should throw error"); - }) - - .catch((error) => { - expect(error.status).to.equal(400); - expect(error.message).to.equal( - "Invalid value for parameter 'tree[0].type': \"foo\"", - ); - }); - }); - - it.skip("octokit.rest.issues.createLabel() with description: null", () => { - const octokit = new Octokit(); - return octokit.rest.issues - .createLabel({ - owner: "foo", - repo: "bar", - name: "baz", - color: "#bada55", - description: null, - }) - - .then(() => { - expect.fail("should throw error"); - }) - - .catch((error) => { - expect(error.status).to.equal(400); - expect(error.message).to.equal("'description' cannot be null"); - }); - }); - - it("does not alter passed options", () => { - const octokit = new Octokit({ - baseUrl: "https://params-test-host.com", - }); - - nock("https://params-test-host.com").get("/orgs/foo").reply(200, {}); - - const options = { - org: "foo", - headers: { - "x-bar": "baz", - }, - }; - return octokit.rest.orgs - .get(options) - .catch(() => { - // ignore error - }) - .then(() => { - expect(options).toStrictEqual({ - org: "foo", - headers: { - "x-bar": "baz", - }, - }); - }); - }); -});