Skip to content

Commit c846d70

Browse files
committed
chore: wip
1 parent d6e4e73 commit c846d70

File tree

25 files changed

+117
-91
lines changed

25 files changed

+117
-91
lines changed

scripts/uninstall.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
#!/usr/bin/env node
22

3-
import { removeHooks } from "../src/git-hooks"
3+
import { removeHooks } from '../src/git-hooks'
44

55
/**
66
* Removes the pre-commit from command in config by default
77
*/
88
function uninstall() {
9-
console.log("[INFO] Removing git hooks from .git/hooks")
9+
console.log('[INFO] Removing git hooks from .git/hooks')
1010

1111
try {
1212
removeHooks()
13-
console.log("[INFO] Successfully removed all git hooks")
14-
} catch (e) {
15-
console.log("[INFO] Couldn't remove git hooks. Reason: " + e)
13+
console.log('[INFO] Successfully removed all git hooks')
14+
}
15+
catch (e) {
16+
console.log(`[INFO] Couldn't remove git hooks. Reason: ${e}`)
1617
}
1718
}
1819

test/bun-git-hooks.test.ts

Lines changed: 69 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { afterEach, beforeEach, describe, expect, it } from 'bun:test'
22
import { execSync } from 'node:child_process'
33
import fs from 'node:fs'
44
import path from 'node:path'
5-
import { version as packageVersion } from '../package.json'
65
import gitHooks from '../src/git-hooks'
76

