1'use strict' 2var path = require('path') 3var fs = require('fs') 4var test = require('tap').test 5var mkdirp = require('mkdirp') 6var common = require('../common-tap.js') 7 8var base = common.pkg 9var installFrom = path.join(base, 'from') 10var installIn = path.join(base, 'in') 11 12var json = { 13 name: 'check-install-self', 14 version: '0.0.1', 15 description: 'fixture' 16} 17 18test('setup', function (t) { 19 setup() 20 t.end() 21}) 22 23var EXEC_OPTS = {cwd: installIn} 24 25test('install self', function (t) { 26 common.npm(['install', installFrom], EXEC_OPTS, function (err, code, stdout, stderr) { 27 if (err) throw err 28 t.comment(stdout.trim()) 29 t.comment(stderr.trim()) 30 t.is(code, 1, 'npm install refused to install a package in itself') 31 t.end() 32 }) 33}) 34test('force install self', function (t) { 35 common.npm(['install', '--force', installFrom], EXEC_OPTS, function (err, code, stdout, stderr) { 36 if (err) throw err 37 t.comment(stdout.trim()) 38 t.comment(stderr.trim()) 39 t.is(code, 0, 'npm install happily installed a package in itself with --force') 40 t.end() 41 }) 42}) 43 44function setup () { 45 mkdirp.sync(path.resolve(installFrom, 'node_modules')) 46 fs.writeFileSync( 47 path.join(installFrom, 'package.json'), 48 JSON.stringify(json, null, 2) 49 ) 50 mkdirp.sync(path.resolve(installIn, 'node_modules')) 51 fs.writeFileSync( 52 path.join(installIn, 'package.json'), 53 JSON.stringify(json, null, 2) 54 ) 55 process.chdir(base) 56} 57