@@ -48,7 +48,7 @@ describe("getRangesForDiff", () => {
48
48
49
49
describe ( "getDiffForFile" , ( ) => {
50
50
it ( "should get the staged diff of a file" , ( ) => {
51
- mockedChildProcess . execSync . mockReturnValue ( Buffer . from ( hunks ) ) ;
51
+ mockedChildProcess . execSync . mockReturnValueOnce ( Buffer . from ( hunks ) ) ;
52
52
process . env . ESLINT_PLUGIN_DIFF_COMMIT = "1234567" ;
53
53
54
54
const diffFromFile = getDiffForFile ( "./mockfile.js" , true ) ;
@@ -70,6 +70,7 @@ describe("getDiffForFile", () => {
70
70
jest . mock ( "child_process" ) . resetAllMocks ( ) ;
71
71
mockedChildProcess . execSync . mockReturnValueOnce ( Buffer . from ( hunks ) ) ;
72
72
73
+ expect ( mockedChildProcess . execSync ) . toHaveBeenCalledTimes ( 0 ) ;
73
74
const diffFromFileA = getDiffForFile ( "./mockfileCache.js" ) ;
74
75
const diffFromFileB = getDiffForFile ( "./mockfileCache.js" ) ;
75
76
expect ( mockedChildProcess . execSync ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -84,14 +85,16 @@ describe("getDiffForFile", () => {
84
85
describe ( "getDiffFileList" , ( ) => {
85
86
it ( "should get the list of staged files" , ( ) => {
86
87
jest . mock ( "child_process" ) . resetAllMocks ( ) ;
87
- mockedChildProcess . execSync . mockReturnValue ( Buffer . from ( diffFileList ) ) ;
88
+ mockedChildProcess . execSync . mockReturnValueOnce ( Buffer . from ( diffFileList ) ) ;
88
89
const staged = false ;
89
- const fileList = getDiffFileList ( staged ) ;
90
+ const fileListA = getDiffFileList ( staged ) ;
91
+ const fileListB = getDiffFileList ( staged ) ;
90
92
91
93
expect ( mockedChildProcess . execSync ) . toHaveBeenCalled ( ) ;
92
- expect ( fileList ) . toEqual (
94
+ expect ( fileListA ) . toEqual (
93
95
[ "file1" , "file2" , "file3" ] . map ( ( p ) => path . resolve ( p ) )
94
96
) ;
97
+ expect ( fileListA ) . toEqual ( fileListB ) ;
95
98
} ) ;
96
99
} ) ;
97
100
0 commit comments