summaryrefslogtreecommitdiff
path: root/deps/npm/test/tap/outdated-new-versions.js
blob: bfd63e18c355e799a347f21dc6845f725df15aba (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
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 common = require('../common-tap.js')
var npm = require('../../')

var pkg = path.resolve(__dirname, 'outdated-new-versions')
var cache = path.resolve(pkg, 'cache')

var json = {
  name: 'new-versions-with-outdated',
  author: 'Rockbert',
  version: '0.0.0',
  dependencies: {
    underscore: '~1.3.1'
  },
  devDependencies: {
    request: '~0.9.0'
  }
}

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

test('dicovers new versions in outdated', function (t) {
  process.chdir(pkg)
  t.plan(4)

  mr({ port: common.port }, function (er, s) {
    npm.load({ cache: cache, registry: common.registry }, function () {
      npm.outdated(function (er, d) {
        t.ifError(er, 'npm outdated completed successfully')
        t.is(process.exitCode, 1, 'exitCode set to 1')
        process.exitCode = 0
        for (var i = 0; i < d.length; i++) {
          if (d[i][1] === 'underscore') t.equal('1.5.1', d[i][4])
          if (d[i][1] === 'request') t.equal('2.27.0', d[i][4])
        }
        s.close()
        t.end()
      })
    })
  })
})

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

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