8000 fix: performance enhancements (#637/#638) · octokit/core.js@9843e38 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9843e38

Browse files
authored
fix: performance enhancements (#637/#638)
1 parent 8e5d7c1 commit 9843e38

File tree

1 file changed

+43
-13
lines changed

1 file changed

+43
-13
lines changed

test/log.test.ts

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,55 @@
1-
import { Octokit } from "../src";
2-
31
describe("octokit.log", () => {
4-
it("has .debug(), .info(), .warn(), and .error() functions", () => {
5-
const octokit = new Octokit();
6-
expect(typeof octokit.log.debug).toBe("function");
7-
expect(typeof octokit.log.info).toBe("function");
8-
expect(typeof octokit.log.warn).toBe("function");
9-
expect(typeof octokit.log.error).toBe("function");
10-
});
2+
it(".debug() and .info() are no-ops by default", async () => {
3+
const calls: String[] = [];
4+
5+
const debug = jest
6+
.spyOn(console, "debug")
7+
.mockImplementation(() => calls.push("debug"));
8+
const info = jest
9+
.spyOn(console, "info")
10+
.mockImplementation(() => calls.push("info"));
11+
const warn = jest
12+
.spyOn(console, "warn")
13+
.mockImplementation(() => calls.push("warn"));
14+
const error = jest
15+
.spyOn(console, "error")
16+
.mockImplementation(() => calls.push("error"));
17+
const Octokit = (await import("../src")).Octokit;
1118

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

21+
octokit.log.debug("foo");
22+
octokit.log.info("bar");
23+
octokit.log.warn("baz");
24+
octokit.log.error("daz");
25+
1526
expect(octokit.log.debug.name).toBe("noop");
1627
expect(octokit.log.info.name).toBe("noop");
1728

18-
octokit.log.debug("foo");
19-
octokit.log.info("bar");
29+
expect(debug).toHaveBeenCalledTimes(0);
30+
expect(info).toHaveBeenCalledTimes(0);
31+
expect(warn).toHaveBeenCalledTimes(1);
32+
expect(error).toHaveBeenCalledTimes(1);
33+
expect(calls).toStrictEqual(["warn", "error"]);
34+
35+
debug.mockRestore();
36+
info.mockRestore();
37+
warn.mockRestore();
38+
error.mockRestore();
39+
});
40+
41+
it("has .debug(), .info(), .warn(), and .error() functions", async () => {
42+
const Octokit = (await import("../src")).Octokit;
43+
44+
const octokit = new Octokit();
45+
expect(typeof octokit.log.debug).toBe("function");
46+
expect(typeof octokit.log.info).toBe("function");
47+
expect(typeof octokit.log.warn).toBe("function");
48+
expect(typeof octokit.log.error).toBe("function");
2049
});
2150

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

2555
const octokit = new Octokit({

0 commit comments

Comments
 (0)
0