-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #185 from snyk/fix/correctly-index-pkg-lock-with-p…
…kgs-with-similar-candidates fix: correctly index pkg lock with pkgs with similar candidates
- Loading branch information
Showing
2 changed files
with
88 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
test/jest/dep-graph-builders/npm-lock-v2/get-child-key.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { getChildNodeKey } from '../../../../lib/dep-graph-builders/npm-lock-v2/index'; | ||
|
||
describe('npm-lock-v2 getChildNodeKey', () => { | ||
it('should filter out candidate keys that have pkgs that are not in ancestry being tested', async () => { | ||
const name = 'global-modules'; | ||
const ancestry = [ | ||
{ name: 'test-root', key: '', inBundle: false }, | ||
{ | ||
name: '@storybook/test-runner', | ||
key: 'node_modules/@storybook/test-runner', | ||
inBundle: false, | ||
}, | ||
{ | ||
name: 'jest-playwright-preset', | ||
key: 'node_modules/@storybook/test-runner/node_modules/jest-playwright-preset', | ||
inBundle: false, | ||
}, | ||
{ | ||
name: 'jest-process-manager', | ||
key: 'node_modules/jest-process-manager', | ||
inBundle: false, | ||
}, | ||
{ name: 'cwd', key: 'node_modules/cwd', inBundle: false }, | ||
{ name: 'find-pkg', key: 'node_modules/find-pkg', inBundle: false }, | ||
{ | ||
name: 'find-file-up', | ||
key: 'node_modules/find-file-up', | ||
inBundle: false, | ||
}, | ||
{ | ||
name: 'resolve-dir', | ||
key: 'node_modules/find-file-up/node_modules/resolve-dir', | ||
inBundle: false, | ||
}, | ||
]; | ||
const pkgs = { | ||
'node_modules/stylelint/node_modules/global-modules': 'exists' as any, | ||
'node_modules/find-file-up/node_modules/global-modules': 'exists' as any, | ||
}; | ||
const pkgKeysByName = new Map([ | ||
[ | ||
'global-modules', | ||
[ | ||
'node_modules/find-file-up/node_modules/global-modules', | ||
'node_modules/stylelint/node_modules/global-modules', | ||
], | ||
], | ||
]); | ||
|
||
const childKey = getChildNodeKey(name, ancestry, pkgs, pkgKeysByName); | ||
expect(childKey).toBe( | ||
'node_modules/find-file-up/node_modules/global-modules', | ||
); | ||
}); | ||
}); |