-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use SIMPLE_GIT_HOOKS_RC to run optional init script (#102)
- Loading branch information
1 parent
20121df
commit a315a60
Showing
5 changed files
with
76 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
_tests/project_with_configuration_in_package_json/initrc_that_does_nothing.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
echo SIMPLE_GIT_HOOKS_RC that does nothing. |
1 change: 1 addition & 0 deletions
1
_tests/project_with_configuration_in_package_json/initrc_that_prevents_hook_fail.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
alias exit=echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -459,7 +459,7 @@ describe("CLI Command-Based Hook Management", () => { | |
}); | ||
}); | ||
|
||
describe("Tests for skipping git hooks using SKIP_SIMPLE_GIT_HOOKS env var", () => { | ||
describe("Test env vars", () => { | ||
const GIT_USER_NAME = "github-actions"; | ||
const GIT_USER_EMAIL = "[email protected]"; | ||
|
||
|
@@ -493,10 +493,6 @@ describe("Tests for skipping git hooks using SKIP_SIMPLE_GIT_HOOKS env var", () | |
spc.setHooksFromConfig(projectWithConfigurationInPackageJsonPath); | ||
}); | ||
|
||
afterEach(() => { | ||
delete process.env.SKIP_SIMPLE_GIT_HOOKS; | ||
}); | ||
|
||
const expectCommitToSucceed = (path) => { | ||
const errorOccurred = performTestCommit(path); | ||
expect(errorOccurred).toBe(false); | ||
|
@@ -507,22 +503,48 @@ describe("Tests for skipping git hooks using SKIP_SIMPLE_GIT_HOOKS env var", () | |
expect(errorOccurred).toBe(true); | ||
}; | ||
|
||
it('commits successfully when SKIP_SIMPLE_GIT_HOOKS is set to "1"', () => { | ||
process.env.SKIP_SIMPLE_GIT_HOOKS = "1"; | ||
expectCommitToSucceed(projectWithConfigurationInPackageJsonPath); | ||
}); | ||
describe("SKIP_SIMPLE_GIT_HOOKS", () => { | ||
afterEach(() => { | ||
delete process.env.SKIP_SIMPLE_GIT_HOOKS; | ||
}); | ||
|
||
it("fails to commit when SKIP_SIMPLE_GIT_HOOKS is not set", () => { | ||
expectCommitToFail(projectWithConfigurationInPackageJsonPath); | ||
}); | ||
it('commits successfully when SKIP_SIMPLE_GIT_HOOKS is set to "1"', () => { | ||
process.env.SKIP_SIMPLE_GIT_HOOKS = "1"; | ||
expectCommitToSucceed(projectWithConfigurationInPackageJsonPath); | ||
}); | ||
|
||
it('fails to commit when SKIP_SIMPLE_GIT_HOOKS is set to "0"', () => { | ||
process.env.SKIP_SIMPLE_GIT_HOOKS = "0"; | ||
expectCommitToFail(projectWithConfigurationInPackageJsonPath); | ||
}); | ||
it("fails to commit when SKIP_SIMPLE_GIT_HOOKS is not set", () => { | ||
expectCommitToFail(projectWithConfigurationInPackageJsonPath); | ||
}); | ||
|
||
it("fails to commit when SKIP_SIMPLE_GIT_HOOKS is set to a random string", () => { | ||
process.env.SKIP_SIMPLE_GIT_HOOKS = "simple-git-hooks"; | ||
expectCommitToFail(projectWithConfigurationInPackageJsonPath); | ||
}); | ||
it('fails to commit when SKIP_SIMPLE_GIT_HOOKS is set to "0"', () => { | ||
process.env.SKIP_SIMPLE_GIT_HOOKS = "0"; | ||
expectCommitToFail(projectWithConfigurationInPackageJsonPath); | ||
}); | ||
|
||
it("fails to commit when SKIP_SIMPLE_GIT_HOOKS is set to a random string", () => { | ||
process.env.SKIP_SIMPLE_GIT_HOOKS = "simple-git-hooks"; | ||
expectCommitToFail(projectWithConfigurationInPackageJsonPath); | ||
}); | ||
}) | ||
|
||
describe("SIMPLE_GIT_HOOKS_RC", () => { | ||
afterEach(() => { | ||
delete process.env.SIMPLE_GIT_HOOKS_RC; | ||
}); | ||
|
||
it("fails to commit when SIMPLE_GIT_HOOKS_RC is not set", () => { | ||
expectCommitToFail(projectWithConfigurationInPackageJsonPath); | ||
}); | ||
|
||
it('commits successfully when SIMPLE_GIT_HOOKS_RC points to initrc_that_prevents_hook_fail.sh', () => { | ||
process.env.SIMPLE_GIT_HOOKS_RC = path.join(projectWithConfigurationInPackageJsonPath, "initrc_that_prevents_hook_fail.sh"); | ||
expectCommitToSucceed(projectWithConfigurationInPackageJsonPath); | ||
}); | ||
|
||
it('fails to commit when SIMPLE_GIT_HOOKS_RC points to initrc_that_does_nothing.sh', () => { | ||
process.env.SIMPLE_GIT_HOOKS_RC = path.join(projectWithConfigurationInPackageJsonPath, "initrc_that_does_nothing.sh"); | ||
expectCommitToFail(projectWithConfigurationInPackageJsonPath); | ||
}); | ||
}) | ||
}); |