@@ -21,12 +21,12 @@ vi.mock('openai', () => {
21
21
}
22
22
} )
23
23
24
- // index.jsモジュール全体をモック
24
+ // Mock the entire index.js module
25
25
vi . mock ( '../index.js' , ( ) => {
26
26
return {
27
27
getGitSummary : vi . fn ( ( options ) => {
28
28
try {
29
- // 実際のdiffコマンドを実行せず、ファイルの変更があるかチェック
29
+ // Check if there are file changes without actually executing the diff command
30
30
const gitStatus = require ( 'child_process' )
31
31
. execSync ( 'git status --porcelain' )
32
32
. toString ( )
@@ -35,8 +35,8 @@ vi.mock('../index.js', () => {
35
35
throw new Error ( 'No changes to commit' )
36
36
}
37
37
38
- // モックされたdiffの内容を返す
39
- return `diff --git a/file1.js b/file1.js\nindex 123456..789012 100644\n--- a/file1.js\n+++ b/file1.js\n@@ -1,5 +1,8 @@\nfunction greet(name) {\n- return \`Hello, \${name}!\`;\n+ // 名前が空の場合のデフォルト値を追加 \n+ const userName = name || 'Guest';\n+ return \`Hello, \${userName}!\`;\n }`
38
+ // Return mocked diff content
39
+ return `diff --git a/file1.js b/file1.js\nindex 123456..789012 100644\n--- a/file1.js\n+++ b/file1.js\n@@ -1,5 +1,8 @@\nfunction greet(name) {\n- return \`Hello, \${name}!\`;\n+ // Add default value when name is empty \n+ const userName = name || 'Guest';\n+ return \`Hello, \${userName}!\`;\n }`
40
40
} catch ( error ) {
41
41
throw new Error ( 'Failed to get git summary' )
42
42
}
@@ -45,40 +45,40 @@ vi.mock('../index.js', () => {
45
45
return 'Mock commit message'
46
46
} ) ,
47
47
gitExtension : vi . fn ( ) ,
48
- // その他必要な関数やオブジェクト
48
+ // Other necessary functions or objects
49
49
}
50
50
} )
51
51
52
- // fs モジュールをモック
52
+ // Mock fs module
53
53
vi . mock ( 'fs' , async ( ) => {
54
54
const actual = await vi . importActual ( 'fs' )
55
55
56
56
return {
57
57
...actual ,
58
58
existsSync : vi . fn ( ( path ) => {
59
- // 特定のパスのみモックレスポンスを返す
59
+ // Return mock response only for specific paths
60
60
if ( path . includes ( '.git-gpt-commit-config.json' ) ) {
61
61
return true
62
62
}
63
- // それ以外は実際の実装を使用
63
+ // Use actual implementation for others
64
64
return actual . existsSync ( path )
65
65
} ) ,
66
66
readFileSync : vi . fn ( ( path , options ) => {
67
- // コンフィグファイルの場合、モックデータを返す
67
+ // Return mock data for config file
68
68
if ( path . includes ( '.git-gpt-commit-config.json' ) ) {
69
69
return JSON . stringify ( {
70
70
model : 'gpt-4o' ,
71
71
language : 'English' ,
72
72
} )
73
73
}
74
- // それ以外は実際の実装を使用
74
+ // Use actual implementation for others
75
75
return actual . readFileSync ( path , options )
76
76
} ) ,
77
77
writeFileSync : vi . fn ( ) ,
78
78
}
79
79
} )
80
80
81
- // commanderをモック
81
+ // Mock commander
82
82
vi . mock ( 'commander' , ( ) => {
83
83
const mockProgram = {
84
84
command : vi . fn ( ) . mockReturnThis ( ) ,
@@ -95,32 +95,32 @@ vi.mock('commander', () => {
95
95
}
96
96
} )
97
97
98
- // child_processをモック
98
+ // Mock child_process
99
99
vi . mock ( 'child_process' , async ( ) => {
100
100
const actual = await vi . importActual ( 'child_process' )
101
101
102
102
return {
103
103
...actual ,
104
104
execSync : vi . fn ( ( command ) => {
105
105
if ( typeof command === 'string' ) {
106
- // git statusコマンドの場合は変更があるとみなす
106
+ // Treat as having changes for git status commands
107
107
if ( command . includes ( 'git status' ) ) {
108
108
return Buffer . from ( 'M file1.js' )
109
109
}
110
110
111
- // git commitコマンドの場合はモック応答
111
+ // Mock response for git commit commands
112
112
if ( command . includes ( 'git commit' ) ) {
113
113
return Buffer . from ( 'Commit successful' )
114
114
}
115
115
}
116
116
117
- // その他のコマンドは実際に実行
117
+ // Actually execute other commands
118
118
return actual . execSync ( command )
119
119
} ) ,
120
120
exec : vi . fn ( ( command , callback ) => {
121
121
if ( command . includes ( 'git diff' ) ) {
122
122
const stdout =
123
- "diff --git a/file1.js b/file1.js\nindex 123456..789012 100644\n--- a/file1.js\n+++ b/file1.js\n@@ -1,5 +1,8 @@\nfunction greet(name) {\n- return `Hello, ${name}!`;\n+ // 名前が空の場合のデフォルト値を追加 \n+ const userName = name || 'Guest';\n+ return `Hello, ${userName}!`;\n }"
123
+ "diff --git a/file1.js b/file1.js\nindex 123456..789012 100644\n--- a/file1.js\n+++ b/file1.js\n@@ -1,5 +1,8 @@\nfunction greet(name) {\n- return \ `Hello, \ ${name}!\ `;\n+ // Add default value when name is empty \n+ const userName = name || 'Guest';\n+ return \ `Hello, \ ${userName}!\ `;\n }"
124
124
callback ( null , { stdout } )
125
125
} else {
126
126
callback ( null , { stdout : '' } )
@@ -129,12 +129,12 @@ vi.mock('child_process', async () => {
129
129
}
130
130
} )
131
131
132
- // promptsモジュールをモック
132
+ // Mock prompts module
133
133
vi . mock ( 'prompts' , ( ) => ( {
134
134
default : vi . fn ( ) . mockResolvedValue ( { value : true } ) ,
135
135
} ) )
136
136
137
- // process.exitをモック
137
+ // Mock process.exit
138
138
vi . stubGlobal ( 'process' , {
139
139
...process ,
140
140
exit : vi . fn ( ( code ) => {
0 commit comments