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.js') 8var pkg = common.pkg 9var opts = [ 10 '--cache=' + common.cache, 11 '--registry=' + common.registry 12] 13 14function reportOutput (t, fh, out) { 15 var trimmed = out.trim() 16 if (!trimmed.length) return 17 var prefix = fh + '> ' 18 t.comment(prefix + trimmed.split(/\n/).join('\n' + prefix)) 19} 20 21var desired = { 22 name: 'npm-test-shrinkwrap-prod-dependency', 23 version: '0.0.0', 24 dependencies: { 25 request: { 26 version: '0.9.0', 27 resolved: common.registry + '/request/-/request-0.9.0.tgz', 28 integrity: 'sha1-EEn1mm9GWI5tAwkh+7hMovDCcU4=' 29 }, 30 underscore: { 31 dev: true, 32 version: '1.5.1', 33 resolved: common.registry + '/underscore/-/underscore-1.5.1.tgz', 34 integrity: 'sha1-0r3oF9F2/63olKtxRY5oKhS4bck=' 35 } 36 } 37} 38 39var json = { 40 author: 'Domenic Denicola', 41 name: 'npm-test-shrinkwrap-prod-dependency', 42 version: '0.0.0', 43 dependencies: { 44 request: '0.9.0' 45 }, 46 devDependencies: { 47 underscore: '1.5.1' 48 } 49} 50 51test("shrinkwrap --also=development doesn't strip out prod dependencies", function (t) { 52 t.plan(4) 53 54 mr({port: common.port}, function (er, s) { 55 t.parent.teardown(() => s.close()) 56 fs.writeFileSync(path.join(pkg, 'package.json'), JSON.stringify(json, null, 2)) 57 common.npm(['install', '.'].concat(opts), {cwd: pkg}, function (err, code, stdout, stderr) { 58 if (err) return t.fail(err) 59 t.is(code, 0, 'install') 60 reportOutput(t, 'out', stdout) 61 reportOutput(t, 'err', stderr) 62 common.npm(['shrinkwrap', '--also=development'].concat(opts), {cwd: pkg}, function (err, code, stdout, stderr) { 63 if (err) return t.fail(err) 64 var ok = t.is(code, 0, 'shrinkwrap') 65 reportOutput(t, 'out', stdout) 66 reportOutput(t, 'err', stderr) 67 if (ok) { 68 try { 69 var results = JSON.parse(fs.readFileSync(path.join(pkg, 'npm-shrinkwrap.json'))) 70 t.pass('read shrinkwrap') 71 } catch (ex) { 72 t.ifError(ex, 'read shrinkwrap') 73 } 74 } 75 t.deepEqual( 76 results.dependencies, 77 desired.dependencies, 78 'results have dev dep' 79 ) 80 s.done() 81 t.end() 82 }) 83 }) 84 }) 85}) 86