• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var fs = require('fs')
2var path = require('path')
3
4var mr = require('npm-registry-mock')
5var test = require('tap').test
6
7var common = require('../common-tap')
8var server
9
10var pkg = common.pkg
11var cache = common.cache
12
13var json = {
14  name: 'prune-with-dev-dep-duplicate',
15  description: 'fixture',
16  version: '0.0.1',
17  main: 'index.js',
18  dependencies: {
19    'test-package': '0.0.0'
20  },
21  devDependencies: {
22    'test-package': '0.0.0'
23  }
24}
25
26var EXEC_OPTS = {
27  cwd: pkg,
28  npm_config_depth: 'Infinity'
29}
30
31test('setup', function (t) {
32  fs.writeFileSync(
33    path.join(pkg, 'package.json'),
34    JSON.stringify(json, null, 2)
35  )
36  mr({ port: common.port }, function (er, s) {
37    server = s
38    t.end()
39  })
40})
41
42function readdir (dir) {
43  try {
44    return fs.readdirSync(dir)
45  } catch (ex) {
46    if (ex.code === 'ENOENT') return []
47    throw ex
48  }
49}
50
51test('npm install also=dev', function (t) {
52  common.npm([
53    'install',
54    '--cache', cache,
55    '--registry', common.registry,
56    '--loglevel', 'silent',
57    '--also=dev'
58  ], EXEC_OPTS, function (err, code, stdout, stderr) {
59    if (err) throw err
60    t.notOk(code, 'exit ok')
61    t.notOk(stderr, 'Should not get data on stderr: ' + stderr)
62    var dirs = readdir(pkg + '/node_modules').sort()
63    t.same(dirs, [ 'test-package' ].sort())
64    t.end()
65  })
66})
67
68test('npm prune also=dev', function (t) {
69  common.npm([
70    'prune',
71    '--loglevel', 'silent',
72    '--also=dev'
73  ], EXEC_OPTS, function (err, code, stdout, stderr) {
74    if (err) throw err
75    t.notOk(code, 'exit ok')
76    t.notOk(stderr, 'Should not get data on stderr: ' + stderr)
77    var dirs = readdir(pkg + '/node_modules').sort()
78    t.same(dirs, [ 'test-package' ])
79    t.end()
80  })
81})
82
83test('npm prune only=prod', function (t) {
84  common.npm([
85    'prune',
86    '--loglevel', 'silent',
87    '--only=prod',
88    '--json'
89  ], EXEC_OPTS, function (err, code, stdout, stderr) {
90    if (err) throw err
91    t.notOk(code, 'exit ok')
92    t.isDeeply(JSON.parse(stdout).removed, [], 'removed nothing')
93    var dirs = readdir(pkg + '/node_modules').sort()
94    t.same(dirs, [ 'test-package' ])
95    t.end()
96  })
97})
98
99test('cleanup', function (t) {
100  server.close()
101  t.pass('cleaned up')
102  t.end()
103})
104