1var fs = require('fs') 2var path = require('path') 3 4var mkdirp = require('mkdirp') 5var mr = require('npm-registry-mock') 6var test = require('tap').test 7 8var common = require('../common-tap') 9var server 10 11var pkg = common.pkg 12var cache = common.cache 13 14var json = { 15 name: 'prune-with-only-dev-deps', 16 description: 'fixture', 17 version: '0.0.1', 18 main: 'index.js', 19 devDependencies: { 20 'test-package-with-one-dep': '0.0.0', 21 'test-package': '0.0.0' 22 } 23} 24 25var EXEC_OPTS = { 26 cwd: pkg, 27 npm_config_depth: 'Infinity' 28} 29 30test('setup', function (t) { 31 mkdirp.sync(cache) 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 t.ifErr(err, 'install finished successfully') 51 t.notOk(code, 'exit ok') 52 t.notOk(stderr, 'Should not get data on stderr: ' + stderr) 53 t.end() 54 }) 55}) 56 57function readdir (dir) { 58 try { 59 return fs.readdirSync(dir) 60 } catch (ex) { 61 if (ex.code === 'ENOENT') return [] 62 throw ex 63 } 64} 65 66test('verify installs', function (t) { 67 var dirs = readdir(pkg + '/node_modules').sort() 68 t.same(dirs, [ 'test-package', 'test-package-with-one-dep' ].sort()) 69 t.end() 70}) 71 72test('npm prune', function (t) { 73 common.npm([ 74 'prune', 75 '--loglevel', 'silent', 76 '--production', 'false' 77 ], EXEC_OPTS, function (err, code, stdout, stderr) { 78 t.ifErr(err, 'prune finished successfully') 79 t.notOk(code, 'exit ok') 80 t.notOk(stderr, 'Should not get data on stderr: ' + stderr) 81 t.end() 82 }) 83}) 84 85test('verify installs', function (t) { 86 var dirs = readdir(pkg + '/node_modules').sort() 87 t.same(dirs, [ 'test-package', 'test-package-with-one-dep' ]) 88 t.end() 89}) 90 91test('npm prune', function (t) { 92 common.npm([ 93 'prune', 94 '--loglevel', 'silent', 95 '--production', 96 '--json' 97 ], EXEC_OPTS, function (err, code, stdout, stderr) { 98 t.ifErr(err, 'prune finished successfully') 99 t.notOk(code, 'exit ok') 100 t.like(JSON.parse(stdout), {removed: [{name: 'test-package'}, {name: 'test-package-with-one-dep'}]}) 101 t.end() 102 }) 103}) 104 105test('verify installs', function (t) { 106 var dirs = readdir(pkg + '/node_modules').sort() 107 t.same(dirs, []) 108 t.end() 109}) 110 111test('cleanup', function (t) { 112 server.close() 113 t.end() 114}) 115