Skip to content

Commit 5a4eeb6

Browse files
authored
test: re-activate more tests and convert them to typescript (#457)
Closes #414
1 parent 93d5afb commit 5a4eeb6

29 files changed

+185
-2072
lines changed

test/integration/agent-ca/agent-ca-test.js

-83
This file was deleted.

test/integration/apps-test.js test/integration/apps.test.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
const nock = require("nock");
1+
import { describe, beforeEach, it } from "vitest";
2+
import nock from "nock";
3+
import { Octokit } from "../../src/index.ts";
24

3-
const { Octokit } = require("../../");
45
const BEARER_TOKEN =
56
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1NTM4MTkzMTIsImV4cCI6MTU1MzgxOTM3MiwiaXNzIjoxfQ.etiSZ4LFQZ8tiMGJVqKDoGn8hxMCgwL4iLvU5xBUqbAPr4pbk_jJZmMQjuxTlOnRxq4e7NouTizGCdfohRMb3R1mpLzGPzOH9_jqSA_BWYxolsRP_WDSjuNcw6nSxrPRueMVRBKFHrqcTOZJej0djRB5pI61hDZJ_-DGtiOIFexlK3iuVKaqBkvJS5-TbTekGuipJ652g06gXuz-l8i0nHiFJldcuIruwn28hTUrjgtPbjHdSBVn_QQLKc2Fhij8OrhcGqp_D_fvb_KovVmf1X6yWiwXV5VXqWARS-JGD9JTAr2495ZlLV_E4WPxdDpz1jl6XS9HUhMuwBpaCOuipw";
67

78
describe("apps", () => {
8-
let octokit;
9+
let octokit: Octokit;
910

1011
beforeEach(() => {
1112
octokit = new Octokit({
1213
baseUrl: "https://apps-test-host.com",
1314
auth: `Bearer ${BEARER_TOKEN}`,
14-
log: console.log,
1515
});
1616
});
1717

1818
it('adds "machine-man" preview header', () => {
1919
nock("https://apps-test-host.com", {
2020
reqheaders: {
2121
authorization: `bearer ${BEARER_TOKEN}`,
22-
accept: "application/vnd.github.machine-man-preview+json",
22+
accept: "application/vnd.github.v3+json",
2323
},
2424
})
2525
.get("/app")
@@ -32,8 +32,7 @@ describe("apps", () => {
3232
nock("https://apps-test-host.com", {
3333
reqheaders: {
3434
authorization: `bearer ${BEARER_TOKEN}`,
35-
accept:
36-
"application/vnd.github.machine-man-preview+json,application/vnd.github.foo-bar-preview+json",
35+
accept: "application/vnd.github.v3+json",
3736
},
3837
})
3938
.get("/app")

test/integration/authentication-test.js test/integration/authentication.test.ts

+20-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const lolex = require("lolex");
2-
const nock = require("nock");
3-
const { createAppAuth } = require("@octokit/auth-app");
4-
const { createActionAuth } = require("@octokit/auth-action");
1+
import { describe, it, expect, vi } from "vitest";
2+
import nock from "nock";
3+
import { createAppAuth } from "@octokit/auth-app";
4+
import { createActionAuth } from "@octokit/auth-action";
55

6-
const { Octokit } = require("../..");
6+
import { Octokit } from "../../src/index.ts";
77

88
describe("authentication", () => {
99
it("unauthenticated", () => {
@@ -69,6 +69,9 @@ describe("authentication", () => {
6969
baseUrl: "https://authentication-test-host.com",
7070
auth: "token abc4567",
7171
log: {
72+
error() {},
73+
debug() {},
74+
info() {},
7275
warn() {},
7376
},
7477
});
@@ -119,7 +122,15 @@ describe("authentication", () => {
119122

120123
it("invalid auth errors", () => {
121124
expect(() => {
122-
Octokit({ auth: {}, log: { warn() {} } });
125+
new Octokit({
126+
auth: {},
127+
log: {
128+
error() {},
129+
debug() {},
130+
info() {},
131+
warn() {},
132+
},
133+
});
123134
}).to.throw(Error);
124135
});
125136

@@ -203,22 +214,22 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
203214
.get("/")
204215
.reply(200, {});
205216

206-
const clock = lolex.install({
217+
const clock = vi.useFakeTimers({
207218
now: 0,
208219
toFake: ["Date"],
209220
});
210221

211222
const octokit = new Octokit({
212223
authStrategy: createAppAuth,
213224
auth: {
214-
id: APP_ID,
225+
appId: APP_ID,
215226
privateKey: PRIVATE_KEY,
216227
installationId: 123,
217228
},
218229
});
219230

220231
return octokit.request("/").then(() => {
221-
clock.uninstall();
232+
clock.useRealTimers();
222233
});
223234
});
224235
});

test/integration/conditional-request-test.js test/integration/conditional-request.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const nock = require("nock");
2-
3-
const { Octokit } = require("../../");
1+
import { describe, beforeEach, it, expect } from "vitest";
2+
import nock from "nock";
3+
import { Octokit } from "../../src/index.ts";
44

55
describe("request 304s", () => {
6-
let octokit;
6+
let octokit: Octokit;
77

88
beforeEach(() => {
99
octokit = new Octokit({
@@ -16,7 +16,7 @@ describe("request 304s", () => {
1616

1717
return octokit.rest.orgs
1818
.get({ org: "myorg", headers: { "If-None-Match": "etag" } })
19-
.then((response) => {
19+
.then(() => {
2020
expect.fail("should throw error");
2121
})
2222
.catch((error) => {
@@ -34,7 +34,7 @@ describe("request 304s", () => {
3434
"If-Modified-Since": "Sun Dec 24 2017 22:00:00 GMT-0600 (CST)",
3535
},
3636
})
37-
.then((response) => {
37+
.then(() => {
3838
expect.fail("should throw error");
3939
})
4040
.catch((error) => {

0 commit comments

Comments
 (0)