@@ -50,6 +50,19 @@ const pipWithRemediation = JSON.parse(
50
50
) ,
51
51
) ;
52
52
53
+ const pipNoIssues = JSON . parse (
54
+ fs . readFileSync (
55
+ pathLib . resolve (
56
+ __dirname ,
57
+ '../../../../../' ,
58
+ 'fixtures' ,
59
+ 'snyk-fix' ,
60
+ 'test-result-pip-no-vulns.json' ,
61
+ ) ,
62
+ 'utf8' ,
63
+ ) ,
64
+ ) ;
65
+
53
66
describe ( 'snyk fix (functional tests)' , ( ) => {
54
67
let origStdWrite ;
55
68
let snykFixSpy : jest . SpyInstance ;
@@ -167,7 +180,7 @@ describe('snyk fix (functional tests)', () => {
167
180
) ;
168
181
169
182
it (
170
- 'snyk fix continues to fix when 1 path fails to test with `snyk fix path1 path2`' ,
183
+ 'snyk fix continues to fix when 1 path fails to test with `snyk fix path1 path2` (exit code 0) ' ,
171
184
async ( ) => {
172
185
// read data from console.log
173
186
let stdoutMessages = '' ;
@@ -205,7 +218,7 @@ describe('snyk fix (functional tests)', () => {
205
218
) ;
206
219
207
220
it (
208
- 'snyk fails to fix when all path fails to test with `snyk fix path1 path2`' ,
221
+ 'snyk fails to fix when all path fails to test with `snyk fix path1 path2` (non 0 error code) ' ,
209
222
async ( ) => {
210
223
// read data from console.log
211
224
let stdoutMessages = '' ;
@@ -241,4 +254,38 @@ describe('snyk fix (functional tests)', () => {
241
254
} ,
242
255
testTimeout ,
243
256
) ;
257
+
258
+ it (
259
+ 'snyk succeeds to fix when no vulns `snyk fix path1` (exit code 0)' ,
260
+ async ( ) => {
261
+ // read data from console.log
262
+ let stdoutMessages = '' ;
263
+ let stderrMessages = '' ;
264
+ jest
265
+ . spyOn ( console , 'log' )
266
+ . mockImplementation ( ( msg : string ) => ( stdoutMessages += msg ) ) ;
267
+ jest
268
+ . spyOn ( console , 'error' )
269
+ . mockImplementation ( ( msg : string ) => ( stderrMessages += msg ) ) ;
270
+
271
+ jest . spyOn ( snyk , 'test' ) . mockResolvedValue ( {
272
+ ...pipNoIssues ,
273
+ // pip plugin does not return targetFile, instead fix will fallback to displayTargetFile
274
+ displayTargetFile : pipRequirementsTxt ,
275
+ } ) ;
276
+ const res = await cli . fix ( pipAppWorkspace , {
277
+ dryRun : true , // prevents write to disc
278
+ quiet : true ,
279
+ } ) ;
280
+ expect ( snykFixSpy ) . toHaveBeenCalledTimes ( 1 ) ;
281
+ expect ( snykFixSpy . mock . calls [ 0 ] [ 1 ] ) . toEqual ( {
282
+ dryRun : true ,
283
+ quiet : true ,
284
+ } ) ;
285
+ expect ( stripAnsi ( res ) ) . toMatch ( 'No successful fixes' ) ;
286
+ expect ( stdoutMessages ) . toEqual ( '' ) ;
287
+ expect ( stderrMessages ) . toEqual ( '' ) ;
288
+ } ,
289
+ testTimeout ,
290
+ ) ;
244
291
} ) ;
0 commit comments