1
+ import { expect } from "chai" ;
2
+ import { stringToRegExp } from "../utils/string" ;
3
+ import { defaultConfigData } from "./default" ;
4
+
5
+ describe ( "Config: generateCommitMessage.responseMatcher" , ( ) => {
6
+ // Test parameters
7
+ const responseMatcher = defaultConfigData . chat . generateCommitMessage . responseMatcher ;
8
+ const regExp = stringToRegExp ( responseMatcher ) ;
9
+
10
+ // Helper function for reusing test logic
11
+ function testResponseMatch ( testCase : string , input : string , expectedMatch : string ) {
12
+ it ( testCase , ( ) => {
13
+ const match = regExp . exec ( input ) ;
14
+ expect ( match ) . to . not . be . null ;
15
+ if ( match ) {
16
+ expect ( match [ 1 ] ) . to . equal ( expectedMatch ) ;
17
+ }
18
+ } ) ;
19
+ }
20
+
21
+ // Core functionality: Extract commit message from simple response
22
+ testResponseMatch (
23
+ "test for extracting conventional commit message from simple response" ,
24
+ "Based on the diff, I would suggest the following commit message:\n\nfeat(core): add new feature\n" ,
25
+ "feat(core): add new feature"
26
+ ) ;
27
+
28
+ // Core functionality: Handle commit messages in code blocks
29
+ testResponseMatch (
30
+ "test for handling responses with code blocks" ,
31
+ `Based on the diff, here's an appropriate commit message:
32
+
33
+ \`\`\`
34
+ fix(auth): resolve user authentication timeout issue
35
+ \`\`\`
36
+
37
+ This commit message follows the conventional format with a 'fix' type and 'auth' scope.` ,
38
+ "fix(auth): resolve user authentication timeout issue"
39
+ ) ;
40
+
41
+ // Bug fix: Handle commit messages with double quotes
42
+ testResponseMatch (
43
+ "test for handling responses with double quotes" ,
44
+ `Based on the provided diff, I recommend using the following commit message:
45
+
46
+ "docs(readme): update installation instructions"
47
+
48
+ This commit message follows the conventional format and accurately describes the changes made to the documentation.` ,
49
+ "docs(readme): update installation instructions"
50
+ ) ;
51
+
52
+ // Bug fix: Handle commit messages with single quotes and backticks
53
+ testResponseMatch (
54
+ "test for handling responses with single quotes and backticks" ,
55
+ `Here are some commit message options:
56
+ 'chore(build): update dependencies'
57
+ \`test(components): add unit tests for login form\`` ,
58
+ "chore(build): update dependencies"
59
+ ) ;
60
+
61
+ // Bug fix: Handle responses with markdown images
62
+ testResponseMatch (
63
+ "test for handling responses with markdown images" ,
64
+ `Here's a diagram showing the changes you made:
65
+ 
66
+
67
+ Based on the diff, I suggest the following commit message:
68
+
69
+ feat(ui): improve button design and layout
70
+
71
+ [Diagram]: https://example.com/diagram-ref.png` ,
72
+ "feat(ui): improve button design and layout"
73
+ ) ;
74
+ } ) ;
0 commit comments