diff options
Diffstat (limited to 'deps/npm/test/tap/update-symlink.js')
-rw-r--r-- | deps/npm/test/tap/update-symlink.js | 118 |
1 files changed, 77 insertions, 41 deletions
diff --git a/deps/npm/test/tap/update-symlink.js b/deps/npm/test/tap/update-symlink.js index 1447fde628..1fb07b8a75 100644 --- a/deps/npm/test/tap/update-symlink.js +++ b/deps/npm/test/tap/update-symlink.js @@ -1,6 +1,5 @@ var fs = require('graceful-fs') var path = require('path') -var osenv = require('osenv') var mkdirp = require('mkdirp') var mr = require('npm-registry-mock') var rimraf = require('rimraf') @@ -8,14 +7,17 @@ var test = require('tap').test var common = require('../common-tap.js') -var pkg = path.resolve(__dirname, 'update-symlink') -var originalLog - -var fakeRoot = path.join(__dirname, 'fakeRoot') +var testdir = path.join(__dirname, path.basename(__filename, '.js')) +var pkg = path.resolve(testdir, 'update-symlink') +var cachedir = path.join(testdir, 'cache') +var globaldir = path.join(testdir, 'global') var OPTS = { env: { - 'npm_config_prefix': fakeRoot - } + 'npm_config_cache': cachedir, + 'npm_config_prefix': globaldir, + 'npm_config_registry': common.registry + }, + cwd: pkg } var jsonLocal = { @@ -28,57 +30,92 @@ var jsonLocal = { } } +var server test('setup', function (t) { cleanup() - originalLog = console.log + mkdirp.sync(cachedir) mkdirp.sync(pkg) - common.npm(['install', '-g', 'underscore@1.3.1'], OPTS, function (err, c, out) { + fs.writeFileSync( + path.join(pkg, 'package.json'), + JSON.stringify(jsonLocal, null, 2) + ) + + mr({ port: common.port }, thenInstallUnderscore) + + function thenInstallUnderscore (er, s) { + server = s + common.npm(['install', '-g', 'underscore@1.3.1'], OPTS, thenLink) + } + + function thenLink (err, c, out) { t.ifError(err, 'global install did not error') - process.chdir(pkg) - fs.writeFileSync( - path.join(pkg, 'package.json'), - JSON.stringify(jsonLocal, null, 2) - ) - common.npm(['link', 'underscore'], OPTS, function (err, c, out) { - t.ifError(err, 'link did not error') - common.npm(['install', 'async@0.2.9'], OPTS, function (err, c, out) { - t.ifError(err, 'local install did not error') - common.npm(['ls'], OPTS, function (err, c, out, stderr) { - t.ifError(err) - t.equal(c, 0) - t.equal(stderr, '', 'got expected stderr') - t.has(out, /async@0.2.9/, 'installed ok') - t.has(out, /underscore@1.3.1/, 'creates local link ok') - t.end() - }) - }) - }) - }) -}) + common.npm(['link', 'underscore'], OPTS, thenInstallAsync) + } -test('when update is called linked packages should be excluded', function (t) { - console.log = function () {} - mr({ port: common.port }, function (er, s) { - common.npm(['update'], OPTS, function (err, c, out, stderr) { + function thenInstallAsync (err, c, out) { + t.ifError(err, 'link did not error') + common.npm(['install', 'async@0.2.9'], OPTS, thenVerify) + } + + function thenVerify (err, c, out) { + t.ifError(err, 'local install did not error') + common.npm(['ls'], OPTS, function (err, c, out, stderr) { t.ifError(err) - t.has(out, /async@1.5.2/, 'updated ok') - t.doesNotHave(stderr, /ERR!/, 'no errors in stderr') - s.close() + t.equal(c, 0) + t.equal(stderr, '', 'got expected stderr') + t.has(out, /async@0.2.9/, 'installed ok') + t.has(out, /underscore@1.3.1/, 'creates local link ok') t.end() }) + } +}) + +test('when update is called linked packages should be excluded', function (t) { + common.npm(['update'], OPTS, function (err, c, out, stderr) { + t.ifError(err) + t.equal(c, 0) + t.has(out, /async@0.2.10/, 'updated ok') + t.doesNotHave(stderr, /ERR!/, 'no errors in stderr') + t.end() + }) +}) + +test('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) { + common.npm(['install', 'underscore'], OPTS, function (err, c, out, stderr) { + t.ifError(err) + t.equal(c, 0) + + t.comment(out.trim()) + t.comment(stderr.trim()) + t.doesNotHave(out, /underscore/, 'linked package not updated') + t.has(stderr, /underscore/, 'warning output relating to linked package') + t.doesNotHave(stderr, /ERR!/, 'no errors in stderr') + t.end() + }) +}) + +test('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) { + common.npm(['install', 'underscore@1.3.1'], OPTS, function (err, c, out, stderr) { + t.ifError(err) + t.equal(c, 0) + t.comment(out.trim()) + t.comment(stderr.trim()) + t.doesNotHave(out, /underscore/, 'linked package not updated') + t.doesNotHave(stderr, /underscore/, 'no warning or error relating to linked package') + t.doesNotHave(stderr, /ERR!/, 'no errors in stderr') + t.end() }) }) test('cleanup', function (t) { + server.close() common.npm(['rm', 'underscore', 'async'], OPTS, function (err, code) { t.ifError(err, 'npm removed the linked package without error') t.equal(code, 0, 'cleanup in local ok') - process.chdir(osenv.tmpdir()) common.npm(['rm', '-g', 'underscore'], OPTS, function (err, code) { t.ifError(err, 'npm removed the global package without error') t.equal(code, 0, 'cleanup in global ok') - console.log = originalLog cleanup() t.end() }) @@ -86,6 +123,5 @@ test('cleanup', function (t) { }) function cleanup () { - rimraf.sync(pkg) - rimraf.sync(fakeRoot) + rimraf.sync(testdir) } |