Skip to content

Commit

Permalink
fix(package-graph): Use correct property when testing for duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Jan 18, 2019
1 parent 16ab98d commit ef33cb7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions core/package-graph/__tests__/package-graph.test.js
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion core/package-graph/index.js
Expand Up @@ -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();

Expand Down

0 comments on commit ef33cb7

Please sign in to comment.