diff options
author | HampusM <hampus@hampusmat.com> | 2021-07-22 17:56:41 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2021-07-22 17:56:41 +0200 |
commit | df7f89172f932ea918405ebafd11133f1aeeef05 (patch) | |
tree | 6dc68e78a7404ac81b8647912ca58ed840ed7618 /test | |
parent | 2d969e3a0c52b87db2df72f1598fed50d0a4b831 (diff) |
Added diff unit test & exported the PatchHeaderData type
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/diff.unit.test.ts | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/test/unit/diff.unit.test.ts b/test/unit/diff.unit.test.ts new file mode 100644 index 0000000..952abb0 --- /dev/null +++ b/test/unit/diff.unit.test.ts @@ -0,0 +1,52 @@ +import { Repository } from "server/src/git/repository"; +import { Diff, PatchHeaderData } from "server/src/git/diff"; +import { EnvironmentVariables } from "../util"; +import { Patch } from "../../packages/server/src/git/patch"; + +const env = process.env as EnvironmentVariables; + +describe("Diff", () => { + let diff: Diff; + + 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 () => { + expect.assertions(2); + + const raw_patches = await diff.rawPatches(); + + expect(raw_patches).toBeDefined(); + expect(typeof raw_patches).toEqual("string"); + }); + + it("Should get the header data", async () => { + expect.assertions(4); + + const patch_header_data = await diff.patchHeaderData(); + + expect(patch_header_data).toBeDefined(); + + expect(patch_header_data).toHaveProperty("indexes"); + expect(patch_header_data).toHaveProperty("lengths"); + expect(patch_header_data).toHaveProperty("last"); + }); + + it("Should get the patches", async () => { + expect.hasAssertions(); + + const patches = await diff.patches(); + + expect(patches).toBeDefined(); + + for(const patch of patches) { + expect(patch).toBeDefined(); + expect(patch).toBeInstanceOf(Patch); + } + }); + }); +});
\ No newline at end of file |