@@ -5,7 +5,13 @@ import { PhysicalModuleToPatch, PackageAndVersion } from '../../src/lib/types';
5
5
import { extractPatchMetadata } from '../../src/lib/snyk-file' ;
6
6
import { checkProject } from '../../src/lib/explore-node-modules' ;
7
7
import { getPatches } from '../../src/lib/get-patches' ;
8
- import { extractTargetFilePathFromPatch , patchString } from '../../src/lib/patch' ;
8
+ import {
9
+ extractTargetFilePathFromPatch ,
10
+ patchString ,
11
+ } from '../../src/lib/patch' ;
12
+
13
+ // TODO: lower it once Protect stops hitting real Snyk API endpoints
14
+ const testTimeout = 30000 ;
9
15
10
16
describe ( 'parsing .snyk file content' , ( ) => {
11
17
it ( 'works with a single patch' , ( ) => {
44
50
SNYK-JS-LODASH-567746:
45
51
- tap > nyc > istanbul-lib-instrument > babel-types > lodash:
46
52
patched: '2021-02-17T13:43:51.857Z'
47
-
53
+
48
54
SNYK-FAKE-THEMODULE-000000:
49
55
- top-level > some-other > the-module:
50
56
patched: '2021-02-17T13:43:51.857Z'
@@ -173,35 +179,43 @@ describe('checkProject', () => {
173
179
// These tests makes a real API calls to Snyk
174
180
// TODO: would be better to mock the response
175
181
describe ( 'getPatches' , ( ) => {
176
- it ( 'seems to work' , async ( ) => {
177
- const packageAndVersions : PackageAndVersion [ ] = [
178
- {
179
- name : 'lodash' ,
180
- version : '4.17.15' ,
181
- } as PackageAndVersion ,
182
- ] ;
183
- const vulnIds = [ 'SNYK-JS-LODASH-567746' ] ;
184
- const patches = await getPatches ( packageAndVersions , vulnIds ) ;
185
- expect ( Object . keys ( patches ) ) . toEqual ( [ 'lodash' ] ) ;
186
- const lodashPatches = patches [ 'lodash' ] ;
187
- expect ( lodashPatches ) . toHaveLength ( 1 ) ;
188
- const theOnePatch = lodashPatches [ 0 ] ;
189
- expect ( theOnePatch . id ) . toBe ( 'patch:SNYK-JS-LODASH-567746:0' ) ;
190
- expect ( theOnePatch . diffs ) . toHaveLength ( 1 ) ;
191
- expect ( theOnePatch . diffs [ 0 ] ) . toContain ( 'index 9b95dfef..43e71ffb 100644' ) ; // something from the actual patch
192
- } ) ;
182
+ it (
183
+ 'seems to work' ,
184
+ async ( ) => {
185
+ const packageAndVersions : PackageAndVersion [ ] = [
186
+ {
187
+ name : 'lodash' ,
188
+ version : '4.17.15' ,
189
+ } as PackageAndVersion ,
190
+ ] ;
191
+ const vulnIds = [ 'SNYK-JS-LODASH-567746' ] ;
192
+ const patches = await getPatches ( packageAndVersions , vulnIds ) ;
193
+ expect ( Object . keys ( patches ) ) . toEqual ( [ 'lodash' ] ) ;
194
+ const lodashPatches = patches [ 'lodash' ] ;
195
+ expect ( lodashPatches ) . toHaveLength ( 1 ) ;
196
+ const theOnePatch = lodashPatches [ 0 ] ;
197
+ expect ( theOnePatch . id ) . toBe ( 'patch:SNYK-JS-LODASH-567746:0' ) ;
198
+ expect ( theOnePatch . diffs ) . toHaveLength ( 1 ) ;
199
+ expect ( theOnePatch . diffs [ 0 ] ) . toContain ( 'index 9b95dfef..43e71ffb 100644' ) ; // something from the actual patch
200
+ } ,
201
+ testTimeout ,
202
+ ) ;
193
203
194
- it ( 'does not download patch for non-applicable version' , async ( ) => {
195
- const packageAndVersions : PackageAndVersion [ ] = [
196
- {
197
- name : 'lodash' ,
198
- version : '4.17.20' , // this version is not applicable to the patch
199
- } as PackageAndVersion ,
200
- ] ;
201
- const vulnIds = [ 'SNYK-JS-LODASH-567746' ] ;
202
- const patches = await getPatches ( packageAndVersions , vulnIds ) ;
203
- expect ( patches ) . toEqual ( { } ) ; // expect nothing to be returned because SNYK-JS-LODASH-567746 does not apply to 4.17.20 of lodash
204
- } ) ;
204
+ it (
205
+ 'does not download patch for non-applicable version' ,
206
+ async ( ) => {
207
+ const packageAndVersions : PackageAndVersion [ ] = [
208
+ {
209
+ name : 'lodash' ,
210
+ version : '4.17.20' , // this version is not applicable to the patch
211
+ } as PackageAndVersion ,
212
+ ] ;
213
+ const vulnIds = [ 'SNYK-JS-LODASH-567746' ] ;
214
+ const patches = await getPatches ( packageAndVersions , vulnIds ) ;
215
+ expect ( patches ) . toEqual ( { } ) ; // expect nothing to be returned because SNYK-JS-LODASH-567746 does not apply to 4.17.20 of lodash
216
+ } ,
217
+ testTimeout ,
218
+ ) ;
205
219
} ) ;
206
220
207
221
describe ( 'applying patches' , ( ) => {
0 commit comments