|
| 1 | +const { exec } = require("child_process"); |
| 2 | +const { |
| 3 | + repoOwner, |
| 4 | + repoName, |
| 5 | + correctBranch, |
| 6 | + wrongBranch, |
| 7 | +} = require("./test.common.js"); |
| 8 | + |
| 9 | +describe("github.js", () => { |
| 10 | + describe("commit command", () => { |
| 11 | + test("commit command, good branch", (done) => { |
| 12 | + exec( |
| 13 | + `node github.js commit -o ${repoOwner} -r ${repoName} -b ${correctBranch} -c dummy/file1.txt -m "this is a commit msg"`, |
| 14 | + (error, stdout, stderr) => { |
| 15 | + expect(error).toBeNull(); |
| 16 | + expect(stdout).toContain( |
| 17 | + `Commit created: https://github.com/${repoOwner}/${repoName}/commit` |
| 18 | + ); |
| 19 | + done(); |
| 20 | + } |
| 21 | + ); |
| 22 | + }, 10000); |
| 23 | + |
| 24 | + test("commit command, BAD branch", (done) => { |
| 25 | + exec( |
| 26 | + `node github.js commit -o ${repoOwner} -r ${repoName} -b ${wrongBranch} -c dummy/file1.txt -m "this is a commit msg"`, |
| 27 | + (error, stdout, stderr) => { |
| 28 | + expect(error).not.toBeNull(); |
| 29 | + expect(stderr).toMatch(/Failed to create commit:/); |
| 30 | + done(); |
| 31 | + } |
| 32 | + ); |
| 33 | + }, 10000); |
| 34 | + }); |
| 35 | + |
| 36 | + describe("branch command", () => { |
| 37 | + test("branch command, good branch", (done) => { |
| 38 | + exec( |
| 39 | + `node github.js branch -o ${repoOwner} -r ${repoName} -b ${correctBranch}`, |
| 40 | + (error, stdout, stderr) => { |
| 41 | + expect(error).toBeNull(); |
| 42 | + expect(stdout).toContain( |
| 43 | + `Repository ${repoOwner}/${repoName} has a branch named '${correctBranch}'` |
| 44 | + ); |
| 45 | + done(); |
| 46 | + } |
| 47 | + ); |
| 48 | + }, 10000); |
| 49 | + |
| 50 | + test("branch command, BAD branch", (done) => { |
| 51 | + exec( |
| 52 | + `node github.js branch -o ${repoOwner} -r ${repoName} -b ${wrongBranch}`, |
| 53 | + (error, stdout, stderr) => { |
| 54 | + expect(error).toBeNull(); |
| 55 | + expect(stdout).toContain( |
| 56 | + `Repository ${repoOwner}/${repoName} has no branch named '${wrongBranch}'` |
| 57 | + ); |
| 58 | + done(); |
| 59 | + } |
| 60 | + ); |
| 61 | + }, 10000); |
| 62 | + }); |
| 63 | +}); |
0 commit comments