• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var common = require('../common-tap')
2var path = require('path')
3var test = require('tap').test
4var rimraf = require('rimraf')
5var mr = require('npm-registry-mock')
6var pkg = path.resolve(__dirname, 'outdated-depth-deep')
7var cache = path.resolve(pkg, 'cache')
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    'npm-test-peer-deps': '0.0.0'
21  },
22  'repository': 'git://github.com/luk-/whatever'
23}, null, 2)
24
25function cleanup () {
26  process.chdir(osenv.tmpdir())
27  rimraf.sync(pkg)
28}
29
30function setup () {
31  mkdirp.sync(pkg)
32  process.chdir(pkg)
33  fs.writeFileSync(path.resolve(pkg, 'package.json'), pj)
34}
35
36test('setup', function (t) {
37  cleanup()
38  setup()
39  t.end()
40})
41
42test('outdated depth deep (9999)', function (t) {
43  var conf = [
44    '--registry', common.registry,
45    '--cache', cache
46  ]
47
48  var server
49  mr({ port: common.port }, thenTopLevelInstall)
50
51  function thenTopLevelInstall (err, s) {
52    if (err) throw err
53    server = s
54    common.npm(conf.concat(['install', '.']), {cwd: pkg}, thenDeepInstall)
55  }
56
57  function thenDeepInstall (err, code, stdout, stderr) {
58    if (err) throw err
59    t.is(code, 0, 'install completed successfully')
60    t.is('', stderr, 'no error output')
61    var depPath = path.join(pkg, 'node_modules', 'npm-test-peer-deps')
62    common.npm(conf.concat(['install', 'underscore']), {cwd: depPath}, thenRunOutdated)
63  }
64
65  function thenRunOutdated (err, code, stdout, stderr) {
66    if (err) throw err
67    t.is(code, 0, 'deep install completed successfully')
68    t.is('', stderr, 'no error output')
69    common.npm(conf.concat(['outdated', '--depth', 9999]), {cwd: pkg}, thenValidateOutput)
70  }
71
72  function thenValidateOutput (err, code, stdout, stderr) {
73    if (err) throw err
74    t.ifError(err)
75    t.is(code, 1, 'npm outdated exited with code 1')
76    t.match(
77      stdout,
78      /underscore.*1\.3\.1.*1\.3\.1.*1\.5\.1.*whatever\n/g,
79      'child package listed')
80    t.match(
81      stdout,
82      /underscore.*1\.3\.1.*1\.3\.1.*1\.5\.1.*whatever > npm-test-peer-deps/g,
83      'child package listed')
84    server.close()
85    t.end()
86  }
87})
88
89test('cleanup', function (t) {
90  cleanup()
91  t.end()
92})
93