summaryrefslogtreecommitdiff
path: root/deps/npm/test/tap/noargs-install-config-save.js
blob: cb1af408abb5c64df574f45bfccd0f7bcd6fadb1 (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
var common = require('../common-tap.js')
var test = require('tap').test
var fs = require('fs')
var rimraf = require('rimraf')
var mkdirp = require('mkdirp')

var mr = require('npm-registry-mock')

var pkg = common.pkg

function writePackageJson () {
  rimraf.sync(pkg)
  mkdirp.sync(pkg)
  mkdirp.sync(pkg + '/cache')

  fs.writeFileSync(pkg + '/package.json', JSON.stringify({
    'author': 'Rocko Artischocko',
    'name': 'noargs',
    'version': '0.0.0',
    'devDependencies': {
      'underscore': '1.3.1'
    }
  }), 'utf8')
}

var env = {
  'npm_config_save': true,
  'npm_config_registry': common.registry,
  'npm_config_cache': pkg + '/cache',
  HOME: process.env.HOME,
  Path: process.env.PATH,
  PATH: process.env.PATH
}
var OPTS = {
  cwd: pkg,
  env: env
}

test('does not update the package.json with empty arguments', function (t) {
  writePackageJson()
  t.plan(2)

  mr({ port: common.port }, function (er, s) {
    common.npm('install', OPTS, function (er, code, stdout, stderr) {
      if (er) throw er
      t.is(code, 0)
      if (code !== 0) {
        console.error('#', stdout)
        console.error('#', stderr)
      }
      var text = JSON.stringify(fs.readFileSync(pkg + '/package.json', 'utf8'))
      s.close()
      t.equal(text.indexOf('"dependencies'), -1, 'dependencies do not exist in file')
    })
  })
})

test('updates the package.json (adds dependencies) with an argument', function (t) {
  writePackageJson()
  t.plan(2)

  mr({ port: common.port }, function (er, s) {
    common.npm(['install', 'underscore', '-P'], OPTS, function (er, code, stdout, stderr) {
      if (er) throw er
      t.is(code, 0)
      s.close()
      var text = JSON.stringify(fs.readFileSync(pkg + '/package.json', 'utf8'))
      t.notEqual(text.indexOf('"dependencies'), -1, 'dependencies exist in file')
    })
  })
})

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