Skip to content

Commit

Permalink
Refactor simple-git-hooks.test.js
Browse files Browse the repository at this point in the history
  • Loading branch information
toplenboren committed Mar 3, 2024
1 parent 66cd8a7 commit 0fde2ac
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "simple-pre-commit-test-package",
"name": "simple-git-hooks-test-package",
"version": "1.0.0",
"devDependencies": {
"simple-git-hooks": "1.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "simple-pre-commit-test-package",
"name": "simple-git-hooks-test-package",
"version": "1.0.0",
"devDependencies": {
"simple-git-hooks": "1.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "simple-pre-commit-test-package",
"name": "simple-git-hooks-test-package",
"version": "1.0.0",
"devDependencies": {
"simple-git-hooks": "1.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "simple-pre-commit-test-package",
"name": "simple-git-hooks-test-package",
"version": "1.0.0",
"simple-git-hooks": {
"pre-commit": "exit 1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "simple-pre-commit-test-package",
"name": "simple-git-hooks-test-package",
"version": "1.0.0",
"devDependencies": {
"simple-git-hooks": "1.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "simple-pre-commit-test-package",
"name": "simple-git-hooks-test-package",
"version": "1.0.0",
"devDependencies": {
"simple-git-hooks": "1.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "simple-pre-commit-test-package",
"name": "simple-git-hooks-test-package",
"version": "1.0.0",
"devDependencies": {
"simple-git-hooks": "1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion _tests/project_with_custom_configuration/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "simple-pre-commit-test-package",
"name": "simple-git-hooks-test-package",
"version": "1.0.0",
"devDependencies": {
"simple-git-hooks": "1.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "simple-pre-commit-test-package",
"name": "simple-git-hooks-test-package",
"version": "1.0.0",
"devDependencies": {
"simple-git-hooks": "1.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "simple-pre-commit-test-package",
"name": "simple-git-hooks-test-package",
"version": "1.0.0",
"dependencies": {
"simple-git-hooks": "1.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "simple-pre-commit-test-package",
"name": "simple-git-hooks-test-package",
"version": "1.0.0",
"devDependencies": {
"simple-git-hooks": "1.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "simple-pre-commit-test-package",
"name": "simple-git-hooks-test-package",
"version": "1.0.0",
"simple-git-hooks": {
"pre-commit": "exit 1",
"preserveUnused": ["commit-msg"]
},
"devDependencies": {
"simple-pre-commit": "1.0.0"
"simple-git-hooks": "1.0.0"
}
}
2 changes: 1 addition & 1 deletion _tests/project_without_configuration/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "simple-pre-commit-test-package",
"name": "simple-git-hooks-test-package",
"version": "1.0.0",
"devDependencies": {
"simple-git-hooks": "1.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "simple-pre-commit-test-package",
"name": "simple-git-hooks-test-package",
"version": "1.0.0",
"devDependencies": {
},
Expand Down
6 changes: 3 additions & 3 deletions simple-git-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function checkSimpleGitHooksInDependencies(projectRootPath) {

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

if (!gitRoot) {
console.log('[INFO] No `.git` root folder found, skipping')
console.info('[INFO] No `.git` root folder found, skipping')
return
}

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

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

/**
Expand Down
26 changes: 12 additions & 14 deletions simple-git-hooks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,34 +85,32 @@ describe("Simple Git Hooks tests", () => {
});

describe("checkSimpleGitHooksInDependencies", () => {
const correctPackageJsonProjectPath = path.normalize(
path.join(process.cwd(), "_tests", "project_with_simple_pre_commit_in_deps")
const PROJECT_WITH_SIMPLE_GIT_HOOKS_IN_DEPS = path.normalize(
path.join(process.cwd(), "_tests", "project_with_simple_git_hooks_in_deps")
);
const correctPackageJsonProjectPath_2 = path.normalize(
const PROJECT_WITH_SIMPLE_GIT_HOOKS_IN_DEV_DEPS = path.normalize(
path.join(
process.cwd(),
"_tests",
"project_with_simple_pre_commit_in_dev_deps"
process.cwd(), "_tests", "project_with_simple_git_hooks_in_dev_deps"
)
);
const incorrectPackageJsonProjectPath = path.normalize(
path.join(process.cwd(), "_tests", "project_without_simple_pre_commit")
const PROJECT_WITHOUT_SIMPLE_GIT_HOOKS = path.normalize(
path.join(process.cwd(), "_tests", "project_without_simple_git_hooks")
);
it("returns true if simple pre commit really in devDeps", () => {
it("returns true if simple-git-hooks really in deps", () => {
expect(
simpleGitHooks.checkSimpleGitHooksInDependencies(correctPackageJsonProjectPath)
simpleGitHooks.checkSimpleGitHooksInDependencies(PROJECT_WITH_SIMPLE_GIT_HOOKS_IN_DEPS)
).toBe(true);
});

it("returns true if simple pre commit really in deps", () => {
it("returns true if simple-git-hooks really in devDeps", () => {
expect(
simpleGitHooks.checkSimpleGitHooksInDependencies(correctPackageJsonProjectPath_2)
simpleGitHooks.checkSimpleGitHooksInDependencies(PROJECT_WITH_SIMPLE_GIT_HOOKS_IN_DEV_DEPS)
).toBe(true);
});

it("returns false if simple pre commit isn`t in deps", () => {
it("returns false if simple-git-hooks isn`t in deps", () => {
expect(
simpleGitHooks.checkSimpleGitHooksInDependencies(incorrectPackageJsonProjectPath)
simpleGitHooks.checkSimpleGitHooksInDependencies(PROJECT_WITHOUT_SIMPLE_GIT_HOOKS)
).toBe(false);
});
});
Expand Down

0 comments on commit 0fde2ac

Please sign in to comment.