diff --git a/packages/snyk-protect/test/unit/protect-unit-tests.spec.ts b/packages/snyk-protect/test/unit/protect-unit-tests.spec.ts index 6902998c65..e7bf6a84a8 100644 --- a/packages/snyk-protect/test/unit/protect-unit-tests.spec.ts +++ b/packages/snyk-protect/test/unit/protect-unit-tests.spec.ts @@ -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', () => { @@ -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' @@ -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', () => {