• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var test = require("tap").test
2var mkdirp = require("mkdirp")
3var rimraf = require("rimraf")
4var fs = require("fs")
5var path = require("path")
6var readInstalled = require("../read-installed.js")
7
8var parent = {
9  name: "parent",
10  version: "1.2.3",
11  dependencies: {},
12  devDependencies: {
13    "child1":"*"
14  },
15  readme:"."
16}
17
18var child1 = {
19  name: "child1",
20  version: "1.2.3",
21  peerDependencies: {
22    child2: "*"
23  },
24  readme:"."
25}
26
27var child2 = {
28  name: "child2",
29  version: "1.2.3",
30  peerDependencies: {
31    child1: "*"
32  },
33  readme:"."
34}
35
36
37var root = path.resolve(__dirname, "cyclic-extraneous-peer-deps")
38var parentjson = path.resolve(root, "package.json")
39var child1root = path.resolve(root, "node_modules/child1")
40var child1json = path.resolve(child1root, "package.json")
41var child2root = path.resolve(root, "node_modules/child2")
42var child2json = path.resolve(child2root, "package.json")
43
44test("setup", function (t) {
45  rimraf.sync(root)
46  mkdirp.sync(child1root)
47  mkdirp.sync(child2root)
48  fs.writeFileSync(parentjson, JSON.stringify(parent, null, 2) + "\n", "utf8")
49  fs.writeFileSync(child1json, JSON.stringify(child1, null, 2) + "\n", "utf8")
50  fs.writeFileSync(child2json, JSON.stringify(child2, null, 2) + "\n", "utf8")
51  t.pass("setup done")
52  t.end()
53})
54
55test("dev mode", function (t) {
56  // peer dev deps should both be not extraneous.
57  readInstalled(root, { dev: true }, function (er, data) {
58    if (er)
59      throw er
60    t.notOk(data.dependencies.child1.extraneous, "c1 not extra")
61    t.notOk(data.dependencies.child2.extraneous, "c2 not extra")
62    t.end()
63  })
64})
65
66test("prod mode", function (t) {
67  readInstalled(root, { dev: false }, function (er, data) {
68    if (er)
69      throw er
70    t.ok(data.dependencies.child1.extraneous, "c1 extra")
71    t.ok(data.dependencies.child2.extraneous, "c2 extra")
72    t.end()
73  })
74})
75
76
77test("cleanup", function (t) {
78  rimraf.sync(root)
79  t.pass("cleanup done")
80  t.end()
81})
82