@@ -29,9 +29,21 @@ Deno.test({
2929 } ,
3030} ) ;
3131
32- async function expectCommonGitInit ( cwd : string = Deno . cwd ( ) ) {
33- const { success : gitInitSuccess } = await git ( cwd , 'init' ) . output ( ) ;
34- expect ( gitInitSuccess ) . toBe ( true ) ;
32+ async function expectCommonGitInit ( cwd : string = Deno . cwd ( ) , config = false ) {
33+ let { success } = await git ( cwd , 'init' ) . output ( ) ;
34+ expect ( success ) . toBe ( true ) ;
35+
36+ if ( config ) {
37+ // configure git user
38+ ( { success } = await git ( cwd , 'config' , 'user.email' , 'tester@example.com' ) . output ( ) ) ;
39+ expect ( success ) . toBe ( true ) ;
40+ ( { success } = await git ( cwd , 'config' , 'user.name' , 'Deno Tester' ) . output ( ) ) ;
41+ expect ( success ) . toBe ( true ) ;
42+
43+ // skip gpg sign
44+ ( { success } = await git ( cwd , 'config' , 'commit.gpgsign' , 'false' ) . output ( ) ) ;
45+ expect ( success ) . toBe ( true ) ;
46+ }
3547}
3648
3749const PRE_COMMIT_PATH = path . join ( GITHOOKS_DIRNAME , 'pre-commit' ) ;
@@ -192,28 +204,24 @@ Deno.test({
192204 await using sbox = await sandbox ( ) ;
193205
194206 try {
195- await expectCommonGitInit ( ) ;
196- await init ( ) ;
207+ await expectCommonGitInit ( Deno . cwd ( ) , true ) ;
208+ await expectCommonInit ( Deno . cwd ( ) ) ;
197209
198210 await Deno . writeTextFile ( 'main.ts' , 'console.log("hello")' ) ;
199211
200212 // add
201- let { success } = await git ( Deno . cwd ( ) , 'add' , 'main.ts' ) . output ( ) ;
202- expect ( success ) . toBe ( true ) ;
203-
204- // skip gpg sign
205- ( { success } = await git ( Deno . cwd ( ) , 'config' , 'commit.gpgsign' , 'false' ) . output ( ) ) ;
213+ const { success } = await git ( Deno . cwd ( ) , 'add' , 'main.ts' ) . output ( ) ;
206214 expect ( success ) . toBe ( true ) ;
207215
208216 // commit
209217 const { success : commitSuccess , stderr } = await git (
210218 Deno . cwd ( ) ,
211219 'commit' ,
212220 '-m' ,
213- 'initial commit' ,
221+ 'test pre- commit hook ' ,
214222 ) . output ( ) ;
215- expect ( commitSuccess ) . toBe ( true ) ;
216223 expect ( new TextDecoder ( ) . decode ( stderr ) ) . toContain ( 'Checked 1 file' ) ;
224+ expect ( commitSuccess ) . toBe ( true ) ;
217225 } finally {
218226 await sbox [ Symbol . asyncDispose ] ( ) ;
219227 }
0 commit comments