diff options
author | Rebecca Turner <me@re-becca.org> | 2017-04-12 21:47:49 -0700 |
---|---|---|
committer | Jeremiah Senkpiel <fishrock123@rocketmail.com> | 2017-04-25 10:52:01 -0400 |
commit | 00842604483e4c2e622dfdb3a97440e07646158f (patch) | |
tree | f3346902636a44b6037652523767636bf7e4f2c9 /deps/npm/test | |
parent | 061c5da010e0d249379618382a499840d38247b8 (diff) | |
download | android-node-v8-00842604483e4c2e622dfdb3a97440e07646158f.tar.gz android-node-v8-00842604483e4c2e622dfdb3a97440e07646158f.tar.bz2 android-node-v8-00842604483e4c2e622dfdb3a97440e07646158f.zip |
deps: upgrade npm to 4.5.0
PR-URL: https://github.com/nodejs/node/pull/12480
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'deps/npm/test')
-rw-r--r-- | deps/npm/test/broken-under-nyc-and-travis/whoami.js | 2 | ||||
-rw-r--r-- | deps/npm/test/common-tap.js | 6 | ||||
-rw-r--r-- | deps/npm/test/tap/00-verify-no-scoped.js | 30 | ||||
-rw-r--r-- | deps/npm/test/tap/add-remote-git-submodule.js | 7 | ||||
-rw-r--r-- | deps/npm/test/tap/adduser-oauth.js | 85 | ||||
-rw-r--r-- | deps/npm/test/tap/adduser-saml.js | 85 | ||||
-rw-r--r-- | deps/npm/test/tap/anon-cli-metrics.js | 2 | ||||
-rw-r--r-- | deps/npm/test/tap/bundled-transitive-deps.js | 32 | ||||
-rw-r--r-- | deps/npm/test/tap/config-meta.js | 6 | ||||
-rw-r--r-- | deps/npm/test/tap/debug-logs.js | 2 | ||||
-rw-r--r-- | deps/npm/test/tap/extraneous-dep-cycle-ls-ok.js | 3 | ||||
-rw-r--r-- | deps/npm/test/tap/git-races.js | 15 | ||||
-rw-r--r-- | deps/npm/test/tap/install-duplicate-deps-warning.js | 69 | ||||
-rw-r--r-- | deps/npm/test/tap/lifecycle-signal.js | 58 | ||||
-rw-r--r-- | deps/npm/test/tap/peer-deps-toplevel.js | 121 | ||||
-rw-r--r-- | deps/npm/test/tap/search.js | 2 | ||||
-rw-r--r-- | deps/npm/test/tap/unit-deps-childDependencySpecifier.js | 3 | ||||
-rw-r--r-- | deps/npm/test/tap/unit-deps-earliestInstallable.js | 3 | ||||
-rw-r--r-- | deps/npm/test/tap/unit-deps-removeObsoleteDep.js | 3 |
19 files changed, 458 insertions, 76 deletions
diff --git a/deps/npm/test/broken-under-nyc-and-travis/whoami.js b/deps/npm/test/broken-under-nyc-and-travis/whoami.js index 268e0f94fe..a5668b1210 100644 --- a/deps/npm/test/broken-under-nyc-and-travis/whoami.js +++ b/deps/npm/test/broken-under-nyc-and-travis/whoami.js @@ -48,7 +48,7 @@ test('npm whoami with bearer auth', { timeout: 2 * 1000 }, function (t) { t.equal(req.url, '/-/whoami') res.setHeader('content-type', 'application/json') - res.writeHeader(200) + res.writeHead(200) res.end(JSON.stringify({ username: 'wombat' }), 'utf8') } diff --git a/deps/npm/test/common-tap.js b/deps/npm/test/common-tap.js index f96f54ebfb..3a9f9d4d28 100644 --- a/deps/npm/test/common-tap.js +++ b/deps/npm/test/common-tap.js @@ -29,8 +29,6 @@ process.env.npm_config_legacy_bundling = 'false' process.env.random_env_var = 'foo' // suppress warnings about using a prerelease version of node process.env.npm_config_node_version = process.version.replace(/-.*$/, '') -// disable metrics for the test suite even if the user has enabled them -process.env.npm_config_send_metrics = 'false' var bin = exports.bin = require.resolve('../bin/npm-cli.js') @@ -49,6 +47,10 @@ exports.npm = function (cmd, opts, cb) { if (!opts.env.npm_config_cache) { opts.env.npm_config_cache = npm_config_cache } + if (!opts.env.npm_config_send_metrics) { + opts.env.npm_config_send_metrics = 'false' + } + nodeBin = opts.nodeExecPath || nodeBin var stdout = '' diff --git a/deps/npm/test/tap/00-verify-no-scoped.js b/deps/npm/test/tap/00-verify-no-scoped.js new file mode 100644 index 0000000000..4f14dea041 --- /dev/null +++ b/deps/npm/test/tap/00-verify-no-scoped.js @@ -0,0 +1,30 @@ +'use strict' +var common = require('../common-tap') +var test = require('tap').test +var path = require('path') +var cwd = path.resolve(__dirname, '..', '..') +var fs = require('fs') + +/* +We can't include any scoped modules in bundled dependencies due to a bug in +npm@<4.4.3 that made any module that bundled scoped dependencies +uninstallable. While this is fixed, we can't have them in ourselves without +making it impossible to upgrade, thus this test. +*/ + +test('no scoped transitive deps', function (t) { + t.ok(fs.existsSync(cwd), 'ensure that the path we are calling ls within exists') + + var opt = { cwd: cwd, stdio: [ 'ignore', 'pipe', 2 ] } + common.npm(['ls', '--parseable', '--production'], opt, function (err, code, stdout) { + t.ifError(err, 'error should not exist') + t.equal(code, 0, 'npm ls exited with code') + var matchScoped = new RegExp(path.join(cwd, 'node_modules', '.*@').replace(/\\/g, '\\\\')) + stdout.split(/\n/).forEach(function (line) { + if (matchScoped.test(line)) { + t.notLike(line, matchScoped, 'prod deps do not contain scoped modules') + } + }) + t.end() + }) +}) diff --git a/deps/npm/test/tap/add-remote-git-submodule.js b/deps/npm/test/tap/add-remote-git-submodule.js index f4a51b4f6c..86fcaa0ee2 100644 --- a/deps/npm/test/tap/add-remote-git-submodule.js +++ b/deps/npm/test/tap/add-remote-git-submodule.js @@ -69,13 +69,11 @@ test('clean', function (t) { }) function bootstrap (t) { + process.chdir(osenv.tmpdir()) + rimraf.sync(pkg) mkdirp.sync(pkg) process.chdir(pkg) fs.writeFileSync('package.json', pjParent) - t.tearDown(function () { - process.chdir(osenv.tmpdir()) - rimraf.sync(pkg) - }) } function setup (cb) { @@ -142,4 +140,5 @@ function setup (cb) { function cleanup () { process.chdir(osenv.tmpdir()) rimraf.sync(repos) + rimraf.sync(pkg) } diff --git a/deps/npm/test/tap/adduser-oauth.js b/deps/npm/test/tap/adduser-oauth.js new file mode 100644 index 0000000000..dc4ff895e0 --- /dev/null +++ b/deps/npm/test/tap/adduser-oauth.js @@ -0,0 +1,85 @@ +var fs = require('fs') +var path = require('path') +var mkdirp = require('mkdirp') +var rimraf = require('rimraf') +var mr = require('npm-registry-mock') + +var test = require('tap').test +var common = require('../common-tap.js') + +var opts = { cwd: __dirname } +var pkg = path.resolve(__dirname, 'adduser-oauth') +var fakeBrowser = path.resolve(pkg, '_script.sh') +var configfile = path.resolve(pkg, '_npmrc') +var outfile = path.resolve(pkg, '_outfile') +var ssoUri = common.registry + '/-/oauth/foo' + +common.pendIfWindows('This is trickier to convert without opening new shells') + +function mocks (server) { + server.filteringRequestBody(function (r) { + if (r.match(/"_id":"org\.couchdb\.user:npm_oauth_auth_dummy_user"/)) { + return 'auth' + } + }) + server.put('/-/user/org.couchdb.user:npm_oauth_auth_dummy_user', 'auth') + .reply(201, { token: 'foo', sso: ssoUri }) +} + +test('setup', function (t) { + mkdirp.sync(pkg) + fs.writeFileSync(configfile, '') + var s = '#!/usr/bin/env bash\n' + + 'echo \"$@\" > ' + outfile + '\n' + fs.writeFileSync(fakeBrowser, s, 'ascii') + fs.chmodSync(fakeBrowser, '0755') + t.pass('made script') + t.end() +}) + +test('npm login', function (t) { + mr({ port: common.port, plugin: mocks }, function (er, s) { + s.get( + '/-/whoami', { authorization: 'Bearer foo' } + ).max(1).reply(401, {}) + var runner = common.npm( + [ + 'login', + '--registry', common.registry, + '--auth-type=oauth', + '--loglevel', 'silent', + '--userconfig', configfile, + '--browser', fakeBrowser + ], + opts, + function (err, code, stdout, stderr) { + t.ifError(err, 'npm ran without issue') + t.equal(code, 0, 'exited OK') + t.notOk(stderr, 'no error output') + stderr && t.comment('stderr - ', stderr) + t.matches(stdout, /Logged in as igotauthed/, + 'successfully authenticated and output the given username') + s.close() + rimraf.sync(configfile) + rimraf.sync(outfile) + t.end() + } + ) + + var buf = '' + runner.stdout.on('data', function (chunk) { + buf += chunk.toString('utf8') + if (buf.match(/complete authentication/)) { + s.get( + '/-/whoami', { authorization: 'Bearer foo' } + ).reply(200, { username: 'igotauthed' }) + } + }) + }) +}) + +test('cleanup', function (t) { + rimraf.sync(pkg) + t.pass('cleaned up') + t.end() +}) diff --git a/deps/npm/test/tap/adduser-saml.js b/deps/npm/test/tap/adduser-saml.js new file mode 100644 index 0000000000..7fd1da2392 --- /dev/null +++ b/deps/npm/test/tap/adduser-saml.js @@ -0,0 +1,85 @@ +var fs = require('fs') +var path = require('path') +var mkdirp = require('mkdirp') +var rimraf = require('rimraf') +var mr = require('npm-registry-mock') + +var test = require('tap').test +var common = require('../common-tap.js') + +var opts = { cwd: __dirname } +var pkg = path.resolve(__dirname, 'adduser-saml') +var fakeBrowser = path.resolve(pkg, '_script.sh') +var configfile = path.resolve(pkg, '_npmrc') +var outfile = path.resolve(pkg, '_outfile') +var ssoUri = common.registry + '/-/saml/foo' + +common.pendIfWindows('This is trickier to convert without opening new shells') + +function mocks (server) { + server.filteringRequestBody(function (r) { + if (r.match(/"_id":"org\.couchdb\.user:npm_saml_auth_dummy_user"/)) { + return 'auth' + } + }) + server.put('/-/user/org.couchdb.user:npm_saml_auth_dummy_user', 'auth') + .reply(201, { token: 'foo', sso: ssoUri }) +} + +test('setup', function (t) { + mkdirp.sync(pkg) + fs.writeFileSync(configfile, '') + var s = '#!/usr/bin/env bash\n' + + 'echo \"$@\" > ' + outfile + '\n' + fs.writeFileSync(fakeBrowser, s, 'ascii') + fs.chmodSync(fakeBrowser, '0755') + t.pass('made script') + t.end() +}) + +test('npm login', function (t) { + mr({ port: common.port, plugin: mocks }, function (er, s) { + s.get( + '/-/whoami', { authorization: 'Bearer foo' } + ).max(1).reply(401, {}) + var runner = common.npm( + [ + 'login', + '--registry', common.registry, + '--auth-type=saml', + '--loglevel', 'silent', + '--userconfig', configfile, + '--browser', fakeBrowser + ], + opts, + function (err, code, stdout, stderr) { + t.ifError(err, 'npm ran without issue') + t.equal(code, 0, 'exited OK') + t.notOk(stderr, 'no error output') + stderr && t.comment('stderr - ', stderr) + t.matches(stdout, /Logged in as igotauthed/, + 'successfully authenticated and output the given username') + s.close() + rimraf.sync(configfile) + rimraf.sync(outfile) + t.end() + } + ) + + var buf = '' + runner.stdout.on('data', function (chunk) { + buf += chunk.toString('utf8') + if (buf.match(/complete authentication/)) { + s.get( + '/-/whoami', { authorization: 'Bearer foo' } + ).reply(200, { username: 'igotauthed' }) + } + }) + }) +}) + +test('cleanup', function (t) { + rimraf.sync(pkg) + t.pass('cleaned up') + t.end() +}) diff --git a/deps/npm/test/tap/anon-cli-metrics.js b/deps/npm/test/tap/anon-cli-metrics.js index deb6184682..cdabd1dc6d 100644 --- a/deps/npm/test/tap/anon-cli-metrics.js +++ b/deps/npm/test/tap/anon-cli-metrics.js @@ -23,7 +23,7 @@ var conf = { npm_config_tmp: tmpdir, npm_config_prefix: globaldir, npm_config_registry: common.registry, - npm_config_metrics_registry: common.registry, + npm_config_metrics_registry: null, npm_config_loglevel: 'warn' }) } diff --git a/deps/npm/test/tap/bundled-transitive-deps.js b/deps/npm/test/tap/bundled-transitive-deps.js index 4aefe5b9cc..9af12337d6 100644 --- a/deps/npm/test/tap/bundled-transitive-deps.js +++ b/deps/npm/test/tap/bundled-transitive-deps.js @@ -18,10 +18,12 @@ var fixture = new Tacks( name: 'bundled-transitive-deps', version: '1.0.0', dependencies: { - 'a': '1.0.0' + 'a': '1.0.0', + '@c/d': '1.0.0' }, bundleDependencies: [ - 'a' + 'a', + '@c/d' ] }), node_modules: Dir({ @@ -39,6 +41,20 @@ var fixture = new Tacks( name: 'b', version: '1.0.0' }) + }), + '@c/d': Dir({ + 'package.json': File({ + name: '@c/d', + version: '1.0.0' + }), + 'node_modules': Dir({ + 'e': Dir({ + 'package.json': File({ + name: 'e', + version: '1.0.0' + }) + }) + }) }) }) }) @@ -58,6 +74,12 @@ test('setup', function (t) { npm.load({}, t.end) }) +function exists (t, filename) { + t.doesNotThrow(filename + ' exists', function () { + fs.statSync(filename) + }) +} + test('bundled-transitive-deps', function (t) { common.npm(['pack'], {cwd: testdir}, thenCheckPack) function thenCheckPack (err, code, stdout, stderr) { @@ -70,9 +92,9 @@ test('bundled-transitive-deps', function (t) { function thenCheckContents (err) { t.ifError(err, 'unpack successful') var transitivePackedDep = path.join(packed, 'node_modules', 'b') - t.doesNotThrow(transitivePackedDep + ' exists', function () { - fs.statSync(transitivePackedDep) - }) + exists(t, transitivePackedDep) + var nestedScopedDep = path.join(packed, 'node_modules', '@c', 'd', 'node_modules', 'e') + exists(t, nestedScopedDep) t.end() } }) diff --git a/deps/npm/test/tap/config-meta.js b/deps/npm/test/tap/config-meta.js index 3cd1bfa7da..168ab2a2e7 100644 --- a/deps/npm/test/tap/config-meta.js +++ b/deps/npm/test/tap/config-meta.js @@ -106,7 +106,7 @@ test('check configs', function (t) { } for (var c2 in DOC) { - if (c2 !== 'versions' && c2 !== 'version' && c2 !== 'init.version') { + if (c2 !== 'versions' && c2 !== 'version' && c2 !== 'init.version' && c2 !== 'ham-it-up') { t.ok(CONFS[c2], 'config in doc should be used somewhere ' + c2) t.ok(types.indexOf(c2) !== -1, 'should be defined in npmconf ' + c2) t.ok(defaults.indexOf(c2) !== -1, 'should have default in npmconf ' + c2) @@ -114,14 +114,14 @@ test('check configs', function (t) { } types.forEach(function (c) { - if (!c.match(/^\_/) && c !== 'argv' && !c.match(/^versions?$/)) { + if (!c.match(/^\_/) && c !== 'argv' && !c.match(/^versions?$/) && c !== 'ham-it-up') { t.ok(DOC[c], 'defined type should be documented ' + c) t.ok(CONFS[c], 'defined type should be used ' + c) } }) defaults.forEach(function (c) { - if (!c.match(/^\_/) && c !== 'argv' && !c.match(/^versions?$/)) { + if (!c.match(/^\_/) && c !== 'argv' && !c.match(/^versions?$/) && c !== 'ham-it-up') { t.ok(DOC[c], 'defaulted type should be documented ' + c) t.ok(CONFS[c], 'defaulted type should be used ' + c) } diff --git a/deps/npm/test/tap/debug-logs.js b/deps/npm/test/tap/debug-logs.js index fbd244446e..4884512429 100644 --- a/deps/npm/test/tap/debug-logs.js +++ b/deps/npm/test/tap/debug-logs.js @@ -60,7 +60,7 @@ test('example', function (t) { common.npm(['run', 'false'], conf, function (err, code, stdout, stderr) { if (err) throw err t.is(code, 1, 'command errored') - var matches = stderr.match(/Please include the following file with any support request:.*\nnpm ERR! {5,5}(.*)/) + var matches = stderr.match(/A complete log of this run can be found in:.*\nnpm ERR! {5,5}(.*)/) t.ok(matches, 'debug log mentioned in error message') if (matches) { var logfile = matches[1] diff --git a/deps/npm/test/tap/extraneous-dep-cycle-ls-ok.js b/deps/npm/test/tap/extraneous-dep-cycle-ls-ok.js index 767cb6d7ff..d483b3e22a 100644 --- a/deps/npm/test/tap/extraneous-dep-cycle-ls-ok.js +++ b/deps/npm/test/tap/extraneous-dep-cycle-ls-ok.js @@ -54,7 +54,8 @@ test('setup', function (t) { var expected = pkg + '\n' + '└─┬ moduleA@1.0.0\n' + - ' └── moduleB@1.0.0\n\n' + ' └─┬ moduleB@1.0.0\n' + + ' └── moduleA@1.0.0 deduped\n\n' test('extraneous-dep-cycle', function (t) { common.npm(['ls', '--unicode=true'], {cwd: pkg}, function (er, code, stdout, stderr) { diff --git a/deps/npm/test/tap/git-races.js b/deps/npm/test/tap/git-races.js index f275455cd0..c6c27d5040 100644 --- a/deps/npm/test/tap/git-races.js +++ b/deps/npm/test/tap/git-races.js @@ -162,7 +162,8 @@ function setup (cb) { var oneTree = [ 'npm-git-test@1.0.0', [ ['dummy-npm-bar@4.0.0', [ - ['dummy-npm-foo@3.0.0', []] + ['dummy-npm-foo@3.0.0', []], + ['dummy-npm-buzz@3.0.0', []] ]], ['dummy-npm-buzz@3.0.0', []], ['dummy-npm-foo@4.0.0', [ @@ -199,17 +200,19 @@ test('setup', function (t) { }) test('correct versions are installed for git dependency', function (t) { - t.plan(3) t.comment('test for https://github.com/npm/npm/issues/7202') npm.commands.install([], function (er) { t.ifError(er, 'installed OK') npm.commands.ls([], true, function (er, result) { t.ifError(er, 'ls OK') var simplified = toSimple(result) - t.ok( - deepEqual(simplified, oneTree) || deepEqual(simplified, otherTree), - 'install tree is correct' - ) + if (deepEqual(simplified, oneTree) || deepEqual(simplified, otherTree)) { + t.pass('install tree is correct') + } else { + t.isDeeply(simplified, oneTree, 'oneTree matches') + t.isDeeply(simplified, otherTree, 'otherTree matches') + } + t.done() }) }) }) diff --git a/deps/npm/test/tap/install-duplicate-deps-warning.js b/deps/npm/test/tap/install-duplicate-deps-warning.js new file mode 100644 index 0000000000..9206fe253c --- /dev/null +++ b/deps/npm/test/tap/install-duplicate-deps-warning.js @@ -0,0 +1,69 @@ +var fs = require('graceful-fs') +var path = require('path') + +var mkdirp = require('mkdirp') +var mr = require('npm-registry-mock') +var osenv = require('osenv') +var rimraf = require('rimraf') +var test = require('tap').test + +var common = require('../common-tap.js') +var npm = npm = require('../../') + +var pkg = path.resolve(__dirname, path.basename(__filename, '.js')) + +var json = { + dependencies: { + underscore: '1.5.1' + }, + devDependencies: { + underscore: '1.3.1' + } +} + +test('setup', function (t) { + t.comment('test for https://github.com/npm/npm/issues/6725') + cleanup() + mkdirp.sync(pkg) + fs.writeFileSync( + path.join(pkg, 'package.json'), + JSON.stringify(json, null, 2) + ) + process.chdir(pkg) + console.dir(pkg) + t.end() +}) + +test('npm install with duplicate dependencies, different versions', function (t) { + t.plan(1) + mr({ port: common.port }, function (er, s) { + var opts = { + cache: path.resolve(pkg, 'cache'), + registry: common.registry + } + + npm.load(opts, function (err) { + if (err) return t.fail(err) + + npm.install('.', function (err, additions, result) { + if (err) return t.fail(err) + + var invalid = result.warnings.filter(function (warning) { return warning.code === 'EDUPLICATEDEP' }) + t.is(invalid.length, 1, 'got a warning (EDUPLICATEDEP) for duplicate dev/production dependencies') + + s.close() + t.end() + }) + }) + }) +}) + +test('cleanup', function (t) { + cleanup() + t.end() +}) + +function cleanup () { + process.chdir(osenv.tmpdir()) + rimraf.sync(pkg) +} diff --git a/deps/npm/test/tap/lifecycle-signal.js b/deps/npm/test/tap/lifecycle-signal.js index 68fe9db2d6..065e5a830a 100644 --- a/deps/npm/test/tap/lifecycle-signal.js +++ b/deps/npm/test/tap/lifecycle-signal.js @@ -12,12 +12,21 @@ var npm = require.resolve('../../bin/npm-cli.js') var pkg = path.resolve(__dirname, 'lifecycle-signal') +var asyncScript = 'console.error(process.pid);process.on(\'SIGINT\',function (){' +asyncScript += 'setTimeout(function(){console.error(process.pid);process.exit()},10)' +asyncScript += '});setInterval(function(){},10);' + +var zombieScript = 'console.error(process.pid);process.on(\'SIGINT\',function (){' +zombieScript += '});setInterval(function(){console.error(process.pid)},10);' + var json = { name: 'lifecycle-signal', version: '1.2.5', scripts: { preinstall: 'node -e "process.kill(process.pid,\'SIGSEGV\')"', - forever: 'node -e "console.error(process.pid);setInterval(function(){},1000)"' + forever: 'node -e "console.error(process.pid);setInterval(function(){},1000)"', + async: 'node -e "' + asyncScript + '"', + zombie: 'node -e "' + zombieScript + '"' } } @@ -72,6 +81,53 @@ test('lifecycle propagate signal term to child', function (t) { }) }) +test('lifecycle wait for async child process exit', function (t) { + // windows does not use lifecycle signals, abort + if (process.platform === 'win32' || process.env.TRAVIS) return t.end() + + var innerChildPid + var interupted + var child = spawn(npm, ['run', 'async'], { + cwd: pkg + }) + child.stderr.on('data', function (data) { + if (!interupted) { + interupted = true + child.kill('SIGINT') + } else { + innerChildPid = parseInt(data.toString(), 10) + } + }) + child.on('exit', function (code, signal) { + t.ok(innerChildPid) + t.end() + }) +}) + +test('lifecycle force kill using multiple SIGINT signals', function (t) { + // windows does not use lifecycle signals, abort + if (process.platform === 'win32' || process.env.TRAVIS) return t.end() + + var innerChildPid + var interupted + var child = spawn(npm, ['run', 'zombie'], { + cwd: pkg + }) + child.stderr.on('data', function (data) { + if (!interupted) { + interupted = true + child.kill('SIGINT') + } else { + innerChildPid = parseInt(data.toString(), 10) + child.kill('SIGINT') + } + }) + child.on('exit', function (code, signal) { + t.ok(innerChildPid) + t.end() + }) +}) + test('cleanup', function (t) { cleanup() t.end() diff --git a/deps/npm/test/tap/peer-deps-toplevel.js b/deps/npm/test/tap/peer-deps-toplevel.js index 1c95867301..a4384a7a55 100644 --- a/deps/npm/test/tap/peer-deps-toplevel.js +++ b/deps/npm/test/tap/peer-deps-toplevel.js @@ -1,16 +1,29 @@ -var fs = require('graceful-fs') +'use strict' var path = require('path') - -var mkdirp = require('mkdirp') -var mr = require('npm-registry-mock') -var osenv = require('osenv') -var rimraf = require('rimraf') var test = require('tap').test - +var mr = require('npm-registry-mock') +var Tacks = require('tacks') +var File = Tacks.File +var Dir = Tacks.Dir +var extend = Object.assign || require('util')._extend var common = require('../common-tap.js') -var npm = npm = require('../../') -var pkg = path.resolve(__dirname, 'peer-deps-toplevel') +var basedir = path.join(__dirname, path.basename(__filename, '.js')) +var testdir = path.join(basedir, 'testdir') +var cachedir = path.join(basedir, 'cache') +var globaldir = path.join(basedir, 'global') +var tmpdir = path.join(basedir, 'tmp') + +var conf = { + cwd: testdir, + env: extend(extend({}, process.env), { + npm_config_cache: cachedir, + npm_config_tmp: tmpdir, + npm_config_prefix: globaldir, + npm_config_registry: common.registry, + npm_config_loglevel: 'warn' + }) +} var expected = { name: 'npm-test-peer-deps-toplevel', @@ -59,57 +72,65 @@ var expected = { } } -var json = { - author: 'Domenic Denicola', - name: 'npm-test-peer-deps-toplevel', - version: '0.0.0', - dependencies: { - 'npm-test-peer-deps': '*' - }, - peerDependencies: { - mkdirp: '*' - } +var server +var fixture = new Tacks(Dir({ + cache: Dir(), + global: Dir(), + tmp: Dir(), + testdir: Dir({ + 'package.json': File({ + name: 'npm-test-peer-deps-toplevel', + version: '0.0.0', + dependencies: { + 'npm-test-peer-deps': '*' + }, + peerDependencies: { + mkdirp: '*' + } + }) + }) +})) + +function setup () { + cleanup() + fixture.create(basedir) } -test('installs the peer dependency directory structure', function (t) { - mr({ port: common.port }, function (er, s) { - setup(function (err) { - t.ifError(err, 'setup ran successfully') +function cleanup () { + fixture.remove(basedir) +} - npm.install('.', function (err) { - t.ifError(err, 'packages were installed') +test('setup', function (t) { + setup() + mr({port: common.port, throwOnUnmatched: true}, function (err, s) { + if (err) throw err + server = s + t.done() + }) +}) - npm.commands.ls([], true, function (err, _, results) { - t.ifError(err, 'listed tree without problems') +test('installs the peer dependency directory structure', function (t) { + common.npm(['install'], conf, function (err, code, stdout, stderr) { + if (err) throw err + t.is(code, 0, 'install ran ok even w/ missing peeer deps') + t.comment(stdout.trim()) + t.comment(stderr.trim()) - t.deepEqual(results, expected, 'got expected output from ls') - s.close() - t.end() - }) - }) + common.npm(['ls', '--json'], conf, function (err, code, stdout, stderr) { + if (err) throw err + t.is(code, 1, 'missing peer deps _are_ an ls error though') + t.comment(stderr.trim()) + var results = JSON.parse(stdout) + + t.deepEqual(results, expected, 'got expected output from ls') + t.done() }) }) }) test('cleanup', function (t) { + server.close() cleanup() - t.end() + t.done() }) -function setup (cb) { - cleanup() - mkdirp.sync(pkg) - fs.writeFileSync( - path.join(pkg, 'package.json'), - JSON.stringify(json, null, 2) - ) - process.chdir(pkg) - - var opts = { cache: path.resolve(pkg, 'cache'), registry: common.registry } - npm.load(opts, cb) -} - -function cleanup () { - process.chdir(osenv.tmpdir()) - rimraf.sync(pkg) -} diff --git a/deps/npm/test/tap/search.js b/deps/npm/test/tap/search.js index 78436e1e29..f389670a42 100644 --- a/deps/npm/test/tap/search.js +++ b/deps/npm/test/tap/search.js @@ -130,7 +130,7 @@ test('can switch to tab separated mode', function (t) { '--cache', CACHE_DIR ], {}, function (err, code, stdout, stderr) { if (err) throw err - t.equal(stdout, 'cool\t\t\tprehistoric\t\t\nfoo\tthis has tabs\t\tprehistoric\t\t\n', 'correct output, including replacing tabs in descriptions') + t.equal(stdout, 'cool\t\t\tprehistoric\t1.0.0\t\nfoo\tthis has tabs\t\tprehistoric\t2.0.0\t\n', 'correct output, including replacing tabs in descriptions') t.equal(stderr, '', 'no error output') t.equal(code, 0, 'search gives 0 error code even if no matches') t.done() diff --git a/deps/npm/test/tap/unit-deps-childDependencySpecifier.js b/deps/npm/test/tap/unit-deps-childDependencySpecifier.js index 600b719fb2..68f9ea6bea 100644 --- a/deps/npm/test/tap/unit-deps-childDependencySpecifier.js +++ b/deps/npm/test/tap/unit-deps-childDependencySpecifier.js @@ -8,6 +8,9 @@ var deps = requireInject('../../lib/install/deps.js', { '../../lib/npm.js': { config: { get: function () { return 'mock' } + }, + limit: { + fetch: 10 } } }) diff --git a/deps/npm/test/tap/unit-deps-earliestInstallable.js b/deps/npm/test/tap/unit-deps-earliestInstallable.js index 26a251addc..5b69d20142 100644 --- a/deps/npm/test/tap/unit-deps-earliestInstallable.js +++ b/deps/npm/test/tap/unit-deps-earliestInstallable.js @@ -7,6 +7,9 @@ var deps = requireInject('../../lib/install/deps.js', { '../../lib/npm.js': { config: { get: function (val) { return (val === 'global-style' || val === 'legacy-bundling') ? false : 'mock' } + }, + limit: { + fetch: 10 } } }) diff --git a/deps/npm/test/tap/unit-deps-removeObsoleteDep.js b/deps/npm/test/tap/unit-deps-removeObsoleteDep.js index 8bba0d0da1..3612818e84 100644 --- a/deps/npm/test/tap/unit-deps-removeObsoleteDep.js +++ b/deps/npm/test/tap/unit-deps-removeObsoleteDep.js @@ -7,6 +7,9 @@ var deps = requireInject('../../lib/install/deps.js', { '../../lib/npm.js': { config: { get: function () { return 'mock' } + }, + limit: { + fetch: 10 } } }) |