• 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-env',
15  version: '0.0.0',
16  dependencies: {
17    'test-package-with-one-dep': '0.0.0'
18  }
19}
20
21test('setup', function (t) {
22  fs.writeFileSync(
23    path.join(pkg, 'package.json'),
24    JSON.stringify(json, null, 2)
25  )
26  mr({port: common.port}, function (er, s) {
27    common.npm(
28      [
29        '--registry', common.registry,
30        'install'
31      ],
32      EXEC_OPTS,
33      function (er, c) {
34        t.ifError(er, 'install ran without issue')
35        t.equal(c, 0)
36        s.close()
37        t.end()
38      }
39    )
40  })
41})
42
43test('npm ls --dev', function (t) {
44  common.npm(['ls', '--dev'], EXEC_OPTS, function (er, code, stdout) {
45    t.ifError(er, 'ls --dev ran without issue')
46    t.equal(code, 0)
47    t.has(stdout, /(empty)/, 'output contains (empty)')
48    t.end()
49  })
50})
51
52test('npm ls --only=development', function (t) {
53  common.npm(['ls', '--only=development'], EXEC_OPTS, function (er, code, stdout) {
54    t.ifError(er, 'ls --only=development ran without issue')
55    t.equal(code, 0)
56    t.has(stdout, /(empty)/, 'output contains (empty)')
57    t.end()
58  })
59})
60
61test('npm ls --only=dev', function (t) {
62  common.npm(['ls', '--only=dev'], EXEC_OPTS, function (er, code, stdout) {
63    t.ifError(er, 'ls --only=dev ran without issue')
64    t.equal(code, 0)
65    t.has(stdout, /(empty)/, 'output contains (empty)')
66    t.end()
67  })
68})
69
70test('npm ls --production', function (t) {
71  common.npm(['ls', '--production'], EXEC_OPTS, function (er, code, stdout) {
72    t.ifError(er, 'ls --production ran without issue')
73    t.notOk(code, 'npm exited ok')
74    t.has(
75      stdout,
76      /test-package-with-one-dep@0\.0\.0/,
77      'output contains test-package-with-one-dep@0.0.0'
78    )
79    t.end()
80  })
81})
82
83test('npm ls --prod', function (t) {
84  common.npm(['ls', '--prod'], EXEC_OPTS, function (er, code, stdout) {
85    t.ifError(er, 'ls --prod ran without issue')
86    t.notOk(code, 'npm exited ok')
87    t.has(
88      stdout,
89      /test-package-with-one-dep@0\.0\.0/,
90      'output contains test-package-with-one-dep@0.0.0'
91    )
92    t.end()
93  })
94})
95
96test('npm ls --only=production', function (t) {
97  common.npm(['ls', '--only=production'], EXEC_OPTS, function (er, code, stdout) {
98    t.ifError(er, 'ls --only=production ran without issue')
99    t.notOk(code, 'npm exited ok')
100    t.has(
101      stdout,
102      /test-package-with-one-dep@0\.0\.0/,
103      'output contains test-package-with-one-dep@0.0.0'
104    )
105    t.end()
106  })
107})
108
109test('npm ls --only=prod', function (t) {
110  common.npm(['ls', '--only=prod'], EXEC_OPTS, function (er, code, stdout) {
111    t.ifError(er, 'ls --only=prod ran without issue')
112    t.notOk(code, 'npm exited ok')
113    t.has(
114      stdout,
115      /test-package-with-one-dep@0\.0\.0/,
116      'output contains test-package-with-one-dep@0.0.0'
117    )
118    t.end()
119  })
120})
121