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

Draft
wants to merge 8 commits into
base: beta
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
94 changes: 62 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Expand Up @@ -44,13 +44,15 @@
"@octokit/fixtures-server": "^8.0.0",
"@octokit/request": "^9.0.1",
"@octokit/tsconfig": "^3.0.0",
"@sinonjs/fake-timers": "^11.2.2",
"@types/jest": "^29.5.11",
"@types/node": "^20.11.5",
"@types/sinonjs__fake-timers": "^8.1.5",
"esbuild": "^0.20.0",
"fetch-mock": "npm:@gr2m/fetch-mock@9.11.0-pull-request-644.1",
"glob": "^10.3.10",
"jest": "^29.7.0",
"nock": "^13.5.0",
"nock": "^14.0.0-beta.5",
"prettier": "^3.2.4",
"semantic-release-plugin-update-version-in-files": "^1.1.0",
"ts-jest": "^29.1.1",
Expand All @@ -63,7 +65,7 @@
"lint": "prettier --check \"{src,test}/**/*.{js,json,ts}\" \"docs/*.js\" docs/package.json \"docs/src/**/*\" *.md package.json",
"lint:fix": "prettier --write \"{src,test}/**/*.{js,json,ts}\" \"docs/*.js\" docs/package.json \"docs/src/**/*\" *.md package.json",
"start-fixtures-server": "octokit-fixtures-server",
"pretest": "npm run -s lint",
"pretest": "npm run -s lint && npm run build",
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --coverage",
"test:typescript": "npx tsc --noEmit --declaration --allowImportingTsExtensions --moduleResolution node16 --module node16 --noUnusedLocals test/typescript-validate.ts"
},
Expand Down
@@ -1,21 +1,21 @@
const { readFileSync } = require("node:fs");
const { resolve } = require("node:path");
const { fetch: undiciFetch, Agent } = require("undici");
import { readFileSync } from "node:fs";
import { fetch as undiciFetch, Agent } from "undici";
import https from "node:https";

const { Octokit } = require("../../..");
const ca = readFileSync(resolve(__dirname, "./ca.crt"));
import { Octokit } from "../../../pkg/dist-src/index.js";
const ca = readFileSync(new URL("./ca.crt", import.meta.url));

describe("custom client certificate", () => {
let server;
before((done) => {
beforeAll((done) => {
server = https.createServer(
{
key: readFileSync(resolve(__dirname, "./localhost.key")),
cert: readFileSync(resolve(__dirname, "./localhost.crt")),
key: readFileSync(new URL("./localhost.key", import.meta.url)),
cert: readFileSync(new URL("./localhost.crt", import.meta.url)),
},
function (request, response) {
expect(request.method).to.equal("GET");
expect(request.url).to.equal("/repos/octokit/rest.js");
expect(request.method).toStrictEqual("GET");
expect(request.url).toStrictEqual("/repos/octokit/rest.js");

response.writeHead(200);
response.write("ok");
Expand Down Expand Up @@ -79,5 +79,5 @@ describe("custom client certificate", () => {
});
});

after((done) => server.close(done));
afterAll(() => 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
@@ -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", () => {});
});
@@ -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
@@ -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);
});
});
});