diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | jest.config.js | 1 | ||||
-rw-r--r-- | package.json | 11 | ||||
-rw-r--r-- | test/setup.ts | 34 | ||||
-rw-r--r-- | test/test.env | 7 | ||||
-rw-r--r-- | test/unit/commit.unit.test.ts | 23 | ||||
-rw-r--r-- | test/unit/repository.unit.test.ts | 14 | ||||
-rw-r--r-- | yarn.lock | 21 |
8 files changed, 83 insertions, 29 deletions
@@ -1,5 +1,6 @@ .DS_Store node_modules +git dist settings.yml diff --git a/jest.config.js b/jest.config.js index 91a2d2c..b541da5 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,4 +1,5 @@ module.exports = { preset: 'ts-jest', testEnvironment: 'node', + globalSetup: "./test/setup.ts" };
\ No newline at end of file diff --git a/package.json b/package.json index abe276d..6f17e44 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "author": "HampusMat", "private": true, "scripts": { - "clean": "rm -rf node_modules dist packages/*/node_modules packages/*/dist", + "clean": "rm -rf node_modules git packages/*/node_modules packages/*/dist", "dev": "concurrently -k --kill-others-on-fail \"cd packages/client && yarn serve\" \"cd packages/server && yarn dev\"", "build": "cd packages/client && yarn build && cd ../server && yarn tsc", "start": "node packages/server/dist/app.js", @@ -15,12 +15,15 @@ "packages/*" ], "devDependencies": { + "@types/fs-extra": "^9.0.12", "@types/jest": "^26.0.23", + "client": "^1.0.0", "concurrently": "^6.2.0", + "dotenv": "^10.0.0", + "fs-extra": "^10.0.0", "jest": "^27.0.6", + "server": "^1.0.0", "ts-jest": "^27.0.3", - "typescript": "^4.3.5", - "client": "^1.0.0", - "server": "^1.0.0" + "typescript": "^4.3.5" } } diff --git a/test/setup.ts b/test/setup.ts new file mode 100644 index 0000000..d0b1410 --- /dev/null +++ b/test/setup.ts @@ -0,0 +1,34 @@ +import { access, mkdir, remove, copy } from "fs-extra"; +import { promisify } from "util"; +import { exec } from "child_process"; +import { config } from "dotenv"; + +const promiseExec = promisify(exec); +config({ path: "test/test.env" }); + +export default async function init() { + const can_access = await access(process.env.BASE_DIR) + .then(() => true) + .catch(() => false); + + console.log(can_access); + + if(can_access) { + await remove(process.env.BASE_DIR); + } + + await mkdir(process.env.BASE_DIR); + await mkdir(`${process.env.BASE_DIR}/${process.env.AVAIL_REPO}`); + + await copy(".git", `${process.env.BASE_DIR}/${process.env.AVAIL_REPO}`); + + process.chdir(`${process.env.BASE_DIR}/${process.env.AVAIL_REPO}`); + + const { stdout, stderr } = await promiseExec("git config core.bare true"); + + if(stderr) { + throw(stderr); + } + + process.chdir("../.."); +}
\ No newline at end of file diff --git a/test/test.env b/test/test.env new file mode 100644 index 0000000..4ff13ac --- /dev/null +++ b/test/test.env @@ -0,0 +1,7 @@ +BASE_DIR=git +AVAIL_REPO=githermit.git +UNAVAIL_REPO=angular +AVAIL_OBJECT=16778756fb25808a1311403590cd7d36fbbeee6c +UNAVAIL_OBJECT=601747563bff808a1d12403690cd7d36fbbeafcc +AVAIL_COMMIT=d546492f4fd400ae61a6abbe1905fdbc67451c4d +UNAVAIL_COMMIT=a546392f4fd440ae61a6afec1d25fdbc67251e2b
\ No newline at end of file diff --git a/test/unit/commit.unit.test.ts b/test/unit/commit.unit.test.ts index c4bb6f8..b8bd178 100644 --- a/test/unit/commit.unit.test.ts +++ b/test/unit/commit.unit.test.ts @@ -1,43 +1,32 @@ - import { Repository } from "server/src/git/repository"; import { Commit } from "server/src/git/commit"; describe("Commit", () => { - const base_dir = "/home/hampus/Projects"; - let repository: Repository; beforeAll(async () => { - repository = await Repository.open(base_dir, "githermit"); + repository = await Repository.open(process.env.BASE_DIR, process.env.AVAIL_REPO); }); test("Lookup a existing commit by id", async () => { - const id = "d546492f4fd400ae61a6abbe1905fdbc67451c4d"; - - const lookupCommit = jest.fn(() => Commit.lookup(repository, id)); + const lookupCommit = jest.fn(() => Commit.lookup(repository, process.env.AVAIL_COMMIT)); const commit = await lookupCommit(); expect(lookupCommit).toReturn(); - expect(commit.id).toBe(id); + expect(commit.id).toBe(process.env.AVAIL_COMMIT); }); test("Lookup a nonexistant commit by id throws", async () => { - const id = "a546392f4fd440ae61a6afec1d25fdbc67251e2b"; - - expect(Commit.lookup(repository, id)).rejects.toThrow(); + expect(Commit.lookup(repository, process.env.UNAVAIL_COMMIT)).rejects.toThrow(); }); test("Lookup if an existing commit exists by id", async () => { - const id = "d546492f4fd400ae61a6abbe1905fdbc67451c4d"; - - expect(Commit.lookupExists(repository, id)).resolves.toBeTruthy(); + expect(Commit.lookupExists(repository, process.env.AVAIL_COMMIT)).resolves.toBeTruthy(); }); test("Lookup if an nonexistant commit exists by id", async () => { - const id = "a546392f4fd440ae61a6afec1d25fdbc67251e2b"; - - expect(Commit.lookupExists(repository, id)).resolves.toBeFalsy(); + expect(Commit.lookupExists(repository, process.env.UNAVAIL_COMMIT)).resolves.toBeFalsy(); }); describe("Functions", () => { diff --git a/test/unit/repository.unit.test.ts b/test/unit/repository.unit.test.ts index 0e13a2a..2a68a29 100644 --- a/test/unit/repository.unit.test.ts +++ b/test/unit/repository.unit.test.ts @@ -1,10 +1,8 @@ import { Repository } from "server/src/git/repository"; describe("Repository", () => { - const base_dir = "/home/hampus/Projects"; - test("Open existing repository", async () => { - const openRepository = jest.fn(() => Repository.open(base_dir, "githermit")); + const openRepository = jest.fn(() => Repository.open(process.env.BASE_DIR, process.env.AVAIL_REPO)); await openRepository(); @@ -12,11 +10,11 @@ describe("Repository", () => { }); test("Open nonexistant repository throws", async () => { - expect(Repository.open(base_dir, "angular")).rejects.toThrow(); + expect(Repository.open(process.env.BASE_DIR, process.env.UNAVAIL_REPO)).rejects.toThrow(); }); test("Open all repositories", async () => { - const openAllRepositories = jest.fn(() => Repository.openAll(base_dir)); + const openAllRepositories = jest.fn(() => Repository.openAll(process.env.BASE_DIR)); await openAllRepositories(); @@ -27,17 +25,17 @@ describe("Repository", () => { let repository: Repository; beforeAll(async () => { - repository = await Repository.open(base_dir, "githermit"); + repository = await Repository.open(process.env.BASE_DIR, process.env.AVAIL_REPO); }); test("Lookup if an existing object exists", async () => { - const exists = await repository.lookupExists("16778756fb25808a1311403590cd7d36fbbeee6c"); + const exists = await repository.lookupExists(process.env.AVAIL_OBJECT); expect(exists).toBeTruthy(); }); test("Lookup if an nonexistant object exists", async () => { - const exists = await repository.lookupExists("601747563bff808a1d12403690cd7d36fbbeafcc"); + const exists = await repository.lookupExists(process.env.UNAVAIL_OBJECT); expect(exists).toBeFalsy(); }); @@ -1615,6 +1615,13 @@ "@types/qs" "*" "@types/serve-static" "*" +"@types/fs-extra@^9.0.12": + version "9.0.12" + resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-9.0.12.tgz#9b8f27973df8a7a3920e8461517ebf8a7d4fdfaf" + integrity sha512-I+bsBr67CurCGnSenZZ7v94gd3tc3+Aj2taxMT4yu4ABLuOgOjeFxX3dokG24ztSRg5tnT00sL8BszO7gSMoIw== + dependencies: + "@types/node" "*" + "@types/glob@^7.1.1": version "7.1.3" resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.3.tgz#e6ba80f36b7daad2c685acd9266382e68985c183" @@ -4798,6 +4805,11 @@ dotenv-expand@^5.1.0: resolved "https://registry.yarnpkg.com/dotenv-expand/-/dotenv-expand-5.1.0.tgz#3fbaf020bfd794884072ea26b1e9791d45a629f0" integrity sha512-YXQl1DSa4/PQyRfgrv6aoNjhasp/p4qs9FjJ4q4cQk+8m4r6k4ZSiEyytKG8f8W9gi8WsQtIObNmKd+tMzNTmA== +dotenv@^10.0.0: + version "10.0.0" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81" + integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q== + dotenv@^8.2.0: version "8.6.0" resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.6.0.tgz#061af664d19f7f4d8fc6e4ff9b584ce237adcb8b" @@ -5896,6 +5908,15 @@ fs-constants@^1.0.0: resolved "https://registry.yarnpkg.com/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad" integrity sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow== +fs-extra@^10.0.0: + version "10.0.0" + resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.0.0.tgz#9ff61b655dde53fb34a82df84bb214ce802e17c1" + integrity sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ== + dependencies: + graceful-fs "^4.2.0" + jsonfile "^6.0.1" + universalify "^2.0.0" + fs-extra@^7.0.0, fs-extra@^7.0.1: version "7.0.1" resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9" |