1var common = require('../common-tap.js') 2var test = require('tap').test 3var fs = require('fs') 4var rimraf = require('rimraf') 5var mkdirp = require('mkdirp') 6 7var mr = require('npm-registry-mock') 8 9var pkg = common.pkg 10 11function writePackageJson () { 12 rimraf.sync(pkg) 13 mkdirp.sync(pkg) 14 mkdirp.sync(pkg + '/cache') 15 16 fs.writeFileSync(pkg + '/package.json', JSON.stringify({ 17 'author': 'Rocko Artischocko', 18 'name': 'noargs', 19 'version': '0.0.0', 20 'devDependencies': { 21 'underscore': '1.3.1' 22 } 23 }), 'utf8') 24} 25 26var env = { 27 'npm_config_save': true, 28 'npm_config_registry': common.registry, 29 'npm_config_cache': pkg + '/cache', 30 HOME: process.env.HOME, 31 Path: process.env.PATH, 32 PATH: process.env.PATH 33} 34var OPTS = { 35 cwd: pkg, 36 env: env 37} 38 39test('does not update the package.json with empty arguments', function (t) { 40 writePackageJson() 41 t.plan(2) 42 43 mr({ port: common.port }, function (er, s) { 44 common.npm('install', OPTS, function (er, code, stdout, stderr) { 45 if (er) throw er 46 t.is(code, 0) 47 if (code !== 0) { 48 console.error('#', stdout) 49 console.error('#', stderr) 50 } 51 var text = JSON.stringify(fs.readFileSync(pkg + '/package.json', 'utf8')) 52 s.close() 53 t.equal(text.indexOf('"dependencies'), -1, 'dependencies do not exist in file') 54 }) 55 }) 56}) 57 58test('updates the package.json (adds dependencies) with an argument', function (t) { 59 writePackageJson() 60 t.plan(2) 61 62 mr({ port: common.port }, function (er, s) { 63 common.npm(['install', 'underscore', '-P'], OPTS, function (er, code, stdout, stderr) { 64 if (er) throw er 65 t.is(code, 0) 66 s.close() 67 var text = JSON.stringify(fs.readFileSync(pkg + '/package.json', 'utf8')) 68 t.notEqual(text.indexOf('"dependencies'), -1, 'dependencies exist in file') 69 }) 70 }) 71}) 72 73test('cleanup', function (t) { 74 rimraf.sync(pkg) 75 t.end() 76}) 77