summaryrefslogtreecommitdiff
path: root/deps/npm/test/tap/outdated.js
blob: 8b1907d95f942aa6bb7a2d024176764831398849 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
var fs = require('graceful-fs')
var path = require('path')

var mkdirp = require('mkdirp')
var mr = require('npm-registry-mock')
var rimraf = require('rimraf')
var test = require('tap').test

var npm = require('../../')
var common = require('../common-tap.js')

// config
var pkg = path.resolve(__dirname, 'outdated')
var cache = path.resolve(pkg, 'cache')
var originalLog

var json = {
  name: 'outdated',
  description: 'fixture',
  version: '0.0.1',
  dependencies: {
    underscore: '1.3.1',
    async: '0.2.9',
    checker: '0.5.1'
  }
}

test('setup', function (t) {
  cleanup()
  originalLog = console.log
  mkdirp.sync(cache)
  fs.writeFileSync(
    path.join(pkg, 'package.json'),
    JSON.stringify(json, null, 2)
  )

  process.chdir(pkg)
  t.end()
})

test('it should not throw', function (t) {
  var output = []
  var expOut = [
    path.resolve(pkg, 'node_modules', 'async') +
      ':async@0.2.9' +
      ':async@0.2.9' +
      ':async@0.2.10' +
      '\n' +
    path.resolve(pkg, 'node_modules', 'checker') +
      ':checker@0.5.1' +
      ':checker@0.5.1' +
      ':checker@0.5.2' +
      '\n' +
    path.resolve(pkg, 'node_modules', 'underscore') +
      ':underscore@1.3.1' +
      ':underscore@1.3.1' +
      ':underscore@1.5.1'
  ]

  var expData = [
    [
      pkg,
      'async',
      '0.2.9',
      '0.2.9',
      '0.2.10',
      '0.2.9',
      null
    ],
    [
      pkg,
      'checker',
      '0.5.1',
      '0.5.1',
      '0.5.2',
      '0.5.1',
      null
    ],
    [
      pkg,
      'underscore',
      '1.3.1',
      '1.3.1',
      '1.5.1',
      '1.3.1',
      null
    ]
  ]

  console.log = function () {}
  mr({ port: common.port }, function (er, s) {
    npm.load(
      {
        cache: 'cache',
        loglevel: 'silent',
        parseable: true,
        registry: common.registry
      },
      function () {
        npm.install('.', function (err) {
          t.ifError(err, 'install success')
          console.log = function () {
            output.push.apply(output, arguments)
          }
          npm.outdated(function (er, d) {
            t.ifError(err, 'outdated completed without error')
            t.equals(process.exitCode, 1, 'exitCode set to 1')
            process.exitCode = 0
            output = output.map(function (x) { return x.replace(/\r/g, '') })
            console.log = originalLog

            t.same(output, expOut)
            t.same(d, expData)

            s.close()
            t.end()
          })
        })
      }
    )
  })
})

test('cleanup', function (t) {
  cleanup()
  console.log = originalLog
  t.end()
})

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