@@ -24,13 +24,69 @@ describe('cli', () => {
2424 expect ( readStdinSpy ) . toHaveBeenCalledWith ( ) ;
2525 } ) ;
2626
27- test ( 'should readStdin when inputType is `command`' , async ( ) => {
28- const executeSpy = jest . spyOn ( utils , 'execute' ) . mockImplementationOnce ( ( ) => '' ) ;
27+ describe ( 'should execute command when inputType is `command`' , ( ) => {
28+ test ( 'should pass args to git command and add `--no-color` flag' , async ( ) => {
29+ const executeSpy = jest . spyOn ( utils , 'execute' ) . mockImplementationOnce ( ( ) => '' ) ;
2930
30- await cli . getInput ( 'command' , [ 'lol' , 'foo' ] , [ ] ) ;
31+ await cli . getInput ( 'command' , [ 'foo' ] , [ ] ) ;
3132
32- expect ( executeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
33- expect ( executeSpy ) . toHaveBeenCalledWith ( 'git diff "lol" "foo" --no-color ' ) ;
33+ expect ( executeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
34+ expect ( executeSpy ) . toHaveBeenCalledWith ( 'git' , [ 'diff' , '--no-color' , 'foo' ] ) ;
35+ } ) ;
36+
37+ test ( 'should not add `--no-color` flag if already in args' , async ( ) => {
38+ const executeSpy = jest . spyOn ( utils , 'execute' ) . mockImplementationOnce ( ( ) => '' ) ;
39+
40+ await cli . getInput ( 'command' , [ '--no-color' ] , [ ] ) ;
41+
42+ expect ( executeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
43+ expect ( executeSpy ) . toHaveBeenCalledWith ( 'git' , [ 'diff' , '--no-color' ] ) ;
44+ } ) ;
45+
46+ test ( 'should add default flags if no args are provided' , async ( ) => {
47+ const executeSpy = jest . spyOn ( utils , 'execute' ) . mockImplementationOnce ( ( ) => '' ) ;
48+
49+ await cli . getInput ( 'command' , [ ] , [ ] ) ;
50+
51+ expect ( executeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
52+ expect ( executeSpy ) . toHaveBeenCalledWith ( 'git' , [ 'diff' , '--no-color' , '-M' , '-C' , 'HEAD' ] ) ;
53+ } ) ;
54+
55+ describe ( 'when receiving paths to ignore' , ( ) => {
56+ test ( 'should add the `--` separator if it is not already in args' , async ( ) => {
57+ const executeSpy = jest . spyOn ( utils , 'execute' ) . mockImplementationOnce ( ( ) => '' ) ;
58+
59+ await cli . getInput ( 'command' , [ 'foo' ] , [ 'some/path' ] ) ;
60+
61+ expect ( executeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
62+ expect ( executeSpy ) . toHaveBeenCalledWith ( 'git' , [ 'diff' , '--no-color' , 'foo' , '--' , ':(exclude)some/path' ] ) ;
63+ } ) ;
64+
65+ test ( 'should not add `--` flag if it is already in args' , async ( ) => {
66+ const executeSpy = jest . spyOn ( utils , 'execute' ) . mockImplementationOnce ( ( ) => '' ) ;
67+
68+ await cli . getInput ( 'command' , [ 'foo' , '--' , 'other/path' ] , [ 'some/path' ] ) ;
69+
70+ expect ( executeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
71+ expect ( executeSpy ) . toHaveBeenCalledWith ( 'git' , [
72+ 'diff' ,
73+ '--no-color' ,
74+ 'foo' ,
75+ '--' ,
76+ 'other/path' ,
77+ ':(exclude)some/path' ,
78+ ] ) ;
79+ } ) ;
80+ } ) ;
81+
82+ test ( 'should not add `--` flag when there are no paths to ignore' , async ( ) => {
83+ const executeSpy = jest . spyOn ( utils , 'execute' ) . mockImplementationOnce ( ( ) => '' ) ;
84+
85+ await cli . getInput ( 'command' , [ 'bar' ] , [ ] ) ;
86+
87+ expect ( executeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
88+ expect ( executeSpy ) . toHaveBeenCalledWith ( 'git' , [ 'diff' , '--no-color' , 'bar' ] ) ;
89+ } ) ;
3490 } ) ;
3591 } ) ;
3692
0 commit comments