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

Run other tests #5

Merged
merged 3 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,14 @@ jobs:
with:
deno-version: v1.x

- name: 🧪 Test Libraries
- name: 🧪 Run Tests
run: deno task test

- name: 🧹 Lint Check
run: deno lint

- name: 📝 Format Check
run: deno fmt --check

- name: 🔍 Type Check
run: deno check ./**/*.ts
2 changes: 1 addition & 1 deletion src/libs/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getRepository, githubToken } from "./env.ts";

export async function getContent<R extends string>(
ctx: RouterContext<R>,
ref: string | undefined = undefined
ref: string | undefined = undefined,
): Promise<void> {
const octokit = new Octokit({ auth: githubToken });
const repository = getRepository();
Expand Down
6 changes: 4 additions & 2 deletions src/libs/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ export function getRepository(): Repository {
path: Deno.env.get("REPOSITORY_PATH") ?? "",
};

for (const key in repository)
if (!repository[key as keyof Repository])
for (const key in repository) {
if (!repository[key as keyof Repository]) {
console.error(`🚨 missing: $REPOSITORY_${key.toUpperCase()}`);
}
}

return repository;
}
Expand Down
4 changes: 2 additions & 2 deletions src/libs/redirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getRepository } from "./env.ts";
export function redirect<R extends string>(
ctx: RouterContext<R>,
userAgent: UserAgent,
ref: string = "master"
ref: string = "master",
): void {
const repository = getRepository();
const url = join(
Expand All @@ -16,7 +16,7 @@ export function redirect<R extends string>(
repository.name,
"blob",
ref,
repository.path
repository.path,
);

if (userAgent?.browser.name) {
Expand Down
10 changes: 6 additions & 4 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ app.addEventListener(
"listen",
({ secure, hostname, port }: ApplicationListenEvent) => {
console.log(
`🔔 listening: ${yellow(
`${secure ? "https" : "http"}://${hostname ?? "localhost"}:${port}`
)}`
`🔔 listening: ${
yellow(
`${secure ? "https" : "http"}://${hostname ?? "localhost"}:${port}`,
)
}`,
);
}
},
);

await app.listen({ port: 8080 });
6 changes: 3 additions & 3 deletions test/libs/content_test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { testing, type RouterContext } from "@oak/oak";
import { type RouterContext, testing } from "@oak/oak";
import { assertEquals, assertStringIncludes } from "@std/assert";
import { STATUS_CODE } from "@std/http/status";
import { getContent } from "../../src/libs/content.ts";
import { testRepo, unknownRepo, testRef, exportRepo } from "../utils.ts";
import { exportRepo, testRef, testRepo, unknownRepo } from "../utils.ts";

Deno.test("Get Content", async <R extends string>() => {
const ctx: RouterContext<R> = testing.createMockContext();
Expand All @@ -28,6 +28,6 @@ Deno.test("Get Content (Not found)", async <R extends string>() => {
assertEquals(ctx.response.status, STATUS_CODE.NotFound);
assertStringIncludes(
ctx.response.body!.toString(),
`⚠️ ${STATUS_CODE.NotFound}:`
`⚠️ ${STATUS_CODE.NotFound}:`,
);
});
2 changes: 1 addition & 1 deletion test/libs/env_test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assertEquals } from "@std/assert";
import { getRepository } from "../../src/libs/env.ts";
import { testRepo, exportRepo, clearRepo } from "../utils.ts";
import { clearRepo, exportRepo, testRepo } from "../utils.ts";

Deno.test("Get Repository Env", () => {
exportRepo(testRepo);
Expand Down
8 changes: 4 additions & 4 deletions test/libs/redirect_test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { testing, type RouterContext } from "@oak/oak";
import { type RouterContext, testing } from "@oak/oak";
import { assertEquals } from "@std/assert";
import { STATUS_CODE } from "@std/http/status";
import { UserAgent } from "@std/http/user-agent";
import { redirect } from "../../src/libs/redirect.ts";
import { testRepo, testRef, exportRepo } from "../utils.ts";
import { exportRepo, testRef, testRepo } from "../utils.ts";

Deno.test("Redirect Detection", <R extends string>() => {
const ctx: RouterContext<R> = testing.createMockContext();
Expand All @@ -13,7 +13,7 @@ Deno.test("Redirect Detection", <R extends string>() => {
assertEquals(ctx.response.status, STATUS_CODE.PermanentRedirect);
assertEquals(
ctx.response.headers.get("location"),
`https://github.com/${testRepo.owner}/${testRepo.name}/blob/master/${testRepo.path}`
`https://github.com/${testRepo.owner}/${testRepo.name}/blob/master/${testRepo.path}`,
);
});

Expand All @@ -25,6 +25,6 @@ Deno.test("Redirect Detection (With ref)", <R extends string>() => {
assertEquals(ctx.response.status, STATUS_CODE.PermanentRedirect);
assertEquals(
ctx.response.headers.get("location"),
`https://github.com/${testRepo.owner}/${testRepo.name}/blob/${testRef}/${testRepo.path}`
`https://github.com/${testRepo.owner}/${testRepo.name}/blob/${testRef}/${testRepo.path}`,
);
});
4 changes: 2 additions & 2 deletions test/router_test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { testing, type RouterContext } from "@oak/oak";
import { type RouterContext, testing } from "@oak/oak";
import { assertEquals } from "@std/assert";
import { STATUS_CODE } from "@std/http/status";
import { router } from "../src/router.ts";
import { testRepo, testRef, exportRepo } from "./utils.ts";
import { exportRepo, testRef, testRepo } from "./utils.ts";

Deno.test("Serve (/)", async <R extends string>() => {
const ctx: RouterContext<R> = testing.createMockContext({
Expand Down
Loading