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

fix: follow up hotpath test #638

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 43 additions & 13 deletions test/log.test.ts
Original file line number Diff line number Diff line change
@@ -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
Loading