From ef33cb79960b7e2d28e2ee4830943c423069f3ee Mon Sep 17 00:00:00 2001 From: Daniel Stockman Date: Fri, 18 Jan 2019 12:07:27 -0800 Subject: [PATCH] fix(package-graph): Use correct property when testing for duplicates --- .../__tests__/package-graph.test.js | 24 +++++++++++++++++++ core/package-graph/index.js | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/core/package-graph/__tests__/package-graph.test.js b/core/package-graph/__tests__/package-graph.test.js index 89a0dfbf79..54252e7f87 100644 --- a/core/package-graph/__tests__/package-graph.test.js +++ b/core/package-graph/__tests__/package-graph.test.js @@ -6,6 +6,30 @@ const Package = require("@lerna/package"); const PackageGraph = require(".."); describe("PackageGraph", () => { + describe("constructor", () => { + it("throws an error when duplicate package names are present", () => { + const pkgs = [ + new Package({ name: "pkg-1", version: "1.0.0" }, "/test/pkg-1", "/test"), + new Package({ name: "pkg-2", version: "2.0.0" }, "/test/pkg-2", "/test"), + new Package({ name: "pkg-2", version: "3.0.0" }, "/test/pkg-3", "/test"), + ]; + + try { + // eslint-disable-next-line no-unused-vars + const graph = new PackageGraph(pkgs); + } catch (err) { + expect(err.prefix).toBe("ENAME"); + expect(err.message).toMatchInlineSnapshot(` +"Package name \\"pkg-2\\" used in multiple packages: + /test/pkg-2 + /test/pkg-3" +`); + } + + expect.assertions(2); + }); + }); + describe("Node", () => { it("proxies Package properties", () => { const pkg = new Package({ name: "my-pkg", version: "1.2.3" }, "/path/to/my-pkg"); diff --git a/core/package-graph/index.js b/core/package-graph/index.js index b17774dc8c..279de06963 100644 --- a/core/package-graph/index.js +++ b/core/package-graph/index.js @@ -67,7 +67,7 @@ class PackageGraph extends Map { constructor(packages, graphType = "allDependencies", forceLocal) { super(packages.map(pkg => [pkg.name, new PackageGraphNode(pkg)])); - if (packages.size !== this.size) { + if (packages.length !== this.size) { // weed out the duplicates const seen = new Map();