Skip to content

Commit

Permalink
test(coverage): adding 100% coverage (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
oscard0m authored Mar 11, 2022
1 parent 054cefa commit 7590916
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
"preset": "ts-jest",
"coverageThreshold": {
"global": {
"statements": 98,
"branches": 96,
"functions": 93,
"lines": 98
"statements": 100,
"branches": 100,
"functions": 100,
"lines": 100
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const createGroups = function (Bottleneck, common) {
});
};

export function throttling(octokit: Octokit, octokitOptions = {}) {
export function throttling(octokit: Octokit, octokitOptions: object) {
const {
enabled = true,
Bottleneck = BottleneckLight,
Expand Down
48 changes: 48 additions & 0 deletions test/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,52 @@ describe("Events", function () {
expect(eventCount).toEqual(1);
});
});

describe("error", function () {
it("logs a warning when an 'error' event is emitted", async function () {
const octokit = new TestOctokit({
throttle: {
onRateLimit: () => {
throw new Error("Should not reach this point");
},
onSecondaryRateLimit: () => {
throw new Error("Should not reach this point");
},
},
});

jest.spyOn(octokit.log, "warn");

const t0 = Date.now();

await octokit.request("GET /route1", {
request: {
responses: [{ status: 201, headers: {}, data: {} }],
},
});
try {
await octokit.request("GET /route2", {
request: {
responses: [
{
status: 403,
headers: {
"x-ratelimit-remaining": "0",
"x-ratelimit-reset": `${Math.round(t0 / 1000) + 30}`,
},
data: {},
},
],
},
});
throw new Error("Should not reach this point");
} catch (error: any) {
expect(error.status).toEqual(403);
expect(octokit.log.warn).toHaveBeenCalledWith(
"Error in throttling-plugin limit handler",
new Error("Should not reach this point")
);
}
});
});
});
1 change: 1 addition & 0 deletions test/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ describe("Github API best practices", function () {
write: new Bottleneck.Group({ minTime: 50 }),
onSecondaryRateLimit: () => 1,
onRateLimit: () => 1,
connection: new Bottleneck({ minTime: 50 }),
},
});

Expand Down

0 comments on commit 7590916

Please sign in to comment.