summaryrefslogtreecommitdiff
path: root/deps/node/deps/npm/node_modules/read-installed/test/depth-0.js
blob: 459df8a729e4120c9409445186baaa90ec42c43d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
var readInstalled = require("../read-installed.js")
var test = require("tap").test
var json = require("../package.json")
var path = require("path")
var known = [].concat(Object.keys(json.dependencies)
  , Object.keys(json.optionalDependencies)
  , Object.keys(json.devDependencies)).sort()

test("make sure that it works with depth=0", function (t) {
  readInstalled(path.join(__dirname, "../"), {
    depth: 0
  }, function (er, map) {
    t.notOk(er, "er should be bull")
    t.ok(map, "map should be data")
    if (er) return console.error(er.stack || er.message)
    // Exclude self from dependencies when depth = 0
    delete map.dependencies[json.name]
    var subdeps = Object.keys(map.dependencies).reduce(function(acc, dep) {
      // Exclude self from dependencies when depth = current depth
      delete map.dependencies[dep].dependencies[dep]
      acc += Object.keys(map.dependencies[dep].dependencies).length;
      return acc;
    }, 0);
    t.equal(subdeps, 0, "there should be no sub dependencies")
    t.end()
  })
})