87
// Util functions:
@@ -59,7 +58,6 @@ describe('bun-git-hooks', () => {
5958
const currentFilePath = path.normalize(path.join(__filename, '..'))
6059

6160
it('works from .git directory itself', () => {
62-
console.log('gitHooks.getGitProjectRoot(gitProjectRoot)', gitHooks.getGitProjectRoot(gitProjectRoot))
6361
expect(gitHooks.getGitProjectRoot(gitProjectRoot)).toBe(gitProjectRoot)
6462
})
6563

@@ -86,19 +84,19 @@ describe('bun-git-hooks', () => {
8684
const PROJECT_WITHOUT_SIMPLE_GIT_HOOKS = path.normalize(
8785
path.join(process.cwd(), '_tests', 'project_without_simple_git_hooks'),
8886
)
89-
it('returns true if simple-git-hooks really in deps', () => {
87+
it('returns true if bun-git-hooks really in deps', () => {
9088
expect(
9189
gitHooks.checkBunGitHooksInDependencies(PROJECT_WITH_SIMPLE_GIT_HOOKS_IN_DEPS),
9290
).toBe(true)
9391
})
9492

95-
it('returns true if simple-git-hooks really in devDeps', () => {
93+
it('returns true if bun-git-hooks really in devDeps', () => {
9694
expect(
9795
gitHooks.checkBunGitHooksInDependencies(PROJECT_WITH_SIMPLE_GIT_HOOKS_IN_DEV_DEPS),
9896
).toBe(true)
9997
})
10098

101-
it('returns false if simple-git-hooks isn`t in deps', () => {
99+
it('returns false if bun-git-hooks isn`t in deps', () => {
102100
expect(
103101
gitHooks.checkBunGitHooksInDependencies(PROJECT_WITHOUT_SIMPLE_GIT_HOOKS),
104102
).toBe(false)
@@ -110,7 +108,7 @@ describe('bun-git-hooks', () => {
110108
* This section of tests should test end 2 end use scenarios.
111109
* If you are adding a new feature, you should create an e2e test suite (describe) for it
112110
*/
113-
describe('e2E tests', () => {
111+
describe('E2E tests', () => {
114112
const TEST_SCRIPT = `${gitHooks.PREPEND_SCRIPT}exit 1`
115113
const COMMON_GIT_HOOKS = { 'pre-commit': TEST_SCRIPT, 'pre-push': TEST_SCRIPT }
116114

@@ -131,6 +129,14 @@ describe('bun-git-hooks', () => {
131129
path.join(testsFolder, 'project_with_configuration_in_alternative_separate_js'),
132130
)
133131

132+
// Configuration in .ts file
133+
const PROJECT_WITH_CONF_IN_SEPARATE_TS = path.normalize(
134+
path.join(testsFolder, 'project_with_configuration_in_separate_ts'),
135+
)
136+
const PROJECT_WITH_CONF_IN_SEPARATE_TS_ALT = path.normalize(
137+
path.join(testsFolder, 'project_with_configuration_in_alternative_separate_ts'),
138+
)
139+
134140
// Configuration in .cjs file
135141
const PROJECT_WITH_CONF_IN_SEPARATE_CJS = path.normalize(
136142
path.join(testsFolder, 'project_with_configuration_in_separate_cjs'),
@@ -205,7 +211,39 @@ describe('bun-git-hooks', () => {
205211

206212
describe('configuration tests', () => {
207213
describe('valid configurations', () => {
208-
it('creates git hooks if configuration is correct from .simple-git-hooks.js', () => {
214+
it('creates git hooks if configuration is correct from .git-hooks.config.ts', () => {
215+
createGitHooksFolder(PROJECT_WITH_CONF_IN_SEPARATE_TS_ALT)
216+
217+
gitHooks.setHooksFromConfig(PROJECT_WITH_CONF_IN_SEPARATE_TS_ALT)
218+
const installedHooks = getInstalledGitHooks(
219+
path.normalize(
220+
path.join(
221+
PROJECT_WITH_CONF_IN_SEPARATE_TS_ALT,
222+
'.git',
223+
'hooks',
224+
),
225+
),
226+
)
227+
expect(installedHooks).toEqual(COMMON_GIT_HOOKS)
228+
})
229+
230+
it('creates git hooks if configuration is correct from git-hooks.config.ts', () => {
231+
createGitHooksFolder(PROJECT_WITH_CONF_IN_SEPARATE_TS)
232+
233+
gitHooks.setHooksFromConfig(PROJECT_WITH_CONF_IN_SEPARATE_TS)
234+
const installedHooks = getInstalledGitHooks(
235+
path.normalize(
236+
path.join(
237+
PROJECT_WITH_CONF_IN_SEPARATE_TS,
238+
'.git',
239+
'hooks',
240+
),
241+
),
242+
)
243+
expect(installedHooks).toEqual(COMMON_GIT_HOOKS)
244+
})
245+
246+
it('creates git hooks if configuration is correct from .git-hooks.config.js', () => {
209247
createGitHooksFolder(PROJECT_WITH_CONF_IN_SEPARATE_JS_ALT)
210248

211249
gitHooks.setHooksFromConfig(PROJECT_WITH_CONF_IN_SEPARATE_JS_ALT)
@@ -221,16 +259,14 @@ describe('bun-git-hooks', () => {
221259
expect(installedHooks).toEqual(COMMON_GIT_HOOKS)
222260
})
223261

224-
it('creates git hooks if configuration is correct from .simple-git-hooks.cjs', () => {
225-
createGitHooksFolder(PROJECT_WITH_CONF_IN_SEPARATE_CJS_ALT)
262+
it('creates git hooks if configuration is correct from git-hooks.config.js', () => {
263+
createGitHooksFolder(PROJECT_WITH_CONF_IN_SEPARATE_JS)
226264

227-
gitHooks.setHooksFromConfig(
228-
PROJECT_WITH_CONF_IN_SEPARATE_CJS_ALT,
229-
)
265+
gitHooks.setHooksFromConfig(PROJECT_WITH_CONF_IN_SEPARATE_JS)
230266
const installedHooks = getInstalledGitHooks(
231267
path.normalize(
232268
path.join(
233-
PROJECT_WITH_CONF_IN_SEPARATE_CJS_ALT,
269+
PROJECT_WITH_CONF_IN_SEPARATE_JS,
234270
'.git',
235271
'hooks',
236272
),
@@ -239,31 +275,37 @@ describe('bun-git-hooks', () => {
239275
expect(installedHooks).toEqual(COMMON_GIT_HOOKS)
240276
})
241277

242-
it('creates git hooks if configuration is correct from simple-git-hooks.cjs', () => {
243-
createGitHooksFolder(PROJECT_WITH_CONF_IN_SEPARATE_CJS)
278+
it('creates git hooks if configuration is correct from .git-hooks.config.cjs', () => {
279+
createGitHooksFolder(PROJECT_WITH_CONF_IN_SEPARATE_CJS_ALT)
244280

245-
gitHooks.setHooksFromConfig(PROJECT_WITH_CONF_IN_SEPARATE_CJS)
281+
gitHooks.setHooksFromConfig(
282+
PROJECT_WITH_CONF_IN_SEPARATE_CJS_ALT,
283+
)
246284
const installedHooks = getInstalledGitHooks(
247285
path.normalize(
248-
path.join(PROJECT_WITH_CONF_IN_SEPARATE_CJS, '.git', 'hooks'),
286+
path.join(
287+
PROJECT_WITH_CONF_IN_SEPARATE_CJS_ALT,
288+
'.git',
289+
'hooks',
290+
),
249291
),
250292
)
251293
expect(installedHooks).toEqual(COMMON_GIT_HOOKS)
252294
})
253295

254-
it('creates git hooks if configuration is correct from simple-git-hooks.js', () => {
255-
createGitHooksFolder(PROJECT_WITH_CONF_IN_SEPARATE_JS)
296+
it('creates git hooks if configuration is correct from git-hooks.config.cjs', () => {
297+
createGitHooksFolder(PROJECT_WITH_CONF_IN_SEPARATE_CJS)
256298

257-
gitHooks.setHooksFromConfig(PROJECT_WITH_CONF_IN_SEPARATE_JS)
299+
gitHooks.setHooksFromConfig(PROJECT_WITH_CONF_IN_SEPARATE_CJS)
258300
const installedHooks = getInstalledGitHooks(
259301
path.normalize(
260-
path.join(PROJECT_WITH_CONF_IN_SEPARATE_JS, '.git', 'hooks'),
302+
path.join(PROJECT_WITH_CONF_IN_SEPARATE_CJS, '.git', 'hooks'),
261303
),
262304
)
263305
expect(installedHooks).toEqual(COMMON_GIT_HOOKS)
264306
})
265307

266-
it('creates git hooks if configuration is correct from .simple-git-hooks.json', () => {
308+
it('creates git hooks if configuration is correct from .git-hooks.config.json', () => {
267309
createGitHooksFolder(PROJECT_WITH_CONF_IN_SEPARATE_JSON_ALT)
268310

269311
gitHooks.setHooksFromConfig(
@@ -281,7 +323,7 @@ describe('bun-git-hooks', () => {
281323
expect(installedHooks).toEqual(COMMON_GIT_HOOKS)
282324
})
283325

284-
it('creates git hooks if configuration is correct from simple-git-hooks.json', () => {
326+
it('creates git hooks if configuration is correct from git-hooks.config.json', () => {
285327
createGitHooksFolder(PROJECT_WITH_CONF_IN_SEPARATE_JSON)
286328

287329
gitHooks.setHooksFromConfig(PROJECT_WITH_CONF_IN_SEPARATE_JSON)
@@ -321,7 +363,7 @@ describe('bun-git-hooks', () => {
321363
createGitHooksFolder(PROJECT_WO_CONF)
322364

323365
expect(() => gitHooks.setHooksFromConfig(PROJECT_WO_CONF)).toThrow(
324-
'[ERROR] Config was not found! Please add `.simple-git-hooks.js` or `simple-git-hooks.js` or `.simple-git-hooks.json` or `simple-git-hooks.json` or `simple-git-hooks` entry in package.json.',
366+
'[ERROR] Config was not found! Please add `.git-hooks.config.js` or `git-hooks.config.js` or `.git-hooks.config.json` or `git-hooks.config.json` or `bun-git-hooks` entry in package.json.',
325367
)
326368
})
327369
})
@@ -489,7 +531,7 @@ describe('bun-git-hooks', () => {
489531
})
490532
})
491533

492-
describe('eNV vars features tests', () => {
534+
describe('ENV vars features tests', () => {
493535
const GIT_USER_NAME = 'github-actions'
494536
const GIT_USER_EMAIL = 'github-actions@github.com'
495537

@@ -530,7 +572,7 @@ describe('bun-git-hooks', () => {
530572
gitHooks.setHooksFromConfig(PROJECT_WITH_CONF_IN_PACKAGE_JSON)
531573
})
532574

533-
describe('sKIP_SIMPLE_GIT_HOOKS', () => {
575+
describe('SKIP_SIMPLE_GIT_HOOKS', () => {
534576
afterEach(() => {
535577
delete process.env.SKIP_SIMPLE_GIT_HOOKS
536578
})
@@ -550,7 +592,7 @@ describe('bun-git-hooks', () => {
550592
})
551593

552594
it('fails to commit when SKIP_SIMPLE_GIT_HOOKS is set to a random string', () => {
553-
process.env.SKIP_SIMPLE_GIT_HOOKS = 'simple-git-hooks'
595+
process.env.SKIP_SIMPLE_GIT_HOOKS = 'bun-git-hooks'
554596
expectCommitToFail(PROJECT_WITH_CONF_IN_PACKAGE_JSON)
555597
})
556598
})
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
'pre-push': 'exit 1',
3+
'pre-commit': 'exit 1',
4+
}

test/fixtures/project_with_configuration_in_alternative_separate_cjs/.simple-git-hooks.cjs

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "simple-git-hooks-test-package",
2+
"name": "bun-git-hooks-test-package",
33
"version": "1.0.0",
44
"devDependencies": {
5-
"simple-git-hooks": "1.0.0"
5+
"bun-git-hooks": "0.1.0"
66
}
77
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
'pre-push': 'exit 1',
3+
'pre-commit': 'exit 1',
4+
}

test/fixtures/project_with_configuration_in_alternative_separate_js/.simple-git-hooks.js

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "simple-git-hooks-test-package",
2+
"name": "bun-git-hooks-test-package",
33
"version": "1.0.0",
44
"devDependencies": {
5-
"simple-git-hooks": "1.0.0"
5+
"bun-git-hooks": "0.1.0"
66
}
77
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "simple-git-hooks-test-package",
2+
"name": "bun-git-hooks-test-package",
33
"version": "1.0.0",
44
"devDependencies": {
5-
"simple-git-hooks": "1.0.0"
5+
"bun-git-hooks": "0.1.0"
66
}
77
}

0 commit comments

Comments
 (0)