• 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',
15  description: 'fixture',
16  version: '0.0.1',
17  main: 'index.js',
18  dependencies: {
19    underscore: '1.3.1'
20  },
21  devDependencies: {
22    mkdirp: '*'
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
42test('npm install', function (t) {
43  common.npm([
44    'install',
45    '--cache', cache,
46    '--registry', common.registry,
47    '--loglevel', 'silent',
48    '--production', 'false'
49  ], EXEC_OPTS, function (err, code, stdout, stderr) {
50    if (err) throw err
51    t.notOk(code, 'exit ok')
52    t.notOk(stderr, 'Should not get data on stderr: ' + stderr)
53    t.end()
54  })
55})
56
57test('npm install test-package', function (t) {
58  common.npm([
59    'install', 'test-package',
60    '--cache', cache,
61    '--registry', common.registry,
62    '--no-save',
63    '--loglevel', 'silent',
64    '--production', 'false'
65  ], EXEC_OPTS, function (err, code, stdout, stderr) {
66    if (err) throw err
67    t.notOk(code, 'exit ok')
68    t.notOk(stderr, 'Should not get data on stderr: ' + stderr)
69    t.end()
70  })
71})
72
73test('setup: verify installs', function (t) {
74  var dirs = fs.readdirSync(pkg + '/node_modules').sort()
75  t.same(dirs, [ 'test-package', 'mkdirp', 'underscore' ].sort())
76  t.end()
77})
78
79test('dev: npm prune', function (t) {
80  common.npm([
81    'prune',
82    '--loglevel', 'silent',
83    '--production', 'false'
84  ], EXEC_OPTS, function (err, code, stdout, stderr) {
85    if (err) throw err
86    t.notOk(code, 'exit ok')
87    t.notOk(stderr, 'Should not get data on stderr: ' + stderr)
88    t.end()
89  })
90})
91
92test('dev: verify installs', function (t) {
93  var dirs = fs.readdirSync(pkg + '/node_modules').sort()
94  t.same(dirs, [ 'mkdirp', 'underscore' ])
95  t.end()
96})
97
98test('production: npm prune', function (t) {
99  common.npm([
100    'prune',
101    '--loglevel', 'silent',
102    '--parseable',
103    '--production'
104  ], EXEC_OPTS, function (err, code, stdout) {
105    if (err) throw err
106    t.notOk(code, 'exit ok')
107    t.equal(stdout.trim().replace(/\\/g, '/'), 'remove\tmkdirp\t0.3.5\tnode_modules/mkdirp')
108    t.end()
109  })
110})
111
112test('pruduction: verify installs', function (t) {
113  var dirs = fs.readdirSync(pkg + '/node_modules').sort()
114  t.same(dirs, [ 'underscore' ])
115  t.end()
116})
117
118test('cleanup', function (t) {
119  server.close()
120  t.end()
121})
122