Skip to content

Commit

Permalink
test: raise timeout for snyk protect tests hitting real Snyk API
Browse files Browse the repository at this point in the history
  • Loading branch information
JackuB committed Mar 30, 2021
1 parent 8045ceb commit eec11b7
Showing 1 changed file with 44 additions and 30 deletions.
74 changes: 44 additions & 30 deletions packages/snyk-protect/test/unit/protect-unit-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import { PhysicalModuleToPatch, PackageAndVersion } from '../../src/lib/types';
import { extractPatchMetadata } from '../../src/lib/snyk-file';
import { checkProject } from '../../src/lib/explore-node-modules';
import { getPatches } from '../../src/lib/get-patches';
import { extractTargetFilePathFromPatch, patchString } from '../../src/lib/patch';
import {
extractTargetFilePathFromPatch,
patchString,
} from '../../src/lib/patch';

// TODO: lower it once Protect stops hitting real Snyk API endpoints
const testTimeout = 30000;

describe('parsing .snyk file content', () => {
it('works with a single patch', () => {
Expand Down Expand Up @@ -44,7 +50,7 @@ patch:
SNYK-JS-LODASH-567746:
- tap > nyc > istanbul-lib-instrument > babel-types > lodash:
patched: '2021-02-17T13:43:51.857Z'
SNYK-FAKE-THEMODULE-000000:
- top-level > some-other > the-module:
patched: '2021-02-17T13:43:51.857Z'
Expand Down Expand Up @@ -173,35 +179,43 @@ describe('checkProject', () => {
// These tests makes a real API calls to Snyk
// TODO: would be better to mock the response
describe('getPatches', () => {
it('seems to work', async () => {
const packageAndVersions: PackageAndVersion[] = [
{
name: 'lodash',
version: '4.17.15',
} as PackageAndVersion,
];
const vulnIds = ['SNYK-JS-LODASH-567746'];
const patches = await getPatches(packageAndVersions, vulnIds);
expect(Object.keys(patches)).toEqual(['lodash']);
const lodashPatches = patches['lodash'];
expect(lodashPatches).toHaveLength(1);
const theOnePatch = lodashPatches[0];
expect(theOnePatch.id).toBe('patch:SNYK-JS-LODASH-567746:0');
expect(theOnePatch.diffs).toHaveLength(1);
expect(theOnePatch.diffs[0]).toContain('index 9b95dfef..43e71ffb 100644'); // something from the actual patch
});
it(
'seems to work',
async () => {
const packageAndVersions: PackageAndVersion[] = [
{
name: 'lodash',
version: '4.17.15',
} as PackageAndVersion,
];
const vulnIds = ['SNYK-JS-LODASH-567746'];
const patches = await getPatches(packageAndVersions, vulnIds);
expect(Object.keys(patches)).toEqual(['lodash']);
const lodashPatches = patches['lodash'];
expect(lodashPatches).toHaveLength(1);
const theOnePatch = lodashPatches[0];
expect(theOnePatch.id).toBe('patch:SNYK-JS-LODASH-567746:0');
expect(theOnePatch.diffs).toHaveLength(1);
expect(theOnePatch.diffs[0]).toContain('index 9b95dfef..43e71ffb 100644'); // something from the actual patch
},
testTimeout,
);

it('does not download patch for non-applicable version', async () => {
const packageAndVersions: PackageAndVersion[] = [
{
name: 'lodash',
version: '4.17.20', // this version is not applicable to the patch
} as PackageAndVersion,
];
const vulnIds = ['SNYK-JS-LODASH-567746'];
const patches = await getPatches(packageAndVersions, vulnIds);
expect(patches).toEqual({}); // expect nothing to be returned because SNYK-JS-LODASH-567746 does not apply to 4.17.20 of lodash
});
it(
'does not download patch for non-applicable version',
async () => {
const packageAndVersions: PackageAndVersion[] = [
{
name: 'lodash',
version: '4.17.20', // this version is not applicable to the patch
} as PackageAndVersion,
];
const vulnIds = ['SNYK-JS-LODASH-567746'];
const patches = await getPatches(packageAndVersions, vulnIds);
expect(patches).toEqual({}); // expect nothing to be returned because SNYK-JS-LODASH-567746 does not apply to 4.17.20 of lodash
},
testTimeout,
);
});

describe('applying patches', () => {
Expand Down

0 comments on commit eec11b7

Please sign in to comment.