Skip to content

Commit 818ff26

Browse files
committed
add test cases
1 parent 79114d1 commit 818ff26

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

simple-git-hooks.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,30 @@ describe("Simple Git Hooks tests", () => {
361361
expect(isEqual(installedHooks, {})).toBe(true);
362362
});
363363

364+
it("only removes git hooks which are not in preserveUnused", () => {
365+
createGitHooksFolder(PROJECT_WITH_UNUSED_CONF_IN_PACKAGE_JSON);
366+
367+
const installedHooksDir = path.normalize(
368+
path.join(PROJECT_WITH_UNUSED_CONF_IN_PACKAGE_JSON, ".git", "hooks")
369+
);
370+
371+
fs.writeFileSync(
372+
path.resolve(installedHooksDir, "commit-msg"),
373+
"# do nothing"
374+
);
375+
376+
let installedHooks = getInstalledGitHooks(installedHooksDir);
377+
378+
expect(isEqual(installedHooks, { "commit-msg": "# do nothing" })).toBe(true);
379+
380+
simpleGitHooks.setHooksFromConfig(PROJECT_WITH_UNUSED_CONF_IN_PACKAGE_JSON);
381+
382+
simpleGitHooks.removeHooks(PROJECT_WITH_UNUSED_CONF_IN_PACKAGE_JSON);
383+
384+
installedHooks = getInstalledGitHooks(installedHooksDir);
385+
expect(isEqual(installedHooks, { "commit-msg": "# do nothing" })).toBe(true);
386+
});
387+
364388
it("creates git hooks and removes unused git hooks", () => {
365389
createGitHooksFolder(PROJECT_WITH_CONF_IN_PACKAGE_JSON);
366390

0 commit comments

Comments
 (0)