add tests, fix pushing issues
This commit is contained in:
parent
15fc6f9d42
commit
ce4252ef16
|
@ -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(
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue