|
| 1 | +import { createFromJSON, DepGraphData } from '../../src'; |
| 2 | +import { loadFixture } from '../helpers'; |
| 3 | +import * as depGraphLib from '../../src'; |
| 4 | + |
| 5 | +describe('isTransitive', () => { |
| 6 | + it('checks direct', () => { |
| 7 | + const graphJson: DepGraphData = loadFixture('simple-graph.json'); |
| 8 | + |
| 9 | + const depGraph = createFromJSON(graphJson); |
| 10 | + |
| 11 | + expect(depGraph.isTransitive({ name: 'a', version: '1.0.0' })).toBe(false); |
| 12 | + expect(depGraph.isTransitive({ name: 'b', version: '1.0.0' })).toBe(false); |
| 13 | + expect(depGraph.isTransitive({ name: 'e', version: '5.0.0' })).toBe(true); |
| 14 | + expect(depGraph.isTransitive({ name: 'd', version: '0.0.1' })).toBe(true); |
| 15 | + expect(depGraph.isTransitive({ name: 'd', version: '0.0.2' })).toBe(true); |
| 16 | + expect(depGraph.isTransitive({ name: 'c', version: '1.0.0' })).toBe(true); |
| 17 | + }); |
| 18 | + |
| 19 | + it('assume non-transitive if any directly depends', () => { |
| 20 | + const builder = new depGraphLib.DepGraphBuilder( |
| 21 | + { name: 'npm' }, |
| 22 | + { name: 'root', version: '1.2.3' }, |
| 23 | + ); |
| 24 | + const rootNodeId = 'root-node'; |
| 25 | + |
| 26 | + // root depends on 'a' and 'b', 'b' depends again on 'a'. |
| 27 | + builder.addPkgNode({ name: 'a', version: '1.0.0' }, 'a|1'); |
| 28 | + builder.connectDep(rootNodeId, 'a|1'); |
| 29 | + |
| 30 | + builder.addPkgNode({ name: 'b', version: '1.0.0' }, 'b'); |
| 31 | + builder.connectDep(rootNodeId, 'b'); |
| 32 | + |
| 33 | + builder.addPkgNode({ name: 'a', version: '1.0.0' }, 'a|2'); |
| 34 | + builder.connectDep('b', 'a|2'); |
| 35 | + |
| 36 | + const depGraph = builder.build(); |
| 37 | + |
| 38 | + expect(depGraph.isTransitive({ name: 'a', version: '1.0.0' })).toBe(false); |
| 39 | + expect(depGraph.isTransitive({ name: 'b', version: '1.0.0' })).toBe(false); |
| 40 | + }); |
| 41 | +}); |
0 commit comments