@@ -2,7 +2,6 @@ import { afterEach, beforeEach, describe, expect, it } from 'bun:test'
22import { execSync } from 'node:child_process'
33import fs from 'node:fs'
44import path from 'node:path'
5- import { version as packageVersion } from '../package.json'
65import 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 } )
0 commit comments