• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var common = require('../common-tap')
2var test = require('tap').test
3var rimraf = require('rimraf')
4var npm = require('../../')
5var mr = require('npm-registry-mock')
6var path = require('path')
7var pkg = path.resolve('outdated-depth-integer')
8
9var osenv = require('osenv')
10var mkdirp = require('mkdirp')
11var fs = require('fs')
12
13var pj = JSON.stringify({
14  'name': 'whatever',
15  'description': 'yeah idk',
16  'version': '1.2.3',
17  'main': 'index.js',
18  'dependencies': {
19    'underscore': '1.3.1'
20  },
21  'repository': 'git://github.com/luk-/whatever'
22}, null, 2)
23
24function cleanup () {
25  process.chdir(osenv.tmpdir())
26  rimraf.sync(pkg)
27}
28
29function setup () {
30  mkdirp.sync(pkg)
31  process.chdir(pkg)
32  fs.writeFileSync('package.json', pj)
33}
34
35test('setup', function (t) {
36  cleanup()
37  setup()
38  t.end()
39})
40
41test('outdated depth integer', function (t) {
42  // todo: update with test-package-with-one-dep once the new
43  // npm-registry-mock is published
44  var expected = [[
45    pkg,
46    'underscore',
47    undefined, // no version installed
48    '1.3.1', // wanted
49    '1.5.1', // latest
50    '1.3.1',
51    null
52  ]]
53
54  mr({ port: common.port }, function (er, s) {
55    npm.load({
56      cache: pkg + '/cache',
57      loglevel: 'silent',
58      registry: common.registry,
59      depth: 5
60    }
61      , function () {
62      npm.install('request@0.9.0', function (er) {
63        if (er) throw new Error(er)
64        npm.outdated(function (err, d) {
65          t.ifError(err, 'outdated did not error')
66          t.is(process.exitCode, 1, 'exitCode set to 1')
67          process.exitCode = 0
68          t.deepEqual(d, expected)
69          s.close()
70          t.end()
71        })
72      })
73    })
74  })
75})
76
77test('cleanup', function (t) {
78  cleanup()
79  t.end()
80})
81