Skip to content

Commit 0fde2ac

Browse files
committed
Refactor simple-git-hooks.test.js
1 parent 66cd8a7 commit 0fde2ac

File tree

16 files changed

+30
-32
lines changed

16 files changed

+30
-32
lines changed

Diff for: _tests/project_with_configuration_in_alternative_separate_cjs/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "simple-pre-commit-test-package",
2+
"name": "simple-git-hooks-test-package",
33
"version": "1.0.0",
44
"devDependencies": {
55
"simple-git-hooks": "1.0.0"

Diff for: _tests/project_with_configuration_in_alternative_separate_js/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "simple-pre-commit-test-package",
2+
"name": "simple-git-hooks-test-package",
33
"version": "1.0.0",
44
"devDependencies": {
55
"simple-git-hooks": "1.0.0"

Diff for: _tests/project_with_configuration_in_alternative_separate_json/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "simple-pre-commit-test-package",
2+
"name": "simple-git-hooks-test-package",
33
"version": "1.0.0",
44
"devDependencies": {
55
"simple-git-hooks": "1.0.0"

Diff for: _tests/project_with_configuration_in_package_json/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "simple-pre-commit-test-package",
2+
"name": "simple-git-hooks-test-package",
33
"version": "1.0.0",
44
"simple-git-hooks": {
55
"pre-commit": "exit 1"

Diff for: _tests/project_with_configuration_in_separate_cjs/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "simple-pre-commit-test-package",
2+
"name": "simple-git-hooks-test-package",
33
"version": "1.0.0",
44
"devDependencies": {
55
"simple-git-hooks": "1.0.0"

Diff for: _tests/project_with_configuration_in_separate_js/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "simple-pre-commit-test-package",
2+
"name": "simple-git-hooks-test-package",
33
"version": "1.0.0",
44
"devDependencies": {
55
"simple-git-hooks": "1.0.0"

Diff for: _tests/project_with_configuration_in_separate_json/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "simple-pre-commit-test-package",
2+
"name": "simple-git-hooks-test-package",
33
"version": "1.0.0",
44
"devDependencies": {
55
"simple-git-hooks": "1.0.0"

Diff for: _tests/project_with_custom_configuration/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "simple-pre-commit-test-package",
2+
"name": "simple-git-hooks-test-package",
33
"version": "1.0.0",
44
"devDependencies": {
55
"simple-git-hooks": "1.0.0"

Diff for: _tests/project_with_incorrect_configuration_in_package_json/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "simple-pre-commit-test-package",
2+
"name": "simple-git-hooks-test-package",
33
"version": "1.0.0",
44
"devDependencies": {
55
"simple-git-hooks": "1.0.0"

Diff for: _tests/project_with_simple_pre_commit_in_deps/package.json renamed to _tests/project_with_simple_git_hooks_in_deps/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "simple-pre-commit-test-package",
2+
"name": "simple-git-hooks-test-package",
33
"version": "1.0.0",
44
"dependencies": {
55
"simple-git-hooks": "1.0.0"

Diff for: _tests/project_with_simple_pre_commit_in_dev_deps/package.json renamed to _tests/project_with_simple_git_hooks_in_dev_deps/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "simple-pre-commit-test-package",
2+
"name": "simple-git-hooks-test-package",
33
"version": "1.0.0",
44
"devDependencies": {
55
"simple-git-hooks": "1.0.0"
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"name": "simple-pre-commit-test-package",
2+
"name": "simple-git-hooks-test-package",
33
"version": "1.0.0",
44
"simple-git-hooks": {
55
"pre-commit": "exit 1",
66
"preserveUnused": ["commit-msg"]
77
},
88
"devDependencies": {
9-
"simple-pre-commit": "1.0.0"
9+
"simple-git-hooks": "1.0.0"
1010
}
1111
}

Diff for: _tests/project_without_configuration/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "simple-pre-commit-test-package",
2+
"name": "simple-git-hooks-test-package",
33
"version": "1.0.0",
44
"devDependencies": {
55
"simple-git-hooks": "1.0.0"

Diff for: _tests/project_without_simple_pre_commit/package.json renamed to _tests/project_without_simple_git_hooks/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "simple-pre-commit-test-package",
2+
"name": "simple-git-hooks-test-package",
33
"version": "1.0.0",
44
"devDependencies": {
55
},

Diff for: simple-git-hooks.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function checkSimpleGitHooksInDependencies(projectRootPath) {
144144

145145
// if simple-git-hooks in dependencies -> note user that he should remove move it to devDeps!
146146
if ('dependencies' in packageJsonContent && 'simple-git-hooks' in packageJsonContent.dependencies) {
147-
console.log('[WARN] You should move simple-git-hooks to the devDependencies!')
147+
console.warn('[WARN] You should move simple-git-hooks to the devDependencies!')
148148
return true // We only check that we are in the correct package, e.g not in a dependency of a dependency
149149
}
150150
if (!('devDependencies' in packageJsonContent)) {
@@ -188,7 +188,7 @@ function _setHook(hook, command, projectRoot=process.cwd()) {
188188
const gitRoot = getGitProjectRoot(projectRoot)
189189

190190
if (!gitRoot) {
191-
console.log('[INFO] No `.git` root folder found, skipping')
191+
console.info('[INFO] No `.git` root folder found, skipping')
192192
return
193193
}
194194

@@ -204,7 +204,7 @@ function _setHook(hook, command, projectRoot=process.cwd()) {
204204
fs.writeFileSync(hookPath, hookCommand)
205205
fs.chmodSync(hookPath, 0o0755)
206206

207-
console.log(`[INFO] Successfully set the ${hook} with command: ${command}`)
207+
console.info(`[INFO] Successfully set the ${hook} with command: ${command}`)
208208
}
209209

210210
/**

Diff for: simple-git-hooks.test.js

+12-14
Original file line numberDiff line numberDiff line change
@@ -85,34 +85,32 @@ describe("Simple Git Hooks tests", () => {
8585
});
8686

8787
describe("checkSimpleGitHooksInDependencies", () => {
88-
const correctPackageJsonProjectPath = path.normalize(
89-
path.join(process.cwd(), "_tests", "project_with_simple_pre_commit_in_deps")
88+
const PROJECT_WITH_SIMPLE_GIT_HOOKS_IN_DEPS = path.normalize(
89+
path.join(process.cwd(), "_tests", "project_with_simple_git_hooks_in_deps")
9090
);
91-
const correctPackageJsonProjectPath_2 = path.normalize(
91+
const PROJECT_WITH_SIMPLE_GIT_HOOKS_IN_DEV_DEPS = path.normalize(
9292
path.join(
93-
process.cwd(),
94-
"_tests",
95-
"project_with_simple_pre_commit_in_dev_deps"
93+
process.cwd(), "_tests", "project_with_simple_git_hooks_in_dev_deps"
9694
)
9795
);
98-
const incorrectPackageJsonProjectPath = path.normalize(
99-
path.join(process.cwd(), "_tests", "project_without_simple_pre_commit")
96+
const PROJECT_WITHOUT_SIMPLE_GIT_HOOKS = path.normalize(
97+
path.join(process.cwd(), "_tests", "project_without_simple_git_hooks")
10098
);
101-
it("returns true if simple pre commit really in devDeps", () => {
99+
it("returns true if simple-git-hooks really in deps", () => {
102100
expect(
103-
simpleGitHooks.checkSimpleGitHooksInDependencies(correctPackageJsonProjectPath)
101+
simpleGitHooks.checkSimpleGitHooksInDependencies(PROJECT_WITH_SIMPLE_GIT_HOOKS_IN_DEPS)
104102
).toBe(true);
105103
});
106104

107-
it("returns true if simple pre commit really in deps", () => {
105+
it("returns true if simple-git-hooks really in devDeps", () => {
108106
expect(
109-
simpleGitHooks.checkSimpleGitHooksInDependencies(correctPackageJsonProjectPath_2)
107+
simpleGitHooks.checkSimpleGitHooksInDependencies(PROJECT_WITH_SIMPLE_GIT_HOOKS_IN_DEV_DEPS)
110108
).toBe(true);
111109
});
112110

113-
it("returns false if simple pre commit isn`t in deps", () => {
111+
it("returns false if simple-git-hooks isn`t in deps", () => {
114112
expect(
115-
simpleGitHooks.checkSimpleGitHooksInDependencies(incorrectPackageJsonProjectPath)
113+
simpleGitHooks.checkSimpleGitHooksInDependencies(PROJECT_WITHOUT_SIMPLE_GIT_HOOKS)
116114
).toBe(false);
117115
});
118116
});

0 commit comments

Comments
 (0)