forked from lerna/lerna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-commit.test.js
52 lines (43 loc) · 1.94 KB
/
git-commit.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"use strict";
jest.mock("@lerna/temp-write");
jest.mock("@lerna/child-process");
const { EOL } = require("os");
const tempWrite = require("@lerna/temp-write");
const childProcess = require("@lerna/child-process");
const { gitCommit } = require("../lib/git-commit");
describe("git commit", () => {
childProcess.exec.mockResolvedValue();
tempWrite.sync.mockReturnValue("temp-file-path");
test("--message", async () => {
const opts = { cwd: "message" };
await gitCommit("subject", {}, opts);
expect(childProcess.exec).toHaveBeenLastCalledWith("git", ["commit", "-m", "subject"], opts);
});
test("--message <multiline>", async () => {
const message = `subject${EOL}${EOL}body`;
const opts = { cwd: "multi-line" };
await gitCommit(message, {}, opts);
expect(tempWrite.sync).toHaveBeenLastCalledWith(message, "lerna-commit.txt");
expect(childProcess.exec).toHaveBeenLastCalledWith("git", ["commit", "-F", "temp-file-path"], opts);
});
test("--amend", async () => {
const opts = { cwd: "no-edit" };
await gitCommit("whoops", { amend: true }, opts);
expect(childProcess.exec).toHaveBeenLastCalledWith("git", ["commit", "--amend", "--no-edit"], opts);
});
test("--no-commit-hooks", async () => {
const opts = { cwd: "no-verify" };
await gitCommit("yolo", { commitHooks: false }, opts);
expect(childProcess.exec).toHaveBeenLastCalledWith("git", ["commit", "--no-verify", "-m", "yolo"], opts);
});
test("--sign-git-commit", async () => {
const opts = { cwd: "signed" };
await gitCommit("nice", { signGitCommit: true }, opts);
expect(childProcess.exec).toHaveBeenLastCalledWith("git", ["commit", "--gpg-sign", "-m", "nice"], opts);
});
test("--signoff-git-commit", async () => {
const opts = { cwd: "signed-off" };
await gitCommit("nice", { signoffGitCommit: true }, opts);
expect(childProcess.exec).toHaveBeenLastCalledWith("git", ["commit", "--signoff", "-m", "nice"], opts);
});
});