Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maint: fixup tests for Jest #414

Closed
wants to merge 11 commits into from
83 changes: 0 additions & 83 deletions test/integration/agent-ca/agent-ca-test.js

This file was deleted.

88 changes: 88 additions & 0 deletions test/integration/agent-ca/agent-ca.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { describe, it, expect, beforeAll, afterAll } from "vitest";
import { readFileSync } from "node:fs";
import { fetch as undiciFetch, Agent } from "undici";
import https from "node:https";

import { Octokit } from "../../../src/index.ts";
import type { AddressInfo } from "node:net";
const ca = readFileSync(new URL("./ca.crt", import.meta.url));

Check failure on line 8 in test/integration/agent-ca/agent-ca.test.ts

View workflow job for this annotation

GitHub Actions / test_matrix (18)

test/integration/agent-ca/agent-ca.test.ts

Error: ENOENT: no such file or directory, open '/home/runner/work/rest.js/rest.js/test/integration/agent-ca/ca.crt' ❯ test/integration/agent-ca/agent-ca.test.ts:8:12 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, syscall: 'open', code: 'ENOENT', path: '/home/runner/work/rest.js/rest.js/test/integration/agent-ca/ca.crt' }

Check failure on line 8 in test/integration/agent-ca/agent-ca.test.ts

View workflow job for this annotation

GitHub Actions / test_matrix (20)

test/integration/agent-ca/agent-ca.test.ts

Error: ENOENT: no such file or directory, open '/home/runner/work/rest.js/rest.js/test/integration/agent-ca/ca.crt' ❯ test/integration/agent-ca/agent-ca.test.ts:8:12 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'open', path: '/home/runner/work/rest.js/rest.js/test/integration/agent-ca/ca.crt' }

Check failure on line 8 in test/integration/agent-ca/agent-ca.test.ts

View workflow job for this annotation

GitHub Actions / test_matrix (22)

test/integration/agent-ca/agent-ca.test.ts

Error: ENOENT: no such file or directory, open '/home/runner/work/rest.js/rest.js/test/integration/agent-ca/ca.crt' ❯ test/integration/agent-ca/agent-ca.test.ts:8:12 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'open', path: '/home/runner/work/rest.js/rest.js/test/integration/agent-ca/ca.crt' }

describe("custom client certificate", () => {
let server: https.Server;
beforeAll(
() =>
new Promise((done) => {
server = https.createServer(
{
key: readFileSync(new URL("./localhost.key", import.meta.url)),
cert: readFileSync(new URL("./localhost.crt", import.meta.url)),
},
function (request, response) {
expect(request.method).toStrictEqual("GET");
expect(request.url).toStrictEqual("/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() as AddressInfo).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() as AddressInfo).port,
request: {
fetch: myFetch,
},
});

return octokit.rest.repos.get({
owner: "octokit",
repo: "rest.js",
});
});

afterAll(() => new Promise(() => server.close()));
});
48 changes: 0 additions & 48 deletions test/integration/apps-test.js

This file was deleted.

19 changes: 19 additions & 0 deletions test/integration/apps.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import nock from "nock";

import { Octokit } from "../../pkg/dist-src/index.js";
const BEARER_TOKEN =
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1NTM4MTkzMTIsImV4cCI6MTU1MzgxOTM3MiwiaXNzIjoxfQ.etiSZ4LFQZ8tiMGJVqKDoGn8hxMCgwL4iLvU5xBUqbAPr4pbk_jJZmMQjuxTlOnRxq4e7NouTizGCdfohRMb3R1mpLzGPzOH9_jqSA_BWYxolsRP_WDSjuNcw6nSxrPRueMVRBKFHrqcTOZJej0djRB5pI61hDZJ_-DGtiOIFexlK3iuVKaqBkvJS5-TbTekGuipJ652g06gXuz-l8i0nHiFJldcuIruwn28hTUrjgtPbjHdSBVn_QQLKc2Fhij8OrhcGqp_D_fvb_KovVmf1X6yWiwXV5VXqWARS-JGD9JTAr2495ZlLV_E4WPxdDpz1jl6XS9HUhMuwBpaCOuipw";

describe.skip("apps", () => {
let octokit;

beforeEach(() => {
octokit = new Octokit({
baseUrl: "https://apps-test-host.com",
auth: `Bearer ${BEARER_TOKEN}`,
log: console,
});
});

it("No test currently implemented", () => {});
});
Original file line number Diff line number Diff line change
@@ -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 { install } from "@sinonjs/fake-timers";
import nock from "nock";
import { createAppAuth } from "@octokit/auth-app";
import { createActionAuth } from "@octokit/auth-action";

const { Octokit } = require("../..");
import { Octokit } from "../../pkg/dist-src/index.js";

describe("authentication", () => {
it("unauthenticated", () => {
Expand All @@ -14,7 +14,7 @@ describe("authentication", () => {
});

return octokit.auth().then((authentication) => {
expect(authentication).to.deep.equal({
expect(authentication).toStrictEqual({
type: "unauthenticated",
});
});
Expand Down Expand Up @@ -120,7 +120,7 @@ describe("authentication", () => {
it("invalid auth errors", () => {
expect(() => {
Octokit({ auth: {}, log: { warn() {} } });
}).to.throw(Error);
}).toThrow(Error);
});

it("action auth strategy", async () => {
Expand Down Expand Up @@ -203,7 +203,7 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
.get("/")
.reply(200, {});

const clock = lolex.install({
const clock = install({
now: 0,
toFake: ["Date"],
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const nock = require("nock");
import nock from "nock";

const { Octokit } = require("../../");
import { Octokit } from "../../pkg/dist-src/index.js";

describe("request 304s", () => {
let octokit;
Expand All @@ -20,7 +20,7 @@ describe("request 304s", () => {
expect.fail("should throw error");
})
.catch((error) => {
expect(error.status).to.equal(304);
expect(error.status).toStrictEqual(304);
});
});

Expand All @@ -38,7 +38,7 @@ describe("request 304s", () => {
expect.fail("should throw error");
})
.catch((error) => {
expect(error.status).to.equal(304);
expect(error.status).toStrictEqual(304);
});
});
});
Loading
Loading