From ce4252ef168d3690ea11773e1dd6f7d36ef39236 Mon Sep 17 00:00:00 2001 From: Tejas Srikanth Date: Tue, 4 Apr 2023 00:54:06 -0400 Subject: [PATCH] add tests, fix pushing issues --- src/gitClient.ts | 4 ++-- src/test/gitclient.test.ts | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/gitClient.ts b/src/gitClient.ts index 61448e7..c15a263 100644 --- a/src/gitClient.ts +++ b/src/gitClient.ts @@ -53,7 +53,7 @@ export async function pushRepo(repoPath: string) { export async function commitRepo(repoPath) { try{ - const stdOut = execSync(`git -C ${repoPath} commit -m \'event commit\'`); + const stdOut = execSync(`git -C ${repoPath} add . && git -C ${repoPath} commit -m \'event commit\'`); console.log(`Push output is: ${stdOut}`); } catch (error){ console.error( @@ -71,7 +71,7 @@ export async function createAndPublishNewBranch(repoPath) { try{ var id = uuid(); execSync( - `git -C ${repoPath} checkout -b ${id} && git -C ${repoPath} push -u origin` + `git -C ${repoPath} checkout -b ${id} && git -C ${repoPath} push -u origin --set-upstream ${id}` ); } catch (error){ console.error( diff --git a/src/test/gitclient.test.ts b/src/test/gitclient.test.ts index a366b1e..5a908c2 100644 --- a/src/test/gitclient.test.ts +++ b/src/test/gitclient.test.ts @@ -1,5 +1,6 @@ -import { cloneRepo, commitRepo, pushRepo, removeRepo } from "../gitClient"; +import { cloneRepo, commitRepo, createAndPublishNewBranch, pushRepo, removeRepo } from "../gitClient"; import { existsSync, readdirSync } from "fs"; +import { execSync } from "child_process"; test("successfully clones repo", async () => { const folderPath = await cloneRepo("https://github.com/octocat/Spoon-Knife"); @@ -10,6 +11,38 @@ test("successfully clones repo", async () => { expect(directoryContents).toContain("README.md"); }); +test("successfully commits to repo", async () => { + const folderPath = await cloneRepo("https://github.com/octocat/Spoon-Knife"); + let thrownError = undefined; + try{ + execSync(`cd ${folderPath} && touch newFile.ts`); + await commitRepo(folderPath); + const directoryContents = readdirSync(folderPath); + expect(directoryContents).toContain("newFile.ts") + } catch(error){ + thrownError = error; + } + expect(thrownError).toBeUndefined(); + +}) + +test("successfully pushes to repo", async () => { + const folderPath = await cloneRepo("https://github.com/tejas-srikanth/Watopoly"); // NOTE: user needs permission to push to repo in order for this to work + let thrownError = undefined; + try{ + execSync(`cd ${folderPath} && touch newerFile.ts`); + await createAndPublishNewBranch(folderPath); + await commitRepo(folderPath); + await pushRepo(folderPath); + const directoryContents = readdirSync(folderPath); + expect(directoryContents).toContain("newerFile.ts") + } catch(error){ + thrownError = error; + } + expect(thrownError).toBeUndefined(); + +}) + test("throws error if can't clone repo", async () => { let thrownError = undefined; try {