1- import { describe , it , expect , mock , afterEach , beforeEach , spyOn } from 'bun:test' ;
1+ import { describe , expect , it , mock } from 'bun:test' ;
22
33// Define the mock functions so we can manipulate them in tests
44const spawnSyncMock = mock ( ( ) => ( {
55 status : 0 ,
6- stdout : Buffer . from ( 'mock-hash-123\n' )
6+ stdout : Buffer . from ( 'mock-hash-123\n' ) ,
77} ) ) ;
88
99mock . module ( 'child_process' , ( ) => ( {
10- spawnSync : spawnSyncMock
10+ spawnSync : spawnSyncMock ,
1111} ) ) ;
1212
13- const listRemotesMock = mock ( async ( ) => [ { remote : 'origin' , url : 'https://github.com/test/repo.git' } ] ) ;
14- const logMock = mock ( async ( ) => [ {
15- oid : 'mock-commit-hash' ,
16- commit : {
17- message : 'mock commit message' ,
18- author : { name : 'Test Author' } ,
19- committer : { name : 'Test Committer' , timestamp : 1625097600 }
20- }
21- } ] ) ;
13+ const listRemotesMock = mock ( async ( ) => [
14+ { remote : 'origin' , url : 'https://github.com/test/repo.git' } ,
15+ ] ) ;
16+ const logMock = mock ( async ( ) => [
17+ {
18+ oid : 'mock-commit-hash' ,
19+ commit : {
20+ message : 'mock commit message' ,
21+ author : { name : 'Test Author' } ,
22+ committer : { name : 'Test Committer' , timestamp : 1625097600 } ,
23+ } ,
24+ } ,
25+ ] ) ;
2226
2327mock . module ( 'isomorphic-git' , ( ) => ( {
2428 default : {
2529 listRemotes : listRemotesMock ,
26- log : logMock
27- }
30+ log : logMock ,
31+ } ,
2832} ) ) ;
2933
30- import { getCurrentCommit , getCommitInfo } from '../src/utils/git' ;
31-
32- describe ( 'git utils' , ( ) => {
33- afterEach ( ( ) => {
34- spawnSyncMock . mockClear ( ) ;
35- listRemotesMock . mockClear ( ) ;
36- logMock . mockClear ( ) ;
37- } ) ;
34+ describe ( 'git utils' , async ( ) => {
35+ const { getCommitInfo, getCurrentCommit } = await import ( '../src/utils/git' ) ;
3836
3937 describe ( 'getCurrentCommit' , ( ) => {
4038 it ( 'should return the commit hash when git command succeeds' , ( ) => {
4139 spawnSyncMock . mockImplementationOnce ( ( ) => ( {
4240 status : 0 ,
43- stdout : Buffer . from ( 'abcdef1234567890\n' )
41+ stdout : Buffer . from ( 'abcdef1234567890\n' ) ,
4442 } ) ) ;
4543
4644 const commit = getCurrentCommit ( ) ;
@@ -52,7 +50,9 @@ describe('git utils', () => {
5250 spawnSyncMock . mockImplementationOnce ( ( ) => ( {
5351 status : 128 ,
5452 stdout : Buffer . from ( '' ) ,
55- stderr : Buffer . from ( 'fatal: not a git repository (or any of the parent directories): .git\n' )
53+ stderr : Buffer . from (
54+ 'fatal: not a git repository (or any of the parent directories): .git\n' ,
55+ ) ,
5656 } ) ) ;
5757
5858 expect ( ( ) => getCurrentCommit ( ) ) . toThrow ( 'Not a git repository' ) ;
@@ -76,14 +76,16 @@ describe('git utils', () => {
7676 } ) ;
7777
7878 it ( 'should handle missing author name by falling back to committer name' , async ( ) => {
79- logMock . mockImplementationOnce ( async ( ) => [ {
80- oid : 'mock-commit-hash-2' ,
81- commit : {
82- message : 'another message' ,
83- author : { name : '' } ,
84- committer : { name : 'Fallback Committer' , timestamp : 1625098000 }
85- }
86- } ] ) ;
79+ logMock . mockImplementationOnce ( async ( ) => [
80+ {
81+ oid : 'mock-commit-hash-2' ,
82+ commit : {
83+ message : 'another message' ,
84+ author : { name : '' } ,
85+ committer : { name : 'Fallback Committer' , timestamp : 1625098000 } ,
86+ } ,
87+ } ,
88+ ] ) ;
8789
8890 const info = await getCommitInfo ( ) ;
8991 expect ( info ?. author ) . toBe ( 'Fallback Committer' ) ;
0 commit comments