aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2021-07-25 14:56:58 +0200
committerHampusM <hampus@hampusmat.com>2021-07-25 14:56:58 +0200
commit7b3292af22a0496007e974b65cd2e34521c9c429 (patch)
tree8205726e27fa7e5f80cd2a7ffb6c7354a11b6dea /test
parent4f5771726aa8c7b6d4e288df2a79f1ffef55c3a3 (diff)
Reformated unit tests & the setup and teardown scripts
Diffstat (limited to 'test')
-rw-r--r--test/setup.ts2
-rw-r--r--test/teardown.ts2
-rw-r--r--test/unit/commit.unit.test.ts24
-rw-r--r--test/unit/diff.unit.test.ts8
-rw-r--r--test/unit/git-http.unit.test.ts50
-rw-r--r--test/unit/misc.unit.test.ts24
-rw-r--r--test/unit/repository.unit.test.ts26
-rw-r--r--test/unit/tree.unit.test.ts14
-rw-r--r--test/util.ts2
9 files changed, 76 insertions, 76 deletions
diff --git a/test/setup.ts b/test/setup.ts
index 50c8754..89eeead 100644
--- a/test/setup.ts
+++ b/test/setup.ts
@@ -9,7 +9,7 @@ config({ path: "test/test.env" });
const env = process.env as EnvironmentVariables;
-export default async function init() {
+export default async function(): Promise<void> {
const can_access = await access(env.BASE_DIR)
.then(() => true)
.catch(() => false);
diff --git a/test/teardown.ts b/test/teardown.ts
index 3712af2..290c478 100644
--- a/test/teardown.ts
+++ b/test/teardown.ts
@@ -1,5 +1,5 @@
import { remove } from "fs-extra";
-export default async function teardown() {
+export default async function(): Promise<void> {
await remove(process.env.BASE_DIR);
} \ No newline at end of file
diff --git a/test/unit/commit.unit.test.ts b/test/unit/commit.unit.test.ts
index 81dc7c8..2a43855 100644
--- a/test/unit/commit.unit.test.ts
+++ b/test/unit/commit.unit.test.ts
@@ -9,11 +9,11 @@ const env = process.env as EnvironmentVariables;
describe("Commit", () => {
let repository: Repository;
- beforeAll(async () => {
+ beforeAll(async() => {
repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO);
});
- it("Should look up a commit", async () => {
+ it("Should look up a commit", async() => {
expect.assertions(8);
const commit = await Commit.lookup(repository, env.AVAIL_COMMIT);
@@ -24,19 +24,19 @@ describe("Commit", () => {
expectCommitProperties(commit);
});
- it("Should look up a nonexistant commit and throw", async () => {
+ it("Should look up a nonexistant commit and throw", async() => {
expect.assertions(1);
await expect(Commit.lookup(repository, env.UNAVAIL_COMMIT)).rejects.toThrow();
});
- it("Should look up if an existent commit exists and respond true", async () => {
+ it("Should look up if an existent commit exists and respond true", async() => {
expect.assertions(1);
await expect(Commit.lookupExists(repository, env.AVAIL_COMMIT)).resolves.toBeTruthy();
});
- it("Should look up if an nonexistant commit exists and respond false", async () => {
+ it("Should look up if an nonexistant commit exists and respond false", async() => {
expect.assertions(1);
await expect(Commit.lookupExists(repository, env.UNAVAIL_COMMIT)).resolves.toBeFalsy();
@@ -45,11 +45,11 @@ describe("Commit", () => {
describe("Methods", () => {
let commit: Commit;
- beforeAll(async () => {
+ beforeAll(async() => {
commit = await repository.masterCommit();
});
- it("Should get the stats", async () => {
+ it("Should get the stats", async() => {
expect.assertions(4);
const stats = await commit.stats();
@@ -61,7 +61,7 @@ describe("Commit", () => {
expect(stats).toHaveProperty("files_changed");
});
- it("Should get the diff", async () => {
+ it("Should get the diff", async() => {
expect.assertions(2);
const diff = await commit.diff();
@@ -69,8 +69,8 @@ describe("Commit", () => {
expect(diff).toBeDefined();
expect(diff).toBeInstanceOf(Diff);
});
-
- it("Should get the tree", async () => {
+
+ it("Should get the tree", async() => {
expect.assertions(2);
const tree = await commit.tree();
@@ -78,5 +78,5 @@ describe("Commit", () => {
expect(tree).toBeDefined();
expect(tree).toBeInstanceOf(Tree);
});
- });
-});
+ });
+}); \ No newline at end of file
diff --git a/test/unit/diff.unit.test.ts b/test/unit/diff.unit.test.ts
index 2021987..1fb164f 100644
--- a/test/unit/diff.unit.test.ts
+++ b/test/unit/diff.unit.test.ts
@@ -8,14 +8,14 @@ const env = process.env as EnvironmentVariables;
describe("Diff", () => {
let diff: Diff;
- beforeAll(async () => {
+ beforeAll(async() => {
const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO);
diff = await (await repository.masterCommit()).diff();
});
describe("Methods", () => {
- it("Should get the raw patches", async () => {
+ it("Should get the raw patches", async() => {
expect.assertions(2);
const raw_patches = await diff.rawPatches();
@@ -24,7 +24,7 @@ describe("Diff", () => {
expect(typeof raw_patches).toEqual("string");
});
- it("Should get the header data", async () => {
+ it("Should get the header data", async() => {
expect.assertions(4);
const patch_header_data = await diff.patchHeaderData();
@@ -36,7 +36,7 @@ describe("Diff", () => {
expect(patch_header_data).toHaveProperty("last");
});
- it("Should get the patches", async () => {
+ it("Should get the patches", async() => {
expect.hasAssertions();
const patches = await diff.patches();
diff --git a/test/unit/git-http.unit.test.ts b/test/unit/git-http.unit.test.ts
index b8a0917..418f32d 100644
--- a/test/unit/git-http.unit.test.ts
+++ b/test/unit/git-http.unit.test.ts
@@ -16,20 +16,20 @@ describe("Git HTTP backend", () => {
app = buildApp({
host: host,
port: port,
- dev_port: 0, // Doesn't matter
+ dev_port: 0,
title: "",
about: "",
base_dir: env.BASE_DIR,
production: false
}, "");
});
-
- afterAll(async () => {
+
+ afterAll(async() => {
await app.close();
- })
+ });
describe("info/refs", () => {
- it("Should make a valid response when the service is git-upload-pack", async () => {
+ it("Should make a valid response when the service is git-upload-pack", async() => {
expect.assertions(7);
const res = await app.inject({
@@ -49,7 +49,7 @@ describe("Git HTTP backend", () => {
expect(payload_lines[payload_lines.length - 1]).toEqual("0000");
});
- it("Should respond with 403 when the service is git-receive-pack", async () => {
+ it("Should respond with 403 when the service is git-receive-pack", async() => {
expect.assertions(3);
const res = await app.inject({
@@ -64,18 +64,18 @@ describe("Git HTTP backend", () => {
});
describe("git-upload-pack", () => {
- it("Should make a valid response", async () => {
+ it("Should make a valid response", async() => {
expect.hasAssertions();
await app.listen(port);
-
+
const head = /^[a-f0-9]+/.exec((await readFile(`${env.BASE_DIR}/${env.AVAIL_REPO}/FETCH_HEAD`)).toString())[0];
const data = `0098want ${head} multi_ack_detailed no-done side-band-64k thin-pack ofs-delta deepen-since deepen-not agent=git/2.32.0\n00000009done`;
- // Send a post request to git-upload-pack with curl
- //
- // I did it this way because i just couldn't get chunked responses
- // to work with LightMyRequest or Supertest
+ /* Send a post request to git-upload-pack with curl
+
+ I did it this way because i just couldn't get chunked responses
+ to work with LightMyRequest or Supertest */
const res = new Promise((resolve: (value: Record<string, Buffer>) => void, reject: (value: ExecException) => void) => {
const curl_params = [
"-X POST",
@@ -118,33 +118,33 @@ describe("Git HTTP backend", () => {
readable_stdout[readable_stdout.length - 1] = readable_stdout[readable_stdout.length - 1].replace(/.*[\x01]/, "");
expect(readable_stdout[0]).toEqual("0008NAK");
- expect(readable_stdout[1]).toMatch(/Enumerating\ objects:\ \d+,\ done\.$/);
+ expect(readable_stdout[1]).toMatch(/Enumerating objects: \d+, done\.$/);
// Make sure the progress output for counting objects is fine and dandy
const counting_objects = readable_stdout[2].split("###");
for(const progress of counting_objects.slice(0, -1)) {
- expect(progress).toMatch(/^Counting\ objects:\s+\d+%\s\(\d+\/\d+\)/);
+ expect(progress).toMatch(/^Counting objects:\s+\d+%\s\(\d+\/\d+\)/);
}
-
- expect(counting_objects[counting_objects.length - 1]).toMatch(/^Counting\ objects:\s+\d+%\s\(\d+\/\d+\),\sdone\./);
+
+ expect(counting_objects[counting_objects.length - 1]).toMatch(/^Counting objects:\s+\d+%\s\(\d+\/\d+\),\sdone\./);
// Make sure the progress output for compressing objects is fine and dandy
const compressing_objects = readable_stdout[3].split("###");
-
+
for(const progress of compressing_objects.slice(0, -1)) {
- expect(progress).toMatch(/^Compressing\ objects:\s+\d+%\s\(\d+\/\d+\)/);
+ expect(progress).toMatch(/^Compressing objects:\s+\d+%\s\(\d+\/\d+\)/);
}
-
- expect(compressing_objects[counting_objects.length - 1]).toMatch(/^Compressing\ objects:\s+\d+%\s\(\d+\/\d+\),\sdone\./);
-
- //Just to be sure
- expect(readable_stdout[readable_stdout.length - 1]).toMatch(/^A?0{4}/);
+
+ expect(compressing_objects[counting_objects.length - 1]).toMatch(/^Compressing objects:\s+\d+%\s\(\d+\/\d+\),\sdone\./);
+
+ // Just to be sure
+ expect(readable_stdout[readable_stdout.length - 1]).toMatch(/^.?0{4}/);
});
});
describe("git-receive-pack", () => {
- it("Should respond with 403", async () => {
+ it("Should respond with 403", async() => {
expect.assertions(3);
const res = await app.inject({
@@ -154,7 +154,7 @@ describe("Git HTTP backend", () => {
"content-type": "application/x-git-receive-pack-request"
}
});
-
+
expect(res).toBeDefined();
expect(res).toHaveProperty("statusCode");
expect(res.statusCode).toEqual(403);
diff --git a/test/unit/misc.unit.test.ts b/test/unit/misc.unit.test.ts
index 95a1d2b..c45d8ba 100644
--- a/test/unit/misc.unit.test.ts
+++ b/test/unit/misc.unit.test.ts
@@ -7,21 +7,21 @@ const env = process.env as EnvironmentVariables;
describe("Miscellaneous functions", () => {
describe("findAsync", () => {
const data: Promise<string>[] = [
- new Promise((resolve) => {
+ new Promise(resolve => {
resolve("hello!");
}),
- new Promise((resolve) => {
+ new Promise(resolve => {
resolve("Dad i'm hungry");
}),
- new Promise((resolve) => {
- resolve("Hi, hungry. I'm dad")
+ new Promise(resolve => {
+ resolve("Hi, hungry. I'm dad");
})
];
- it("Should find an existent item in an array", async () => {
+ it("Should find an existent item in an array", async() => {
expect.assertions(2);
- const result = await findAsync(data, async (item) => {
+ const result = await findAsync(data, async item => {
return await item === "Dad i'm hungry";
});
@@ -29,10 +29,10 @@ describe("Miscellaneous functions", () => {
expect(result).toEqual("Dad i'm hungry");
});
- it("Should fail to find a nonexistent item in an array", async () => {
+ it("Should fail to find a nonexistent item in an array", async() => {
expect.assertions(1);
- const result = await findAsync(data, async (item) => {
+ const result = await findAsync(data, async item => {
return await item === "Hello there";
});
@@ -41,7 +41,7 @@ describe("Miscellaneous functions", () => {
});
describe("getFile", () => {
- it("Should return the content of a file in a bare git repository", async () => {
+ it("Should return the content of a file in a bare git repository", async() => {
expect.assertions(2);
const content = await getFile(env.BASE_DIR, env.AVAIL_REPO, "description");
@@ -50,7 +50,7 @@ describe("Miscellaneous functions", () => {
expect(content).toEqual("Unnamed repository; edit this file 'description' to name the repository.");
});
- it("Should fail to return the content of a nonexistent file in a bare repository", async () => {
+ it("Should fail to return the content of a nonexistent file in a bare repository", async() => {
expect.assertions(1);
await expect(getFile(env.BASE_DIR, env.AVAIL_REPO, "myselfasteem")).rejects.toBeInstanceOf(BaseError);
@@ -58,7 +58,7 @@ describe("Miscellaneous functions", () => {
});
describe("getDirectory", () => {
- it("Should return the content of a directory", async () => {
+ it("Should return the content of a directory", async() => {
expect.assertions(3);
const dir = await getDirectory(`${env.BASE_DIR}/${env.AVAIL_REPO}/refs`);
@@ -68,7 +68,7 @@ describe("Miscellaneous functions", () => {
expect(dir).toContain("tags");
});
- it("Should fail to return the content of a nonexistent directory", async () => {
+ it("Should fail to return the content of a nonexistent directory", async() => {
expect.assertions(1);
await expect(getDirectory(`${env.BASE_DIR}/${env.AVAIL_REPO}/something`)).rejects.toBeInstanceOf(BaseError);
diff --git a/test/unit/repository.unit.test.ts b/test/unit/repository.unit.test.ts
index 4fa851b..7d3f954 100644
--- a/test/unit/repository.unit.test.ts
+++ b/test/unit/repository.unit.test.ts
@@ -18,7 +18,7 @@ function expectRepositoryProperties(repository: Repository) {
}
describe("Repository", () => {
- it("Should open a repository", async () => {
+ it("Should open a repository", async() => {
expect.assertions(8);
const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO);
@@ -29,13 +29,13 @@ describe("Repository", () => {
expectRepositoryProperties(repository);
});
- it("Should fail to open a nonexistant repository", async () => {
+ it("Should fail to open a nonexistant repository", async() => {
expect.assertions(1);
await expect(Repository.open(env.BASE_DIR, env.UNAVAIL_REPO)).rejects.toBeInstanceOf(BaseError);
});
- it("Should open all repositories", async () => {
+ it("Should open all repositories", async() => {
expect.hasAssertions();
const all_repositories = await Repository.openAll(env.BASE_DIR);
@@ -44,7 +44,7 @@ describe("Repository", () => {
for(const repository of all_repositories) {
expect(repository).toBeDefined();
- expect(repository).toBeInstanceOf(Repository)
+ expect(repository).toBeInstanceOf(Repository);
expectRepositoryProperties(repository);
}
@@ -53,23 +53,23 @@ describe("Repository", () => {
describe("Methods", () => {
let repository: Repository;
- beforeAll(async () => {
+ beforeAll(async() => {
repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO);
});
- it("Should look up if an existent object exists and respond true", async () => {
+ it("Should look up if an existent object exists and respond true", async() => {
expect.assertions(1);
await expect(repository.lookupExists(env.AVAIL_OBJECT)).resolves.toBeTruthy();
});
- it("Should look up if an nonexistant object exists and respond false", async () => {
+ it("Should look up if an nonexistant object exists and respond false", async() => {
expect.assertions(1);
await expect(repository.lookupExists(env.UNAVAIL_OBJECT)).resolves.toBeFalsy();
});
- it("Should get the master commit", async () => {
+ it("Should get the master commit", async() => {
expect.assertions(8);
const master_commit = await repository.masterCommit();
@@ -80,7 +80,7 @@ describe("Repository", () => {
expectCommitProperties(master_commit);
});
- it("Should get the commits", async () => {
+ it("Should get the commits", async() => {
expect.hasAssertions();
const commits = await repository.commits();
@@ -95,7 +95,7 @@ describe("Repository", () => {
}
});
- it("Should get the tree", async () => {
+ it("Should get the tree", async() => {
expect.assertions(2);
const tree = await repository.tree();
@@ -104,7 +104,7 @@ describe("Repository", () => {
expect(tree).toBeInstanceOf(Tree);
});
- it("Should get the branches", async () => {
+ it("Should get the branches", async() => {
expect.hasAssertions();
const branches = await repository.branches();
@@ -120,7 +120,7 @@ describe("Repository", () => {
}
});
- it("Should get the tags", async () => {
+ it("Should get the tags", async() => {
expect.hasAssertions();
const tags = await repository.tags();
@@ -136,4 +136,4 @@ describe("Repository", () => {
}
});
});
-});
+}); \ No newline at end of file
diff --git a/test/unit/tree.unit.test.ts b/test/unit/tree.unit.test.ts
index 1f66435..1658c35 100644
--- a/test/unit/tree.unit.test.ts
+++ b/test/unit/tree.unit.test.ts
@@ -7,7 +7,7 @@ import { EnvironmentVariables } from "../util";
const env = process.env as EnvironmentVariables;
describe("Tree", () => {
- it("Should get the tree of a repository", async () => {
+ it("Should get the tree of a repository", async() => {
expect.assertions(2);
const tree = await Tree.ofRepository(await Repository.open(env.BASE_DIR, env.AVAIL_REPO));
@@ -19,13 +19,13 @@ describe("Tree", () => {
describe("Methods", () => {
let tree: Tree;
- beforeAll(async () => {
+ beforeAll(async() => {
tree = await Tree.ofRepository(await Repository.open(env.BASE_DIR, env.AVAIL_REPO));
});
it("Should get the entries", () => {
expect.hasAssertions();
-
+
const entries = tree.entries();
expect(entries).toBeDefined();
@@ -36,7 +36,7 @@ describe("Tree", () => {
}
});
- it("Should return the entry of a path", async () => {
+ it("Should return the entry of a path", async() => {
expect.assertions(2);
const entry = await tree.find("packages/server");
@@ -45,19 +45,19 @@ describe("Tree", () => {
expect(entry).toBeInstanceOf(Tree);
});
- it("Should fail to return the entry of a nonexistent path", async () => {
+ it("Should fail to return the entry of a nonexistent path", async() => {
expect.assertions(1);
await expect(tree.find("dependencies/libstd++")).rejects.toBeInstanceOf(BaseError);
});
- it("Should find out if an existent path exists and return true", async () => {
+ it("Should find out if an existent path exists and return true", async() => {
expect.assertions(1);
await expect(tree.findExists("packages/shared_types/package.json")).resolves.toBeTruthy();
});
- it("Should find out if a nonexistent path exists and return false", async () => {
+ it("Should find out if a nonexistent path exists and return false", async() => {
expect.assertions(1);
await expect(tree.findExists("packages/core/main.js")).resolves.toBeFalsy();
diff --git a/test/util.ts b/test/util.ts
index 6cc5cbc..5886514 100644
--- a/test/util.ts
+++ b/test/util.ts
@@ -11,7 +11,7 @@ export type EnvironmentVariables = {
UNAVAIL_COMMIT: string
}
-export function expectCommitProperties(commit: Commit) {
+export function expectCommitProperties(commit: Commit): void {
expect(commit).toHaveProperty("id");
expect(commit).toHaveProperty("author");
expect(commit).toHaveProperty("author.name");