1var common = require('../common-tap.js') 2common.skipIfWindows('symlinks are weird on windows') 3var test = require('tap').test 4var path = require('path') 5var fs = require('fs') 6var rimraf = require('rimraf') 7var mkdirp = require('mkdirp') 8 9var root = common.pkg 10var pkg = path.resolve(root, 'pkg') 11var dep = path.resolve(root, 'dep') 12var target = path.resolve(pkg, 'node_modules', 'dep') 13var cache = common.cache 14var globalPath = path.resolve(root, 'global') 15 16var pkgj = { 17 'name': 'pkg', 18 'version': '1.2.3', 19 'dependencies': { 20 'dep': '1.2.3' 21 } 22} 23var depj = { 'name': 'dep', 'version': '1.2.3' } 24 25var myreg = require('http').createServer(function (q, s) { 26 s.statusCode = 403 27 s.end(JSON.stringify({'error': 'forbidden'}) + '\n') 28}).listen(common.port) 29 30test('setup', function (t) { 31 rimraf.sync(root) 32 mkdirp.sync(root) 33 mkdirp.sync(path.resolve(pkg, 'node_modules')) 34 mkdirp.sync(dep) 35 mkdirp.sync(cache) 36 mkdirp.sync(globalPath) 37 fs.writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify(pkgj)) 38 fs.writeFileSync(path.resolve(dep, 'package.json'), JSON.stringify(depj)) 39 fs.symlinkSync(dep, target, 'dir') 40 t.end() 41}) 42 43test('ignore install if package is linked', function (t) { 44 common.npm(['install'], { 45 cwd: pkg, 46 env: { 47 PATH: process.env.PATH || process.env.Path, 48 HOME: process.env.HOME, 49 'npm_config_prefix': globalPath, 50 'npm_config_cache': cache, 51 'npm_config_registry': common.registry, 52 'npm_config_loglevel': 'silent' 53 }, 54 stdio: 'inherit' 55 }, function (er, code) { 56 if (er) throw er 57 t.equal(code, 0, 'npm install exited with code') 58 t.end() 59 }) 60}) 61 62test('still a symlink', function (t) { 63 t.equal(true, fs.lstatSync(target).isSymbolicLink()) 64 t.end() 65}) 66 67test('cleanup', function (t) { 68 rimraf.sync(root) 69 myreg.close() 70 t.end() 71}) 72