summaryrefslogtreecommitdiff
path: root/deps/npm/test/tap/install-local-dep-cycle.js
blob: a66f04bce4715d1b6ea12ecaa16adac5c7e20612 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
'use strict'
var path = require('path')
var fs = require('graceful-fs')
var mkdirp = require('mkdirp')
var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')

var base = common.pkg

var baseJSON = {
  name: 'base',
  version: '1.0.0',
  dependencies: {
    a: 'file:a/',
    b: 'file:b/'
  }
}

var aPath = path.join(base, 'a')
var aJSON = {
  name: 'a',
  version: '1.0.0',
  dependencies: {
    b: 'file:../b',
    c: 'file:../c'
  }
}

var bPath = path.join(base, 'b')
var bJSON = {
  name: 'b',
  version: '1.0.0'
}

var cPath = path.join(base, 'c')
var cJSON = {
  name: 'c',
  version: '1.0.0',
  dependencies: {
    b: 'file:../b'
  }
}

test('setup', function (t) {
  cleanup()
  setup()
  t.end()
})

test('install', function (t) {
  common.npm(['install'], {cwd: base}, function (er, code, stdout, stderr) {
    t.ifError(er, 'npm config ran without issue')
    t.is(code, 0, 'exited with a non-error code')
    t.is(stderr, '', 'Ran without errors')
    t.end()
  })
})

test('cleanup', function (t) {
  cleanup()
  t.end()
})

function saveJson (pkgPath, json) {
  mkdirp.sync(pkgPath)
  fs.writeFileSync(path.join(pkgPath, 'package.json'), JSON.stringify(json, null, 2))
}

function setup () {
  saveJson(base, baseJSON)
  saveJson(aPath, aJSON)
  saveJson(bPath, bJSON)
  saveJson(cPath, cJSON)
}

function cleanup () {
  rimraf.sync(base)
}