Skip to content

Commit f9bb8f8

Browse files
committed
added tests for github.js file
1 parent 3d5143c commit f9bb8f8

4 files changed

Lines changed: 68 additions & 2 deletions

File tree

github.test.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
});

index.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
require("dotenv").config();
21
const {
32
repoOwner,
43
repoName,

jest.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// add dot env to all jest tests
2+
require("dotenv").config();

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
},
1010
"scripts": {
1111
"gh": "node github.js",
12-
"test": "jest"
12+
"test": "jest",
13+
"test:index": "jest --testPathPattern=index.test.js",
14+
"test:github": "jest --testPathPattern=github.test.js"
1315
},
1416
"keywords": [
1517
"git",

0 commit comments

Comments
 (0)