Skip to content

Commit

Permalink
test(conventional-commits): add two tests
Browse files Browse the repository at this point in the history
  • Loading branch information
krohrsb committed Mar 30, 2020
1 parent 7597c8d commit 38d1cbf
Showing 1 changed file with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,57 @@ test("should add conventional commit label if none/skip", async () => {
const result = await logParse.normalizeCommit(commit);
expect(result?.labels).toStrictEqual(["skip-release", "internal", "patch"]);
});

test("should not add skip when a non skip commit is present with a skip commit", async () => {
const commit = makeCommitFromMsg("fix: a test");
const conventionalCommitsPlugin = new ConventionalCommitsPlugin();
const logParse = new LogParse();
const autoHooks = makeHooks();
const mockGit = ({
getUserByEmail: jest.fn(),
searchRepo: jest.fn(),
getCommitDate: jest.fn(),
getFirstCommit: jest.fn(),
getPr: jest.fn(),
getLatestRelease: () => Promise.resolve("1.2.3"),
getGitLog: () =>
Promise.resolve([commit, makeCommitFromMsg("chore: a test 2")]),
getCommitsForPR: () => Promise.resolve([{ sha: "1" }]),
} as unknown) as Git;

conventionalCommitsPlugin.apply({
hooks: autoHooks,
labels: defaultLabels,
semVerLabels: versionLabels,
logger: dummyLog(),
git: mockGit,
release: new Release(mockGit),
} as Auto);

autoHooks.onCreateLogParse.call(logParse);

const result = await logParse.normalizeCommit(commit);
expect(result?.labels).toStrictEqual(["patch"]);
});

test("should skip when not a fix/feat/breaking change commit", async () => {
const conventionalCommitsPlugin = new ConventionalCommitsPlugin();
const autoHooks = makeHooks();
conventionalCommitsPlugin.apply({
hooks: autoHooks,
labels: defaultLabels,
semVerLabels: versionLabels,
logger: dummyLog(),
} as Auto);

const logParseHooks = makeLogParseHooks();
autoHooks.onCreateLogParse.call({
hooks: logParseHooks,
} as LogParse);

const commit = makeCommitFromMsg("chore: i should not trigger a release");
expect(await logParseHooks.parseCommit.promise({ ...commit })).toStrictEqual({
...commit,
labels: ["skip-release"],
});
});

0 comments on commit 38d1cbf

Please sign in to comment.