summaryrefslogtreecommitdiff
path: root/deps/npm/test/tap/circular-dep.js
blob: d9f72e7ddbfb0d497a31e9b866b7961244c3a921 (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var test = require("tap").test
  , fs = require("fs")
  , path = require("path")
  , existsSync = fs.existsSync || path.existsSync
  , npm = require("../../")
  , rimraf = require("rimraf")
  , mr = require("npm-registry-mock")
  , common = require("../common-tap.js")
  , server

test("installing a package that depends on the current package", function (t) {
  t.plan(1)

  setup(function () {
    npm.install("optimist", function (err) {
      if (err) return t.fail(err)
      npm.dedupe(function(err) {
        if (err) return t.fail(err)
        t.ok(existsSync(path.join(__dirname,
          "circular-dep", "minimist", "node_modules", "optimist",
          "node_modules", "minimist"
        )))
        cleanup()
        server.close()
      })
    })
  })
})

function setup (cb) {
  process.chdir(path.join(__dirname, "circular-dep", "minimist"))
  cleanup()
  fs.mkdirSync(path.join(__dirname,
    "circular-dep", "minimist", "node_modules"))
  mr(common.port, function (s) {
    server = s
    npm.load({
      registry: common.registry,
      cache: path.resolve(__dirname, "circular-dep", "cache")
    }, cb)
  })
}

function cleanup() {
  rimraf.sync(path.join(__dirname,
    "circular-dep", "minimist", "node_modules"))
  rimraf.sync(path.join(__dirname,
    "circular-dep", "cache"))
}