Skip to content

Commit

Permalink
feat(Octokit): add testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ijsKoud committed Jun 21, 2023
1 parent 3943e31 commit 769acdd
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 8 deletions.
7 changes: 4 additions & 3 deletions packages/octokit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"scripts": {
"build": "tsc --build",
"build-watch": "tsc --watch > /dev/null",
"lint": "TIMING=1 eslint"
"lint": "TIMING=1 eslint",
"test": "vitest run"
},
"dependencies": {
"@octokit/auth-app": "5.0.5",
Expand All @@ -20,8 +21,8 @@
"@types/node": "^18.16.18",
"eslint": "^8.43.0",
"prettier": "^2.8.8",
"redis": "^4.6.7",
"typescript": "5.1.3"
"typescript": "5.1.3",
"vitest": "0.32.2"
},
"engines": {
"node": ">= v18.16.0"
Expand Down
9 changes: 5 additions & 4 deletions packages/octokit/src/Octokit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@ export class Octokit extends ExtendableOctokit {
public readonly userAgent: string;

public get options() {
return {
const options: OctokitOptions = {
appId: this.appId,
privateKey: this.privateKey,
clientId: this.clientId,
clientSecret: this.clientSecret,
installationId: this.installationId
clientSecret: this.clientSecret
};

if (this.installationId) options.installationId = this.installationId;
return options;
}

public constructor(options: OctokitOptions) {
const userAgent = "@ijsblokje/octokit (https://github.com/ijsKoud/ijsblokje)";

super({
userAgent,
auth: options,
Expand Down
44 changes: 44 additions & 0 deletions packages/octokit/tests/Octokit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Octokit, type OctokitOptions } from "../src/index.js";

/** Checks whether the input is a class or not */
function isClass(input: unknown) {
return typeof input === "function" && typeof input.prototype === "object";
}

describe("Octokit", () => {
test("Octokit should be a class", () => {
expect(isClass(Octokit)).toBe(true);
});

const baseOptions: OctokitOptions = {
appId: 15483,
clientId: "",
clientSecret: "",
privateKey: "-----BEGIN RSA PRIVATE KEY-----\ntest test test\n-----END RSA PRIVATE KEY-----"
};

test("Without installationId", () => {
const octokit = new Octokit(baseOptions);
expect(octokit.options).toStrictEqual(baseOptions);

expect(octokit.userAgent).toBe("@ijsblokje/octokit (https://github.com/ijsKoud/ijsblokje)");
expect(typeof octokit.request === "function").toBe(true);
expect(typeof octokit.hook === "function").toBe(true);
expect(typeof octokit.graphql === "function").toBe(true);
expect(typeof octokit.log === "object").toBe(true);
});

test("With installationId", () => {
const options: OctokitOptions = { ...baseOptions, installationId: 11150 };
const octokit = new Octokit(options);
expect(octokit.options).toStrictEqual(options);
});

test("Octokit#new()", () => {
const octokit = new Octokit(baseOptions);
const clonedOctokit = octokit.new();

expect(clonedOctokit instanceof Octokit).toBe(true);
expect(clonedOctokit.options).toStrictEqual(baseOptions);
});
});
12 changes: 12 additions & 0 deletions packages/octokit/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "./",
"noEmit": true,
"incremental": true,
"tsBuildInfoFile": ".tsbuildinfo-2",
"types": ["vitest/globals"]
},
"include": ["*.test.ts"],
"references": [{ "path": "../" }]
}
2 changes: 1 addition & 1 deletion packages/octokit/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../tsconfig.json",
"include": ["./src/**/*.ts"],
"compilerOptions": { "outDir": "./dist" }
"compilerOptions": { "outDir": "./dist", "composite": true }
}
13 changes: 13 additions & 0 deletions packages/octokit/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
globals: true,
cache: {
dir: "../../node_modules/.vitest"
}
},
esbuild: {
target: "ES2020"
}
});

0 comments on commit 769acdd

Please sign in to comment.