Skip to content

Commit eec11b7

Browse files
committedMar 30, 2021
test: raise timeout for snyk protect tests hitting real Snyk API
1 parent 8045ceb commit eec11b7

File tree

1 file changed

+44
-30
lines changed

1 file changed

+44
-30
lines changed
 

‎packages/snyk-protect/test/unit/protect-unit-tests.spec.ts

+44-30
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import { PhysicalModuleToPatch, PackageAndVersion } from '../../src/lib/types';
55
import { extractPatchMetadata } from '../../src/lib/snyk-file';
66
import { checkProject } from '../../src/lib/explore-node-modules';
77
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;
915

1016
describe('parsing .snyk file content', () => {
1117
it('works with a single patch', () => {
@@ -44,7 +50,7 @@ patch:
4450
SNYK-JS-LODASH-567746:
4551
- tap > nyc > istanbul-lib-instrument > babel-types > lodash:
4652
patched: '2021-02-17T13:43:51.857Z'
47-
53+
4854
SNYK-FAKE-THEMODULE-000000:
4955
- top-level > some-other > the-module:
5056
patched: '2021-02-17T13:43:51.857Z'
@@ -173,35 +179,43 @@ describe('checkProject', () => {
173179
// These tests makes a real API calls to Snyk
174180
// TODO: would be better to mock the response
175181
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+
);
193203

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+
);
205219
});
206220

207221
describe('applying patches', () => {

0 commit comments

Comments
 (0)
Please sign in to comment.