|
| 1 | +var fs = require('graceful-fs') |
| 2 | +var path = require('path') |
| 3 | +var osenv = require('osenv') |
| 4 | +var mkdirp = require('mkdirp') |
| 5 | +var mr = require('npm-registry-mock') |
| 6 | +var rimraf = require('rimraf') |
| 7 | +var test = require('tap').test |
| 8 | + |
| 9 | +var common = require('../common-tap.js') |
| 10 | + |
| 11 | +var pkg = path.resolve(__dirname, 'update-symlink') |
| 12 | +var originalLog |
| 13 | + |
| 14 | +var fakeRoot = path.join(__dirname, 'fakeRoot') |
| 15 | +var OPTS = { |
| 16 | + env: { |
| 17 | + 'npm_config_prefix': fakeRoot |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +var jsonLocal = { |
| 22 | + name: 'my-local-package', |
| 23 | + description: 'fixture', |
| 24 | + version: '1.0.0', |
| 25 | + dependencies: { |
| 26 | + 'async': '*', |
| 27 | + 'underscore': '*' |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +test('setup', function (t) { |
| 32 | + cleanup() |
| 33 | + originalLog = console.log |
| 34 | + mkdirp.sync(pkg) |
| 35 | + common.npm(['install', '-g', '[email protected]'], OPTS, function (err, c, out) { |
| 36 | + t.ifError(err, 'global install did not error') |
| 37 | + process.chdir(pkg) |
| 38 | + fs.writeFileSync( |
| 39 | + path.join(pkg, 'package.json'), |
| 40 | + JSON.stringify(jsonLocal, null, 2) |
| 41 | + ) |
| 42 | + common.npm(['link', 'underscore'], OPTS, function (err, c, out) { |
| 43 | + t.ifError(err, 'link did not error') |
| 44 | + common.npm(['install', '[email protected]'], OPTS, function (err, c, out) { |
| 45 | + t.ifError(err, 'local install did not error') |
| 46 | + common.npm(['ls'], OPTS, function (err, c, out, stderr) { |
| 47 | + t.ifError(err) |
| 48 | + t.equal(c, 0) |
| 49 | + t.equal(stderr, '', 'got expected stderr') |
| 50 | + t.has(out, /async@0.2.9/, 'installed ok') |
| 51 | + t.has(out, /underscore@1.3.1/, 'creates local link ok') |
| 52 | + t.end() |
| 53 | + }) |
| 54 | + }) |
| 55 | + }) |
| 56 | + }) |
| 57 | +}) |
| 58 | + |
| 59 | +test('when update is called linked packages should be excluded', function (t) { |
| 60 | + console.log = function () {} |
| 61 | + mr({ port: common.port }, function (er, s) { |
| 62 | + common.npm(['update'], OPTS, function (err, c, out, stderr) { |
| 63 | + t.ifError(err) |
| 64 | + t.has(out, /async@1.5.2/, 'updated ok') |
| 65 | + t.doesNotHave(stderr, /ERR!/, 'no errors in stderr') |
| 66 | + s.close() |
| 67 | + t.end() |
| 68 | + }) |
| 69 | + }) |
| 70 | +}) |
| 71 | + |
| 72 | +test('cleanup', function (t) { |
| 73 | + common.npm(['rm', 'underscore', 'async'], OPTS, function (err, code) { |
| 74 | + t.ifError(err, 'npm removed the linked package without error') |
| 75 | + t.equal(code, 0, 'cleanup in local ok') |
| 76 | + process.chdir(osenv.tmpdir()) |
| 77 | + common.npm(['rm', '-g', 'underscore'], OPTS, function (err, code) { |
| 78 | + t.ifError(err, 'npm removed the global package without error') |
| 79 | + t.equal(code, 0, 'cleanup in global ok') |
| 80 | + |
| 81 | + console.log = originalLog |
| 82 | + cleanup() |
| 83 | + t.end() |
| 84 | + }) |
| 85 | + }) |
| 86 | +}) |
| 87 | + |
| 88 | +function cleanup () { |
| 89 | + rimraf.sync(pkg) |
| 90 | + rimraf.sync(fakeRoot) |
| 91 | +} |
0 commit comments