summaryrefslogtreecommitdiff
path: root/deps/npm/test/tap/outdated-depth-deep.js
blob: 682b1ca95878e985e177084d56ebabda1a43074d (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
var common = require('../common-tap')
var path = require('path')
var test = require('tap').test
var rimraf = require('rimraf')
var mr = require('npm-registry-mock')
var pkg = path.resolve(__dirname, 'outdated-depth-deep')
var cache = path.resolve(pkg, 'cache')

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',
    'npm-test-peer-deps': '0.0.0'
  },
  '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(path.resolve(pkg, 'package.json'), pj)
}

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

test('outdated depth deep (9999)', function (t) {
  var conf = [
    '--registry', common.registry,
    '--cache', cache
  ]

  var server
  mr({ port: common.port }, thenTopLevelInstall)

  function thenTopLevelInstall (err, s) {
    if (err) throw err
    server = s
    common.npm(conf.concat(['install', '.']), {cwd: pkg}, thenDeepInstall)
  }

  function thenDeepInstall (err, code, stdout, stderr) {
    if (err) throw err
    t.is(code, 0, 'install completed successfully')
    t.is('', stderr, 'no error output')
    var depPath = path.join(pkg, 'node_modules', 'npm-test-peer-deps')
    common.npm(conf.concat(['install', 'underscore']), {cwd: depPath}, thenRunOutdated)
  }

  function thenRunOutdated (err, code, stdout, stderr) {
    if (err) throw err
    t.is(code, 0, 'deep install completed successfully')
    t.is('', stderr, 'no error output')
    common.npm(conf.concat(['outdated', '--depth', 9999]), {cwd: pkg}, thenValidateOutput)
  }

  function thenValidateOutput (err, code, stdout, stderr) {
    if (err) throw err
    t.is(code, 0, 'outdated completed successfully')
    t.is('', stderr, 'no error output')
    t.match(
      stdout,
      /underscore.*1\.3\.1.*1\.3\.1.*1\.5\.1.*whatever\n/g,
      'child package listed')
    t.match(
      stdout,
      /underscore.*1\.3\.1.*1\.3\.1.*1\.5\.1.*whatever > npm-test-peer-deps/g,
      'child package listed')
    server.close()
    t.end()
  }
})

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