Skip to content

Commit

Permalink
fix: performance enhancements (#637/#638)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed Nov 22, 2023
1 parent 8e5d7c1 commit 9843e38
Showing 1 changed file with 43 additions and 13 deletions.
56 changes: 43 additions & 13 deletions test/log.test.ts
@@ -1,25 +1,55 @@
import { Octokit } from "../src";

describe("octokit.log", () => {
it("has .debug(), .info(), .warn(), and .error() functions", () => {
const octokit = new Octokit();
expect(typeof octokit.log.debug).toBe("function");
expect(typeof octokit.log.info).toBe("function");
expect(typeof octokit.log.warn).toBe("function");
expect(typeof octokit.log.error).toBe("function");
});
it(".debug() and .info() are no-ops by default", async () => {
const calls: String[] = [];

const debug = jest
.spyOn(console, "debug")
.mockImplementation(() => calls.push("debug"));
const info = jest
.spyOn(console, "info")
.mockImplementation(() => calls.push("info"));
const warn = jest
.spyOn(console, "warn")
.mockImplementation(() => calls.push("warn"));
const error = jest
.spyOn(console, "error")
.mockImplementation(() => calls.push("error"));
const Octokit = (await import("../src")).Octokit;

it(".debug() and .info() are no-ops by default", () => {
const octokit = new Octokit();

octokit.log.debug("foo");
octokit.log.info("bar");
octokit.log.warn("baz");
octokit.log.error("daz");

expect(octokit.log.debug.name).toBe("noop");
expect(octokit.log.info.name).toBe("noop");

octokit.log.debug("foo");
octokit.log.info("bar");
expect(debug).toHaveBeenCalledTimes(0);
expect(info).toHaveBeenCalledTimes(0);
expect(warn).toHaveBeenCalledTimes(1);
expect(error).toHaveBeenCalledTimes(1);
expect(calls).toStrictEqual(["warn", "error"]);

debug.mockRestore();
info.mockRestore();
warn.mockRestore();
error.mockRestore();
});

it("has .debug(), .info(), .warn(), and .error() functions", async () => {
const Octokit = (await import("../src")).Octokit;

const octokit = new Octokit();
expect(typeof octokit.log.debug).toBe("function");
expect(typeof octokit.log.info).toBe("function");
expect(typeof octokit.log.warn).toBe("function");
expect(typeof octokit.log.error).toBe("function");
});

it("all .log.*() methods can be overwritten", () => {
it("all .log.*() methods can be overwritten", async () => {
const Octokit = (await import("../src")).Octokit;
const calls: String[] = [];

const octokit = new Octokit({
Expand Down

0 comments on commit 9843e38

Please sign in to comment.