1var fs = require('graceful-fs') 2var path = require('path') 3 4var mkdirp = require('mkdirp') 5var mr = require('npm-registry-mock') 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-save-exact', 17 version: '0.0.1', 18 description: 'fixture' 19} 20 21test('mock registry', function (t) { 22 mr({ port: common.port }, function (er, s) { 23 t.parent.teardown(() => s.close()) 24 t.end() 25 }) 26}) 27 28const setup = t => { 29 t.test('destroy', t => rimraf(pkg, t.end)) 30 t.test('create', t => { 31 mkdirp.sync(path.resolve(pkg, 'node_modules')) 32 fs.writeFileSync( 33 path.join(pkg, 'package.json'), 34 JSON.stringify(json, null, 2) 35 ) 36 t.end() 37 }) 38 t.end() 39} 40 41const check = (savearg, deptype) => t => { 42 common.npm( 43 [ 44 '--loglevel', 'silent', 45 '--registry', common.registry, 46 savearg, 47 '--save-exact', 48 'install', 'underscore@1.3.1' 49 ], 50 EXEC_OPTS, 51 function (err, code) { 52 t.ifError(err, 'npm ran without issue') 53 t.notOk(code, 'npm install exited without raising an error code') 54 55 var p = path.resolve(pkg, 'node_modules/underscore/package.json') 56 t.ok(JSON.parse(fs.readFileSync(p))) 57 58 p = path.resolve(pkg, 'package.json') 59 var pkgJson = JSON.parse(fs.readFileSync(p, 'utf8')) 60 61 t.same( 62 pkgJson[deptype], 63 { 'underscore': '1.3.1' }, 64 'underscore dependency should specify exactly 1.3.1' 65 ) 66 67 t.end() 68 } 69 ) 70} 71 72test('\'npm install --save --save-exact\' should install local pkg', function (t) { 73 t.test('setup', setup) 74 t.test('check', check('--save', 'dependencies')) 75 t.end() 76}) 77 78test('\'npm install --save-dev --save-exact\' should install local pkg', function (t) { 79 t.test('setup', setup) 80 t.test('check', check('--save-dev', 'devDependencies')) 81 t.end() 82}) 83