1var fs = require('graceful-fs') 2var path = require('path') 3var mkdirp = require('mkdirp') 4var mr = require('npm-registry-mock') 5var rimraf = require('rimraf') 6var test = require('tap').test 7 8var common = require('../common-tap.js') 9 10var testdir = path.join(__dirname, path.basename(__filename, '.js')) 11var pkg = path.resolve(testdir, 'update-symlink') 12var cachedir = path.join(testdir, 'cache') 13var globaldir = path.join(testdir, 'global') 14var OPTS = { 15 env: { 16 'npm_config_cache': cachedir, 17 'npm_config_prefix': globaldir, 18 'npm_config_registry': common.registry 19 }, 20 cwd: pkg 21} 22 23var jsonLocal = { 24 name: 'my-local-package', 25 description: 'fixture', 26 version: '1.0.0', 27 dependencies: { 28 'async': '*', 29 'underscore': '*' 30 } 31} 32 33var server 34test('setup', function (t) { 35 cleanup() 36 mkdirp.sync(cachedir) 37 mkdirp.sync(pkg) 38 fs.writeFileSync( 39 path.join(pkg, 'package.json'), 40 JSON.stringify(jsonLocal, null, 2) 41 ) 42 43 mr({ port: common.port }, thenInstallUnderscore) 44 45 function thenInstallUnderscore (er, s) { 46 server = s 47 common.npm(['install', '-g', 'underscore@1.3.1'], OPTS, thenLink) 48 } 49 50 function thenLink (err, c, out) { 51 t.ifError(err, 'global install did not error') 52 common.npm(['link', 'underscore'], OPTS, thenInstallAsync) 53 } 54 55 function thenInstallAsync (err, c, out) { 56 t.ifError(err, 'link did not error') 57 common.npm(['install', 'async@0.2.9'], OPTS, thenVerify) 58 } 59 60 function thenVerify (err, c, out) { 61 t.ifError(err, 'local install did not error') 62 common.npm(['ls'], OPTS, function (err, c, out, stderr) { 63 t.ifError(err) 64 t.equal(c, 0) 65 t.equal(stderr, '', 'got expected stderr') 66 t.has(out, /async@0.2.9/, 'installed ok') 67 t.has(out, /underscore@1.3.1/, 'creates local link ok') 68 t.end() 69 }) 70 } 71}) 72 73test('when update is called linked packages should be excluded', function (t) { 74 common.npm(['update', '--parseable'], OPTS, function (err, c, out, stderr) { 75 if (err) throw err 76 t.equal(c, 0) 77 t.has(out, /^update\tasync\t0.2.10\t/m, 'updated ok') 78 t.doesNotHave(stderr, /ERR!/, 'no errors in stderr') 79 t.end() 80 }) 81}) 82 83test('when install is called and the package already exists as a link, outputs a warning if the requested version is not the same as the linked one', function (t) { 84 common.npm(['install', 'underscore', '--parseable'], OPTS, function (err, c, out, stderr) { 85 if (err) throw err 86 t.equal(c, 0) 87 88 t.comment(out.trim()) 89 t.comment(stderr.trim()) 90 t.has(out, /^update-linked\tunderscore\t/m) 91 t.has(stderr, /underscore/, 'warning output relating to linked package') 92 t.doesNotHave(stderr, /ERR!/, 'no errors in stderr') 93 t.end() 94 }) 95}) 96 97test('when install is called and the package already exists as a link, does not warn if the requested version is same as the linked one', function (t) { 98 common.npm(['install', 'underscore@1.3.1', '--parseable'], OPTS, function (err, c, out, stderr) { 99 if (err) throw err 100 t.equal(c, 0) 101 t.comment(out.trim()) 102 t.comment(stderr.trim()) 103 t.has(out, /^update-linked\tunderscore\t/m) 104 t.doesNotHave(stderr, /underscore/, 'no warning or error relating to linked package') 105 t.doesNotHave(stderr, /ERR!/, 'no errors in stderr') 106 t.end() 107 }) 108}) 109 110test('cleanup', function (t) { 111 server.close() 112 common.npm(['rm', 'underscore', 'async'], OPTS, function (err, code) { 113 if (err) throw err 114 t.equal(code, 0, 'cleanup in local ok') 115 common.npm(['rm', '-g', 'underscore'], OPTS, function (err, code) { 116 if (err) throw err 117 t.equal(code, 0, 'cleanup in global ok') 118 119 cleanup() 120 t.end() 121 }) 122 }) 123}) 124 125function cleanup () { 126 rimraf.sync(testdir) 127} 128