-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
148 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
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,144 @@ | ||
import { IImpactGraph } from 'jfrog-ide-webview'; | ||
import { YarnImpactGraphUtil, YarnWhyItem } from '../../main/treeDataProviders/utils/yarnImpactGraph'; | ||
import { assert } from 'chai'; | ||
import { RootNode } from '../../main/treeDataProviders/dependenciesTree/dependenciesRoot/rootTree'; | ||
|
||
describe('Yarn impact graph util', async () => { | ||
it('Build single impact graph', async () => { | ||
const results: IImpactGraph = new YarnImpactGraphUtilMock('minimist', '0.0.8', 'Mock-Project', '').create(); | ||
assert.deepEqual(results, generateExpectedSingleImpactGraph()); | ||
}); | ||
|
||
it.only('Build multiple impact graphs', async () => { | ||
const results: IImpactGraph = new YarnImpactGraphUtilMock('minimist', '1.2.0', 'Mock-Project', '').create(); | ||
assert.deepEqual(results, generateExpectedMultipleImpactGraphs()); | ||
}); | ||
}); | ||
|
||
class YarnImpactGraphUtilMock extends YarnImpactGraphUtil { | ||
protected runYarnWhy(): YarnWhyItem[] { | ||
const yarnWhyOutput: YarnWhyItem[] = [ | ||
{ | ||
type: 'info', | ||
data: '\r=> Found "[email protected]"' | ||
}, | ||
{ | ||
type: 'info', | ||
data: 'Has been hoisted to "minimist"' | ||
}, | ||
{ | ||
type: 'info', | ||
data: 'Reasons this module exists' | ||
}, | ||
{ | ||
type: 'list', | ||
data: { | ||
type: 'reasons', | ||
items: [ | ||
'Specified in "dependencies"', | ||
'Hoisted from "jest-cli#node-notifier#minimist"', | ||
'Hoisted from "jest-cli#sane#minimist"', | ||
'Hoisted from "jest-cli#istanbul-lib-instrument#babel-generator#detect-indent#minimist"' | ||
] | ||
} | ||
}, | ||
{ | ||
type: 'info', | ||
data: 'Disk size without dependencies: "96KB"' | ||
}, | ||
{ | ||
type: 'info', | ||
data: '\r=> Found "mkdirp#[email protected]"' | ||
}, | ||
{ | ||
type: 'info', | ||
data: 'This module exists because "jest-cli#istanbul-api#mkdirp" depends on it.' | ||
} | ||
]; | ||
return yarnWhyOutput; | ||
} | ||
} | ||
|
||
function generateExpectedSingleImpactGraph(): IImpactGraph { | ||
return { | ||
root: { | ||
name: 'Mock-Project', | ||
children: [ | ||
{ | ||
name: 'jest-cli', | ||
children: [ | ||
{ | ||
name: 'istanbul-api', | ||
children: [ | ||
{ | ||
name: 'mkdirp', | ||
children: [ | ||
{ | ||
name: 'minimist:0.0.8' | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
pathsCount: 1, | ||
pathsLimit: RootNode.IMPACT_PATHS_LIMIT | ||
}; | ||
} | ||
|
||
function generateExpectedMultipleImpactGraphs(): IImpactGraph { | ||
return { | ||
root: { | ||
name: 'Mock-Project', | ||
children: [ | ||
{ | ||
name: 'minimist:1.2.0' | ||
}, | ||
{ | ||
name: 'jest-cli', | ||
children: [ | ||
{ | ||
name: 'node-notifier', | ||
children: [ | ||
{ | ||
name: 'minimist:1.2.0' | ||
} | ||
] | ||
}, | ||
{ | ||
name: 'sane', | ||
children: [ | ||
{ | ||
name: 'minimist:1.2.0' | ||
} | ||
] | ||
}, | ||
{ | ||
name: 'istanbul-lib-instrument', | ||
children: [ | ||
{ | ||
name: 'babel-generator', | ||
children: [ | ||
{ | ||
name: 'detect-indent', | ||
children: [ | ||
{ | ||
name: 'minimist:1.2.0' | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
pathsCount: 4, | ||
pathsLimit: RootNode.IMPACT_PATHS_LIMIT | ||
}; | ||
} |