Skip to content

Commit

Permalink
test: helpers.depTreesEqual checks labels & provenance
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-go committed Nov 27, 2019
1 parent 0786b06 commit 6b6336b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions test/helpers.ts
Expand Up @@ -25,6 +25,10 @@ export function depTreesEqual(a: any, b: any) {
return false;
}

if (!_.isEqual(a.labels, b.labels) || !_.isEqual(a.versionProvenance, b.versionProvenance)) {
return false;
}

const aDeps = a.dependencies || {};
const bDeps = b.dependencies || {};

Expand Down
16 changes: 14 additions & 2 deletions test/legacy/from-dep-tree.test.ts
Expand Up @@ -325,16 +325,22 @@ describe('depTreeToGraph with (invalid) null dependency', () => {

describe('with versionProvenance', () => {
let depGraph: types.DepGraph;
let depTree: depGraphLib.legacy.DepTree;

beforeAll(async () => {
const depTree = helpers.loadFixture('maven-dep-tree.json');
depTree = helpers.loadFixture('maven-dep-tree.json');
depGraph = await depGraphLib.legacy.depTreeToGraph(depTree, 'maven');
});

it('matches snapshot', () => {
expect(depGraph.toJSON()).toMatchSnapshot();
});

it ('equals orig depTree when converted back', async () => {
const restoredDepTree = await depGraphLib.legacy.graphToDepTree(depGraph, 'maven');
expect(helpers.depTreesEqual(restoredDepTree, depTree)).toBeTruthy();
});

it ('getPkgNodes() returns versionProvenance', () => {
const commonsIoNodes = depGraph.getPkgNodes({name: 'commons-io:commons-io', version: '2.2'});
expect(commonsIoNodes[0].info.versionProvenance!.type).toEqual('dependencyManagement');
Expand Down Expand Up @@ -364,16 +370,22 @@ describe('without versionProvenance', () => {

describe('with labels', () => {
let depGraph: types.DepGraph;
let depTree: depGraphLib.legacy.DepTree;

beforeAll(async () => {
const depTree = helpers.loadFixture('labelled-dep-tree.json');
depTree = helpers.loadFixture('labelled-dep-tree.json');
depGraph = await depGraphLib.legacy.depTreeToGraph(depTree, 'maven');
});

it('matches snapshot', () => {
expect(depGraph.toJSON()).toMatchSnapshot();
});

it ('equals orig depTree when converted back', async () => {
const restoredDepTree = await depGraphLib.legacy.graphToDepTree(depGraph, 'maven');
expect(helpers.depTreesEqual(restoredDepTree, depTree)).toBeTruthy();
});

it('getPkgNodes() returns labels', () => {
let dNodes = depGraph.getPkgNodes({name: 'd', version: '2.0.0'});
dNodes = _.sortBy(dNodes, 'id');
Expand Down

0 comments on commit 6b6336b

Please sign in to comment.