summaryrefslogtreecommitdiff
path: root/deps/node/deps/npm/test/need-npm5-update/outdated-depth-integer.js
blob: 98c08fa192fcae16f71bcff4dbe4dbc8bd5600cb (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
80
var common = require('../common-tap')
var test = require('tap').test
var rimraf = require('rimraf')
var npm = require('../../')
var mr = require('npm-registry-mock')
var path = require('path')
var pkg = path.resolve('outdated-depth-integer')

var osenv = require('osenv')
var mkdirp = require('mkdirp')
var fs = require('fs')

var pj = JSON.stringify({
  'name': 'whatever',
  'description': 'yeah idk',
  'version': '1.2.3',
  'main': 'index.js',
  'dependencies': {
    'underscore': '1.3.1'
  },
  'repository': 'git://github.com/luk-/whatever'
}, null, 2)

function cleanup () {
  process.chdir(osenv.tmpdir())
  rimraf.sync(pkg)
}

function setup () {
  mkdirp.sync(pkg)
  process.chdir(pkg)
  fs.writeFileSync('package.json', pj)
}

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

test('outdated depth integer', function (t) {
  // todo: update with test-package-with-one-dep once the new
  // npm-registry-mock is published
  var expected = [[
    pkg,
    'underscore',
    undefined, // no version installed
    '1.3.1', // wanted
    '1.5.1', // latest
    '1.3.1',
    null
  ]]

  mr({ port: common.port }, function (er, s) {
    npm.load({
      cache: pkg + '/cache',
      loglevel: 'silent',
      registry: common.registry,
      depth: 5
    }
      , function () {
      npm.install('request@0.9.0', function (er) {
        if (er) throw new Error(er)
        npm.outdated(function (err, d) {
          t.ifError(err, 'outdated did not error')
          t.is(process.exitCode, 1, 'exitCode set to 1')
          process.exitCode = 0
          t.deepEqual(d, expected)
          s.close()
          t.end()
        })
      })
    })
  })
})

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