1var fs = require('graceful-fs') 2var path = require('path') 3var existsSync = fs.existsSync || path.existsSync 4 5var mkdirp = require('mkdirp') 6var rimraf = require('rimraf') 7var test = require('tap').test 8 9var common = require('../common-tap.js') 10 11var pkg = common.pkg 12 13var EXEC_OPTS = { cwd: pkg } 14 15var json = { 16 name: 'install-cli-only-shrinkwrap', 17 description: 'fixture', 18 version: '0.0.0', 19 dependencies: { 20 dependency: 'file:./dependency' 21 }, 22 devDependencies: { 23 'dev-dependency': 'file:./dev-dependency' 24 } 25} 26 27var shrinkwrap = { 28 name: 'install-cli-only-shrinkwrap', 29 description: 'fixture', 30 version: '0.0.0', 31 lockfileVersion: 1, 32 requires: true, 33 dependencies: { 34 dependency: { 35 version: 'file:./dependency' 36 }, 37 'dev-dependency': { 38 version: 'file:./dev-dependency', 39 dev: true 40 } 41 } 42} 43 44var dependency = { 45 name: 'dependency', 46 description: 'fixture', 47 version: '0.0.0' 48} 49 50var devDependency = { 51 name: 'dev-dependency', 52 description: 'fixture', 53 version: '0.0.0' 54} 55 56test('setup', function (t) { 57 mkdirp.sync(path.join(pkg, 'dependency')) 58 fs.writeFileSync( 59 path.join(pkg, 'dependency', 'package.json'), 60 JSON.stringify(dependency, null, 2) 61 ) 62 63 mkdirp.sync(path.join(pkg, 'dev-dependency')) 64 fs.writeFileSync( 65 path.join(pkg, 'dev-dependency', 'package.json'), 66 JSON.stringify(devDependency, null, 2) 67 ) 68 69 mkdirp.sync(path.join(pkg, 'node_modules')) 70 fs.writeFileSync( 71 path.join(pkg, 'package.json'), 72 JSON.stringify(json, null, 2) 73 ) 74 fs.writeFileSync( 75 path.join(pkg, 'npm-shrinkwrap.json'), 76 JSON.stringify(shrinkwrap, null, 2) 77 ) 78 t.end() 79}) 80 81test('\'npm install --only=development\' should only install devDependencies', function (t) { 82 common.npm(['install', '--only=development'], EXEC_OPTS, function (err, code, stderr, stdout) { 83 if (err) throw err 84 t.comment(stdout.trim()) 85 t.comment(stderr.trim()) 86 t.is(code, 0, 'npm install did not raise error code') 87 t.ok( 88 existsSync( 89 path.resolve(pkg, 'node_modules/dev-dependency/package.json') 90 ), 91 'devDependency was installed' 92 ) 93 t.notOk( 94 existsSync(path.resolve(pkg, 'node_modules/dependency/package.json')), 95 'dependency was NOT installed' 96 ) 97 rimraf(path.join(pkg, 'node_modules'), t.end) 98 }) 99}) 100 101test('\'npm install --only=production\' should only install dependencies', function (t) { 102 common.npm(['install', '--only=production'], EXEC_OPTS, function (err, code, stdout, stderr) { 103 if (err) throw err 104 t.comment(stdout.trim()) 105 t.comment(stderr.trim()) 106 t.is(code, 0, 'npm install did not raise error code') 107 t.ok( 108 existsSync( 109 path.resolve(pkg, 'node_modules/dependency/package.json') 110 ), 111 'dependency was installed' 112 ) 113 t.notOk( 114 existsSync(path.resolve(pkg, 'node_modules/dev-dependency/package.json')), 115 'devDependency was NOT installed' 116 ) 117 rimraf(path.join(pkg, 'node_modules'), t.end) 118 }) 119}) 120