Skip to content

Commit 38d1cbf

Browse files
committed
test(conventional-commits): add two tests
1 parent 7597c8d commit 38d1cbf

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

plugins/conventional-commits/__tests__/conventional-commits.test.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,57 @@ test("should add conventional commit label if none/skip", async () => {
211211
const result = await logParse.normalizeCommit(commit);
212212
expect(result?.labels).toStrictEqual(["skip-release", "internal", "patch"]);
213213
});
214+
215+
test("should not add skip when a non skip commit is present with a skip commit", async () => {
216+
const commit = makeCommitFromMsg("fix: a test");
217+
const conventionalCommitsPlugin = new ConventionalCommitsPlugin();
218+
const logParse = new LogParse();
219+
const autoHooks = makeHooks();
220+
const mockGit = ({
221+
getUserByEmail: jest.fn(),
222+
searchRepo: jest.fn(),
223+
getCommitDate: jest.fn(),
224+
getFirstCommit: jest.fn(),
225+
getPr: jest.fn(),
226+
getLatestRelease: () => Promise.resolve("1.2.3"),
227+
getGitLog: () =>
228+
Promise.resolve([commit, makeCommitFromMsg("chore: a test 2")]),
229+
getCommitsForPR: () => Promise.resolve([{ sha: "1" }]),
230+
} as unknown) as Git;
231+
232+
conventionalCommitsPlugin.apply({
233+
hooks: autoHooks,
234+
labels: defaultLabels,
235+
semVerLabels: versionLabels,
236+
logger: dummyLog(),
237+
git: mockGit,
238+
release: new Release(mockGit),
239+
} as Auto);
240+
241+
autoHooks.onCreateLogParse.call(logParse);
242+
243+
const result = await logParse.normalizeCommit(commit);
244+
expect(result?.labels).toStrictEqual(["patch"]);
245+
});
246+
247+
test("should skip when not a fix/feat/breaking change commit", async () => {
248+
const conventionalCommitsPlugin = new ConventionalCommitsPlugin();
249+
const autoHooks = makeHooks();
250+
conventionalCommitsPlugin.apply({
251+
hooks: autoHooks,
252+
labels: defaultLabels,
253+
semVerLabels: versionLabels,
254+
logger: dummyLog(),
255+
} as Auto);
256+
257+
const logParseHooks = makeLogParseHooks();
258+
autoHooks.onCreateLogParse.call({
259+
hooks: logParseHooks,
260+
} as LogParse);
261+
262+
const commit = makeCommitFromMsg("chore: i should not trigger a release");
263+
expect(await logParseHooks.parseCommit.promise({ ...commit })).toStrictEqual({
264+
...commit,
265+
labels: ["skip-release"],
266+
});
267+
});

0 commit comments

Comments
 (0)