• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var fs = require('graceful-fs')
2var path = require('path')
3
4var mr = require('npm-registry-mock')
5var test = require('tap').test
6
7var common = require('../common-tap')
8
9var pkg = common.pkg
10
11var EXEC_OPTS = { cwd: pkg }
12
13var json = {
14  name: 'ls-depth-umnet',
15  author: 'Evan You',
16  version: '0.0.0',
17  dependencies: {
18    'test-package-with-one-dep': '0.0.0',
19    underscore: '1.5.1',
20    optimist: '0.6.0'
21  }
22}
23
24test('setup', function (t) {
25  fs.writeFileSync(
26    path.join(pkg, 'package.json'),
27    JSON.stringify(json, null, 2)
28  )
29  mr({ port: common.port }, function (er, s) {
30    common.npm(
31      [
32        '--registry', common.registry,
33        'install', '--no-save', 'underscore@1.3.1', 'mkdirp', 'test-package-with-one-dep'
34      ],
35      EXEC_OPTS,
36      function (er, c) {
37        t.ifError(er, 'setup installation ran without issue')
38        t.equal(c, 0)
39        s.close()
40        t.end()
41      }
42    )
43  })
44})
45
46test('npm ls --depth=0', function (t) {
47  common.npm(
48    ['ls', '--depth=0'],
49    EXEC_OPTS,
50    function (er, c, out) {
51      t.ifError(er, 'setup installation ran without issue')
52      t.equal(c, 1, 'ls barfed')
53      t.has(
54        out,
55        /UNMET DEPENDENCY optimist@0\.6\.0/,
56        'output contains optimist@0.6.0 and labeled as unmet dependency'
57      )
58      t.has(
59        out,
60        /mkdirp@0\.3\.5 extraneous/,
61        'output contains mkdirp@0.3.5 and labeled as extraneous'
62      )
63      t.has(
64        out,
65        /underscore@1\.3\.1 invalid/,
66        'output contains underscore@1.3.1 and labeled as invalid'
67      )
68      t.has(
69        out,
70        /test-package-with-one-dep@0\.0\.0\n/,
71        'output contains test-package-with-one-dep@0.0.0 and has no labels'
72      )
73      t.doesNotHave(
74        out,
75        /test-package@0\.0\.0/,
76        'output does not contain test-package@0.0.0 which is at depth=1'
77      )
78      t.end()
79    }
80  )
81})
82
83test('npm ls --depth=1', function (t) {
84  common.npm(
85    ['ls', '--depth=1'],
86    EXEC_OPTS,
87    function (er, c, out) {
88      t.ifError(er, 'setup installation ran without issue')
89      t.equal(c, 1, 'ls barfed')
90      t.has(
91        out,
92        /UNMET DEPENDENCY optimist@0\.6\.0/,
93        'output contains optimist@0.6.0 and labeled as unmet dependency'
94      )
95      t.has(
96        out,
97        /mkdirp@0\.3\.5 extraneous/,
98        'output contains mkdirp@0.3.5 and labeled as extraneous'
99      )
100      t.has(
101        out,
102        /underscore@1\.3\.1 invalid/,
103        'output contains underscore@1.3.1 and labeled as invalid'
104      )
105      t.has(
106        out,
107        /test-package-with-one-dep@0\.0\.0\n/,
108        'output contains test-package-with-one-dep@0.0.0 and has no labels'
109      )
110      t.has(
111        out,
112        /test-package@0\.0\.0/,
113        'output contains test-package@0.0.0 which is at depth=1'
114      )
115      t.end()
116    }
117  )
118})
119
120test('npm ls --depth=Infinity', function (t) {
121  // travis has a preconfigured depth=0, in general we can not depend
122  // on the default value in all environments, so explicitly set it here
123  common.npm(
124    ['ls', '--depth=Infinity'],
125    EXEC_OPTS,
126    function (er, c, out) {
127      t.ifError(er, 'setup installation ran without issue')
128      t.equal(c, 1, 'ls barfed')
129      t.has(
130        out,
131        /UNMET DEPENDENCY optimist@0\.6\.0/,
132        'output contains optimist@0.6.0 and labeled as unmet dependency'
133      )
134      t.has(
135        out,
136        /mkdirp@0\.3\.5 extraneous/,
137        'output contains mkdirp@0.3.5 and labeled as extraneous'
138      )
139      t.has(
140        out,
141        /underscore@1\.3\.1 invalid/,
142        'output contains underscore@1.3.1 and labeled as invalid'
143      )
144      t.has(
145        out,
146        /test-package-with-one-dep@0\.0\.0\n/,
147        'output contains test-package-with-one-dep@0.0.0 and has no labels'
148      )
149      t.has(
150        out,
151        /test-package@0\.0\.0/,
152        'output contains test-package@0.0.0 which is at depth=1'
153      )
154      t.end()
155    }
156  )
157})
158