diff options
author | Rebecca Turner <me@re-becca.org> | 2015-05-22 03:14:39 -0400 |
---|---|---|
committer | Jeremiah Senkpiel <fishrock123@rocketmail.com> | 2015-05-23 19:48:00 -0400 |
commit | c54d05759811608c6158211f790b4cf0706831c1 (patch) | |
tree | dcdfe2dde7dce2505da008913739d48aa006a5c1 /deps/npm/test | |
parent | 367ffd167d5919eabd843798157355c02c5f3a41 (diff) | |
download | android-node-v8-c54d05759811608c6158211f790b4cf0706831c1.tar.gz android-node-v8-c54d05759811608c6158211f790b4cf0706831c1.tar.bz2 android-node-v8-c54d05759811608c6158211f790b4cf0706831c1.zip |
deps: upgrade to npm 2.10.1
PR-URL: https://github.com/nodejs/io.js/pull/1763
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'deps/npm/test')
41 files changed, 980 insertions, 576 deletions
diff --git a/deps/npm/test/fixtures/config/userconfig-with-gc b/deps/npm/test/fixtures/config/userconfig-with-gc index 7268fcb3c6..824d492bce 100644 --- a/deps/npm/test/fixtures/config/userconfig-with-gc +++ b/deps/npm/test/fixtures/config/userconfig-with-gc @@ -1,4 +1,4 @@ -globalconfig=/Users/ogd/Documents/projects/npm/npm/test/fixtures/config/globalconfig +globalconfig=/Users/rebecca/code/npm-release/test/fixtures/config/globalconfig email=i@izs.me env-thing=asdf init.author.name=Isaac Z. Schlueter diff --git a/deps/npm/test/fixtures/github-com-BryanDonovan-dummy-npm-bar.git.tar.gz b/deps/npm/test/fixtures/github-com-BryanDonovan-dummy-npm-bar.git.tar.gz Binary files differnew file mode 100644 index 0000000000..fb27e17f48 --- /dev/null +++ b/deps/npm/test/fixtures/github-com-BryanDonovan-dummy-npm-bar.git.tar.gz diff --git a/deps/npm/test/fixtures/github-com-BryanDonovan-dummy-npm-buzz.git.tar.gz b/deps/npm/test/fixtures/github-com-BryanDonovan-dummy-npm-buzz.git.tar.gz Binary files differnew file mode 100644 index 0000000000..0ea851fbec --- /dev/null +++ b/deps/npm/test/fixtures/github-com-BryanDonovan-dummy-npm-buzz.git.tar.gz diff --git a/deps/npm/test/fixtures/github-com-BryanDonovan-dummy-npm-foo.git.tar.gz b/deps/npm/test/fixtures/github-com-BryanDonovan-dummy-npm-foo.git.tar.gz Binary files differnew file mode 100644 index 0000000000..8e1abc6d05 --- /dev/null +++ b/deps/npm/test/fixtures/github-com-BryanDonovan-dummy-npm-foo.git.tar.gz diff --git a/deps/npm/test/fixtures/github-com-BryanDonovan-npm-git-test.git.tar.gz b/deps/npm/test/fixtures/github-com-BryanDonovan-npm-git-test.git.tar.gz Binary files differnew file mode 100644 index 0000000000..7a4b9e8131 --- /dev/null +++ b/deps/npm/test/fixtures/github-com-BryanDonovan-npm-git-test.git.tar.gz diff --git a/deps/npm/test/tap/404-private-registry-scoped.js b/deps/npm/test/tap/404-private-registry-scoped.js new file mode 100644 index 0000000000..681fff05e8 --- /dev/null +++ b/deps/npm/test/tap/404-private-registry-scoped.js @@ -0,0 +1,22 @@ +var nock = require('nock') +var test = require('tap').test +var npm = require('../../') +var addNamed = require('../../lib/cache/add-named') + +test('scoped package names not mangled on error with non-root registry', function test404 (t) { + nock('http://localhost:1337') + .get('/registry/@scope%2ffoo') + .reply(404, { + error: 'not_found', + reason: 'document not found' + }) + + npm.load({registry: 'http://localhost:1337/registry', global: true}, function () { + addNamed('@scope/foo', '*', null, function checkError (err) { + t.ok(err, 'should error') + t.equal(err.message, '404 Not Found: @scope/foo', 'should have package name in error') + t.equal(err.pkgid, '@scope/foo', 'err.pkgid should match package name') + t.end() + }) + }) +}) diff --git a/deps/npm/test/tap/404-private-registry.js b/deps/npm/test/tap/404-private-registry.js new file mode 100644 index 0000000000..9e05f483eb --- /dev/null +++ b/deps/npm/test/tap/404-private-registry.js @@ -0,0 +1,22 @@ +var nock = require('nock') +var test = require('tap').test +var npm = require('../../') +var addNamed = require('../../lib/cache/add-named') + +test('package names not mangled on error with non-root registry', function test404 (t) { + nock('http://localhost:1337') + .get('/registry/foo') + .reply(404, { + error: 'not_found', + reason: 'document not found' + }) + + npm.load({registry: 'http://localhost:1337/registry', global: true}, function () { + addNamed('foo', '*', null, function checkError (err) { + t.ok(err, 'should error') + t.equal(err.message, '404 Not Found: foo', 'should have package name in error') + t.equal(err.pkgid, 'foo', 'err.pkgid should match package name') + t.end() + }) + }) +}) diff --git a/deps/npm/test/tap/access.js b/deps/npm/test/tap/access.js index aa97b1a203..5ac1d61384 100644 --- a/deps/npm/test/tap/access.js +++ b/deps/npm/test/tap/access.js @@ -83,6 +83,102 @@ test("npm access on named package", function (t) { ) }) +test("npm change access on unscoped package", function (t) { + common.npm( + [ + "access", + "restricted", "yargs", + "--registry", common.registry + ], + { cwd : pkg }, + function (er, code, stdout, stderr) { + t.ok(code, 'exited with Error') + t.ok(stderr.match(/you can't change the access level of unscoped packages/)) + t.end() + } + ) +}) + +test('npm access add', function (t) { + common.npm( + [ + "access", + "add", "@scoped/another", + "--registry", common.registry + ], + { cwd : pkg }, + function (er, code, stdout, stderr) { + t.ok(code, 'exited with Error') + t.ok(stderr.match(/npm access add isn't implemented yet!/)) + t.end() + } + ) +}) + +test('npm access rm', function (t) { + common.npm( + [ + "access", + "rm", "@scoped/another", + "--registry", common.registry + ], + { cwd : pkg }, + function (er, code, stdout, stderr) { + t.ok(code, 'exited with Error') + t.ok(stderr.match(/npm access rm isn't implemented yet!/)) + t.end() + } + ) +}) + +test('npm access ls', function (t) { + common.npm( + [ + "access", + "ls", "@scoped/another", + "--registry", common.registry + ], + { cwd : pkg }, + function (er, code, stdout, stderr) { + t.ok(code, 'exited with Error') + t.ok(stderr.match(/npm access ls isn't implemented yet!/)) + t.end() + } + ) +}) + +test('npm access edit', function (t) { + common.npm( + [ + "access", + "edit", "@scoped/another", + "--registry", common.registry + ], + { cwd : pkg }, + function (er, code, stdout, stderr) { + t.ok(code, 'exited with Error') + t.ok(stderr.match(/npm access edit isn't implemented yet!/)) + t.end() + } + ) +}) + +test('npm access blerg', function (t) { + common.npm( + [ + "access", + "blerg", "@scoped/another", + "--registry", common.registry + ], + { cwd : pkg }, + function (er, code, stdout, stderr) { + t.ok(code, 'exited with Error') + t.ok(stderr.match(/Usage:/)) + t.end() + } + ) +}) + test("cleanup", function (t) { t.pass("cleaned up") rimraf.sync(pkg) diff --git a/deps/npm/test/tap/add-remote-git-fake-windows.js b/deps/npm/test/tap/add-remote-git-fake-windows.js index 0e0d539fb0..c9c9dd446b 100644 --- a/deps/npm/test/tap/add-remote-git-fake-windows.js +++ b/deps/npm/test/tap/add-remote-git-fake-windows.js @@ -16,6 +16,20 @@ var daemon var daemonPID var git +var pjParent = JSON.stringify({ + name: 'parent', + version: '1.2.3', + dependencies: { + child: 'git://localhost:1233/child.git' + } +}, null, 2) + '\n' + +var pjChild = JSON.stringify({ + name: 'child', + version: '1.0.3' +}, null, 2) + '\n' + + test('setup', function (t) { bootstrap() setup(function (er, r) { @@ -53,19 +67,6 @@ test('clean', function (t) { process.kill(daemonPID) }) -var pjParent = JSON.stringify({ - name: 'parent', - version: '1.2.3', - dependencies: { - child: 'git://localhost:1233/child.git' - } -}, null, 2) + '\n' - -var pjChild = JSON.stringify({ - name: 'child', - version: '1.0.3' -}, null, 2) + '\n' - function bootstrap () { rimraf.sync(pkg) mkdirp.sync(pkg) diff --git a/deps/npm/test/tap/add-remote-git-file.js b/deps/npm/test/tap/add-remote-git-file.js index b2a7be9039..673be4c285 100644 --- a/deps/npm/test/tap/add-remote-git-file.js +++ b/deps/npm/test/tap/add-remote-git-file.js @@ -16,6 +16,11 @@ var repo = resolve(__dirname, 'add-remote-git-file-repo') var git var cloneURL = 'git+file://' + resolve(pkg, 'child.git') +var pjChild = JSON.stringify({ + name: 'child', + version: '1.0.3' +}, null, 2) + '\n' + test('setup', function (t) { bootstrap() setup(function (er, r) { @@ -45,11 +50,6 @@ test('clean', function (t) { t.end() }) -var pjChild = JSON.stringify({ - name: 'child', - version: '1.0.3' -}, null, 2) + '\n' - function bootstrap () { cleanup() mkdirp.sync(pkg) diff --git a/deps/npm/test/tap/add-remote-git-shrinkwrap.js b/deps/npm/test/tap/add-remote-git-shrinkwrap.js index 94951e9a9d..f2982355e1 100644 --- a/deps/npm/test/tap/add-remote-git-shrinkwrap.js +++ b/deps/npm/test/tap/add-remote-git-shrinkwrap.js @@ -16,6 +16,19 @@ var daemon var daemonPID var git +var pjParent = JSON.stringify({ + name: 'parent', + version: '1.2.3', + dependencies: { + 'child': 'git://localhost:1235/child.git#master' + } +}, null, 2) + '\n' + +var pjChild = JSON.stringify({ + name: 'child', + version: '1.0.3' +}, null, 2) + '\n' + test('setup', function (t) { bootstrap() setup(function (er, r) { @@ -88,19 +101,6 @@ test('clean', function (t) { process.kill(daemonPID) }) -var pjParent = JSON.stringify({ - name: 'parent', - version: '1.2.3', - dependencies: { - 'child': 'git://localhost:1235/child.git#master' - } -}, null, 2) + '\n' - -var pjChild = JSON.stringify({ - name: 'child', - version: '1.0.3' -}, null, 2) + '\n' - function bootstrap () { mkdirp.sync(pkg) fs.writeFileSync(resolve(pkg, 'package.json'), pjParent) diff --git a/deps/npm/test/tap/add-remote-git.js b/deps/npm/test/tap/add-remote-git.js index 269d0cac7d..e33d09c1a1 100644 --- a/deps/npm/test/tap/add-remote-git.js +++ b/deps/npm/test/tap/add-remote-git.js @@ -16,6 +16,19 @@ var daemon var daemonPID var git +var pjParent = JSON.stringify({ + name: 'parent', + version: '1.2.3', + dependencies: { + child: 'git://localhost:1234/child.git' + } +}, null, 2) + '\n' + +var pjChild = JSON.stringify({ + name: 'child', + version: '1.0.3' +}, null, 2) + '\n' + test('setup', function (t) { bootstrap() setup(function (er, r) { @@ -47,19 +60,6 @@ test('clean', function (t) { process.kill(daemonPID) }) -var pjParent = JSON.stringify({ - name: 'parent', - version: '1.2.3', - dependencies: { - child: 'git://localhost:1234/child.git' - } -}, null, 2) + '\n' - -var pjChild = JSON.stringify({ - name: 'child', - version: '1.0.3' -}, null, 2) + '\n' - function bootstrap () { mkdirp.sync(pkg) fs.writeFileSync(resolve(pkg, 'package.json'), pjParent) diff --git a/deps/npm/test/tap/bin.js b/deps/npm/test/tap/bin.js new file mode 100644 index 0000000000..ee4e1ff28c --- /dev/null +++ b/deps/npm/test/tap/bin.js @@ -0,0 +1,17 @@ +var path = require("path") +var test = require("tap").test +var common = require("../common-tap.js") +var opts = { cwd: __dirname } +var binDir = "../../node_modules/.bin" +var fixture = path.resolve(__dirname, binDir) + +test('npm bin', function (t) { + common.npm(["bin"], opts, function (err, code, stdout, stderr) { + t.ifError(err, "bin ran without issue") + t.notOk(stderr, "should have no stderr") + t.equal(code, 0, "exit ok") + var res = path.resolve(stdout) + t.equal(res, fixture + "\n") + t.end() + }) +}) diff --git a/deps/npm/test/tap/builtin-config.js b/deps/npm/test/tap/builtin-config.js index 75acd2be27..d92551ed6e 100644 --- a/deps/npm/test/tap/builtin-config.js +++ b/deps/npm/test/tap/builtin-config.js @@ -32,6 +32,7 @@ test("setup", function (t) { test("install npm into first folder", function (t) { var args = ["install", npm, "-g", "--prefix=" + folder + "/first", + "--ignore-scripts", "--cache=" + folder + "/cache", "--no-spin", "--loglevel=silent", diff --git a/deps/npm/test/tap/bundled-dependencies-nonarray.js b/deps/npm/test/tap/bundled-dependencies-nonarray.js index 938aa629a5..bff0522d03 100644 --- a/deps/npm/test/tap/bundled-dependencies-nonarray.js +++ b/deps/npm/test/tap/bundled-dependencies-nonarray.js @@ -13,6 +13,22 @@ var dir = path.resolve(__dirname, 'bundleddependencies') var pkg = path.resolve(dir, 'pkg-with-bundled') var dep = path.resolve(dir, 'a-bundled-dep') +var pj = JSON.stringify({ + name: 'pkg-with-bundled', + version: '1.0.0', + dependencies: { + 'a-bundled-dep': 'file:../a-bundled-dep' + }, + bundledDependencies: { + 'a-bundled-dep': 'file:../a-bundled-dep' + } +}, null, 2) + '\n' + +var pjDep = JSON.stringify({ + name: 'a-bundled-dep', + version: '2.0.0' +}, null, 2) + '\n' + test('setup', function (t) { bootstrap() t.end() @@ -45,22 +61,6 @@ test('cleanup', function (t) { t.end() }) -var pj = JSON.stringify({ - name: 'pkg-with-bundled', - version: '1.0.0', - dependencies: { - 'a-bundled-dep': 'file:../a-bundled-dep' - }, - bundledDependencies: { - 'a-bundled-dep': 'file:../a-bundled-dep' - } -}, null, 2) + '\n' - -var pjDep = JSON.stringify({ - name: 'a-bundled-dep', - version: '2.0.0' -}, null, 2) + '\n' - function bootstrap () { mkdirp.sync(dir) diff --git a/deps/npm/test/tap/cache-add-unpublished.js b/deps/npm/test/tap/cache-add-unpublished.js index 46f0db232e..fe26929fce 100644 --- a/deps/npm/test/tap/cache-add-unpublished.js +++ b/deps/npm/test/tap/cache-add-unpublished.js @@ -1,12 +1,34 @@ var common = require("../common-tap.js") var test = require("tap").test +var mr = require("npm-registry-mock") test("cache add", function (t) { - common.npm(["cache", "add", "superfoo"], {}, function (er, c, so, se) { - if (er) throw er - t.ok(c, "got non-zero exit code") - t.equal(so, "", "nothing printed to stdout") - t.similar(se, /404 Not Found: superfoo/, "got expected error") - t.end() + setup(function (er, s) { + if (er) { + throw er + } + common.npm([ + "cache", + "add", + "superfoo", + "--registry=http://localhost:1337/" + ], {}, function (er, c, so, se) { + if (er) throw er + t.ok(c, "got non-zero exit code") + t.equal(so, "", "nothing printed to stdout") + t.similar(se, /404 Not Found: superfoo/, "got expected error") + s.close() + t.end() + }) }) }) + +function setup (cb) { + var s = require("http").createServer(function (req, res) { + res.statusCode = 404 + res.end("{\"error\":\"not_found\"}\n") + }) + s.listen(1337, function () { + cb(null, s) + }) +} diff --git a/deps/npm/test/tap/config-meta.js b/deps/npm/test/tap/config-meta.js index 5e0c1b7e7c..3da27a872b 100644 --- a/deps/npm/test/tap/config-meta.js +++ b/deps/npm/test/tap/config-meta.js @@ -37,7 +37,7 @@ test("get files", function (t) { }) files.forEach(function (f) { try { - var s = fs.statSync(f) + var s = fs.lstatSync(f) } catch (er) { return } diff --git a/deps/npm/test/tap/dedupe-scoped.js b/deps/npm/test/tap/dedupe-scoped.js index dacf405fcf..a093e1f8c0 100644 --- a/deps/npm/test/tap/dedupe-scoped.js +++ b/deps/npm/test/tap/dedupe-scoped.js @@ -11,40 +11,6 @@ var modules = join(pkg, 'node_modules') var EXEC_OPTS = { cwd: pkg } -test('setup', function (t) { - setup() - t.end() -}) - -// we like the cars -function ltrimm (l) { return l.trim() } - -test('dedupe finds the common scoped modules and moves it up one level', function (t) { - common.npm( - [ - 'find-dupes' // I actually found a use for this command! - ], - EXEC_OPTS, - function (err, code, stdout, stderr) { - t.ifError(err, 'successful dry run against fake install') - t.notOk(code, 'npm ran without issue') - t.notOk(stderr, 'npm printed no errors') - t.same( - stdout.trim().split('\n').map(ltrimm), - [prolog].concat(body).map(ltrimm), - 'got expected output' - ) - - t.end() - } - ) -}) - -test('cleanup', function (t) { - cleanup() - t.end() -}) - var prolog = 'dedupe@0.0.0 ' + pkg var body = function () {/* ├─┬ first@1.0.0 @@ -95,6 +61,41 @@ var secondUnique = { 'version': '1.2.0' } + +test('setup', function (t) { + setup() + t.end() +}) + +// we like the cars +function ltrimm (l) { return l.trim() } + +test('dedupe finds the common scoped modules and moves it up one level', function (t) { + common.npm( + [ + 'find-dupes' // I actually found a use for this command! + ], + EXEC_OPTS, + function (err, code, stdout, stderr) { + t.ifError(err, 'successful dry run against fake install') + t.notOk(code, 'npm ran without issue') + t.notOk(stderr, 'npm printed no errors') + t.same( + stdout.trim().split('\n').map(ltrimm), + [prolog].concat(body).map(ltrimm), + 'got expected output' + ) + + t.end() + } + ) +}) + +test('cleanup', function (t) { + cleanup() + t.end() +}) + function setup (cb) { cleanup() diff --git a/deps/npm/test/tap/gently-rm-overeager.js b/deps/npm/test/tap/gently-rm-overeager.js index 7284d3e368..35f46cc219 100644 --- a/deps/npm/test/tap/gently-rm-overeager.js +++ b/deps/npm/test/tap/gently-rm-overeager.js @@ -13,6 +13,14 @@ var EXEC_OPTS = { cwd : pkg } +var fixture = { + name: "@test/whoops", + version: "1.0.0", + scripts: { + postinstall: "echo \"nope\" && exit 1" + } +} + test("setup", function (t) { cleanup() setup() @@ -40,14 +48,6 @@ test("cleanup", function (t) { }) -var fixture = { - name: "@test/whoops", - version: "1.0.0", - scripts: { - postinstall: "echo \"nope\" && exit 1" - } -} - function cleanup () { rimraf.sync(pkg) rimraf.sync(dep) diff --git a/deps/npm/test/tap/gently-rm-symlink.js b/deps/npm/test/tap/gently-rm-symlink.js index ff1524b04a..d69b62e5b2 100644 --- a/deps/npm/test/tap/gently-rm-symlink.js +++ b/deps/npm/test/tap/gently-rm-symlink.js @@ -15,6 +15,17 @@ var EXEC_OPTS = { cwd : pkg } + +var index = "module.exports = function () { console.log('whoop whoop') }" + +var fixture = { + name: "@test/linked", + version: "1.0.0", + bin: { + linked: "./index.js" + } +} + test("setup", function (t) { cleanup() setup() @@ -72,17 +83,6 @@ test("cleanup", function (t) { t.end() }) - -var index = "module.exports = function () { console.log('whoop whoop') }" - -var fixture = { - name: "@test/linked", - version: "1.0.0", - bin: { - linked: "./index.js" - } -} - function verify (t, stdout) { var binPath = resolve(lnk, "bin", "linked") var pkgPath = resolve(lnk, "lib", "node_modules", "@test", "linked") diff --git a/deps/npm/test/tap/git-dependency-install-link.js b/deps/npm/test/tap/git-dependency-install-link.js index 92938b3426..cbb256d983 100644 --- a/deps/npm/test/tap/git-dependency-install-link.js +++ b/deps/npm/test/tap/git-dependency-install-link.js @@ -26,6 +26,20 @@ var EXEC_OPTS = { cache: cache } +var pjParent = JSON.stringify({ + name: 'parent', + version: '1.2.3', + dependencies: { + 'child': 'git://localhost:1234/child.git' + } +}, null, 2) + '\n' + +var pjChild = JSON.stringify({ + name: 'child', + version: '1.0.3' +}, null, 2) + '\n' + + test('setup', function (t) { bootstrap() setup(function (er, r) { @@ -93,19 +107,6 @@ test('clean', function (t) { process.kill(daemonPID) }) -var pjParent = JSON.stringify({ - name: 'parent', - version: '1.2.3', - dependencies: { - 'child': 'git://localhost:1234/child.git' - } -}, null, 2) + '\n' - -var pjChild = JSON.stringify({ - name: 'child', - version: '1.0.3' -}, null, 2) + '\n' - function bootstrap () { rimraf.sync(repo) rimraf.sync(pkg) diff --git a/deps/npm/test/tap/git-npmignore.js b/deps/npm/test/tap/git-npmignore.js index 6a703f0cf6..5e915a706f 100644 --- a/deps/npm/test/tap/git-npmignore.js +++ b/deps/npm/test/tap/git-npmignore.js @@ -27,6 +27,19 @@ var EXEC_OPTS = { cwd : pkg } +var gitignore = "node_modules/\n" +var npmignore = "t.js\n" + +var a = "console.log('hi');" +var t = "require('tap').test(function (t) { t.pass('I am a test!'); t.end(); });" +var fixture = { + "name" : "gitch", + "version" : "1.0.0", + "private" : true, + "main" : "a.js" +} + + test("setup", function (t) { setup(function (er) { t.ifError(er, "setup ran OK") @@ -85,18 +98,6 @@ function packInstallTest (spec, t) { ) } -var gitignore = "node_modules/\n" -var npmignore = "t.js\n" - -var a = "console.log('hi');" -var t = "require('tap').test(function (t) { t.pass('I am a test!'); t.end(); });" -var fixture = { - "name" : "gitch", - "version" : "1.0.0", - "private" : true, - "main" : "a.js" -} - function cleanup () { process.chdir(tmpdir()) rimraf.sync(pkg) diff --git a/deps/npm/test/tap/git-races.js b/deps/npm/test/tap/git-races.js new file mode 100644 index 0000000000..6bbfe78bd7 --- /dev/null +++ b/deps/npm/test/tap/git-races.js @@ -0,0 +1,212 @@ +var execFile = require('child_process').execFile +var path = require('path') +var zlib = require('zlib') + +var asyncMap = require('slide').asyncMap +var deepEqual = require('deep-equal') +var fs = require('graceful-fs') +var mkdirp = require('mkdirp') +var once = require('once') +var requireInject = require('require-inject') +var rimraf = require('rimraf') +var tar = require('tar') +var test = require('tap').test +var tmpdir = require('osenv').tmpdir +var which = require('which') + +var wd = path.resolve(tmpdir(), 'git-races') +var fixtures = path.resolve(__dirname, '../fixtures') +var testcase = 'github-com-BryanDonovan-npm-git-test' +var testcase_git = path.resolve(wd, testcase + '.git') +var testcase_path = path.resolve(wd, testcase) +var testcase_tgz = path.resolve(fixtures, testcase + '.git.tar.gz') + +var testtarballs = [] +var testrepos = {} +var testurls = {} + +/* +This test is specifically for #7202, where the bug was if you tried installing multiple git urls that +pointed at the same repo but had different comittishes, you'd sometimes get the wrong version. +The test cases, provided by @BryanDonovan, have a dependency tree like this: + + top + bar#4.0.0 + buzz#3.0.0 + foo#3.0.0 + buzz#3.0.0 + foo#4.0.0 + buzz#2.0.0 + +But what would happen is that buzz#2.0.0 would end up installed under bar#4.0.0. + +bar#4.0.0 shouldn't have gotten its own copy if buzz, and if it did, it shouldn've been buzz#3.0.0 +*/ + +;['bar', 'foo', 'buzz'].forEach(function (name) { + var mockurl = 'ssh://git@github.com/BryanDonovan/dummy-npm-' + name + '.git' + var realrepo = path.resolve(wd, 'github-com-BryanDonovan-dummy-npm-' + name + '.git') + var tgz = path.resolve(fixtures, 'github-com-BryanDonovan-dummy-npm-' + name + '.git.tar.gz') + + testrepos[mockurl] = realrepo + testtarballs.push(tgz) +}) + +function cleanup () { + process.chdir(tmpdir()) + rimraf.sync(wd) +} + +var npm = requireInject.installGlobally('../../lib/npm.js', { + 'child_process': { + 'execFile': function (cmd, args, options, cb) { + // If it's a clone we swap any requests for any of the urls we're mocking + // with the path to the bare repo + if (args[0] === 'clone') { + var m2 = args.length - 2 + var m1 = args.length - 1 + if (testrepos[args[m2]]) { + testurls[args[m1]] = args[m2] + args[m2] = testrepos[args[m2]] + } + execFile(cmd, args, options, cb) + // here, we intercept npm validating the remote origin url on one of the + // clones we've done previously and return the original url that was requested + } else if (args[0] === 'config' && args[1] === '--get' && args[2] === 'remote.origin.url') { + process.nextTick(function () { + cb(null, testurls[options.cwd], '') + }) + } else { + execFile(cmd, args, options, cb) + } + } + } +}) + +function extract (tarball, target, cb) { + cb = once(cb) + fs.createReadStream(tarball).on('error', function (er) { cb(er) }) + .pipe(zlib.createGunzip()).on('error', function (er) { cb(er) }) + .pipe(tar.Extract({path: target})).on('error', function (er) { cb(er) }) + .on('end', function () { + cb() + }) +} + +// Copied from lib/utils/git, because we need to use +// it before calling npm.load and lib/utils/git uses npm.js +// which doesn't allow that. =( =( + +function prefixGitArgs () { + return process.platform === 'win32' ? ['-c', 'core.longpaths=true'] : [] +} + +var gitcmd + +function execGit (args, options, cb) { + var fullArgs = prefixGitArgs().concat(args || []) + return execFile(gitcmd, fullArgs, options, cb) +} + +function gitWhichAndExec (args, options, cb) { + if (gitcmd) return execGit(args, options, cb) + + which('git', function (err, pathtogit) { + if (err) { + err.code = 'ENOGIT' + return cb(err) + } + gitcmd = pathtogit + + execGit(args, options, cb) + }) +} + +function andClone (gitdir, repodir, cb) { + return function (er) { + if (er) return cb(er) + gitWhichAndExec(['clone', gitdir, repodir], {}, cb) + } +} + +function setup (cb) { + cleanup() + mkdirp.sync(wd) + + extract(testcase_tgz, wd, andClone(testcase_git, testcase_path, andExtractPackages)) + + function andExtractPackages (er) { + if (er) return cb(er) + asyncMap(testtarballs, function (tgz, done) { + extract(tgz, wd, done) + }, andChdir) + } + function andChdir (er) { + if (er) return cb(er) + process.chdir(testcase_path) + andLoadNpm() + } + function andLoadNpm () { + var opts = { + cache: path.resolve(wd, 'cache') + } + npm.load(opts, cb) + } +} + +// there are two (sic) valid trees that can result we don't care which one we +// get in npm@2 +var oneTree = [ + 'npm-git-test@1.0.0', [ + ['dummy-npm-bar@4.0.0', [ + ['dummy-npm-foo@3.0.0', []] + ]], + ['dummy-npm-buzz@3.0.0', []], + ['dummy-npm-foo@4.0.0', [ + ['dummy-npm-buzz@2.0.0', []] + ]] + ] +] +var otherTree = [ + 'npm-git-test@1.0.0', [ + ['dummy-npm-bar@4.0.0', [ + ['dummy-npm-buzz@3.0.0', []], + ['dummy-npm-foo@3.0.0', []] + ]], + ['dummy-npm-buzz@3.0.0', []], + ['dummy-npm-foo@4.0.0', [ + ['dummy-npm-buzz@2.0.0', []] + ]] + ] +] + +function toSimple (tree) { + var deps = [] + Object.keys(tree.dependencies || {}).forEach(function (dep) { + deps.push(toSimple(tree.dependencies[dep])) + }) + return [ tree['name'] + '@' + tree['version'], deps ] +} + +test('setup', function (t) { + setup(function (er) { + t.ifError(er, 'setup ran OK') + t.end() + }) +}) + +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' + ) + }) + }) +}) diff --git a/deps/npm/test/tap/graceful-restart.js b/deps/npm/test/tap/graceful-restart.js index bd1f311441..5326474805 100644 --- a/deps/npm/test/tap/graceful-restart.js +++ b/deps/npm/test/tap/graceful-restart.js @@ -10,36 +10,6 @@ var common = require('../common-tap.js') var pkg = resolve(__dirname, 'graceful-restart') -test('setup', function (t) { - bootstrap() - t.end() -}) - -test('graceless restart', function (t) { - fs.writeFileSync(resolve(pkg, 'package.json'), pjGraceless) - createChild(['run-script', 'restart'], function (err, code, out) { - t.ifError(err, 'restart finished successfully') - t.equal(code, 0, 'npm run-script exited with code') - t.equal(out, outGraceless, 'expected all scripts to run') - t.end() - }) -}) - -test('graceful restart', function (t) { - fs.writeFileSync(resolve(pkg, 'package.json'), pjGraceful) - createChild(['run-script', 'restart'], function (err, code, out) { - t.ifError(err, 'restart finished successfully') - t.equal(code, 0, 'npm run-script exited with code') - t.equal(out, outGraceful, 'expected only *restart scripts to run') - t.end() - }) -}) - -test('clean', function (t) { - cleanup() - t.end() -}) - var outGraceless = [ 'prerestart', 'prestop', @@ -90,6 +60,36 @@ var pjGraceful = JSON.stringify({ } }, null, 2) + '\n' +test('setup', function (t) { + bootstrap() + t.end() +}) + +test('graceless restart', function (t) { + fs.writeFileSync(resolve(pkg, 'package.json'), pjGraceless) + createChild(['run-script', 'restart'], function (err, code, out) { + t.ifError(err, 'restart finished successfully') + t.equal(code, 0, 'npm run-script exited with code') + t.equal(out, outGraceless, 'expected all scripts to run') + t.end() + }) +}) + +test('graceful restart', function (t) { + fs.writeFileSync(resolve(pkg, 'package.json'), pjGraceful) + createChild(['run-script', 'restart'], function (err, code, out) { + t.ifError(err, 'restart finished successfully') + t.equal(code, 0, 'npm run-script exited with code') + t.equal(out, outGraceful, 'expected only *restart scripts to run') + t.end() + }) +}) + +test('clean', function (t) { + cleanup() + t.end() +}) + function bootstrap () { mkdirp.sync(pkg) } diff --git a/deps/npm/test/tap/install-bad-man.js b/deps/npm/test/tap/install-bad-man.js index 531509e997..9ec8a84734 100644 --- a/deps/npm/test/tap/install-bad-man.js +++ b/deps/npm/test/tap/install-bad-man.js @@ -15,6 +15,13 @@ var EXEC_OPTS = { cwd: target } +var json = { + name : "install-bad-man", + version : "1.2.3", + man : [ "./install-bad-man.1.lol" ] +} + + test("setup", function (t) { setup() t.pass("setup ran") @@ -54,12 +61,6 @@ test("clean", function (t) { t.end() }) -var json = { - name : "install-bad-man", - version : "1.2.3", - man : [ "./install-bad-man.1.lol" ] -} - function setup () { cleanup() mkdirp.sync(pkg) diff --git a/deps/npm/test/tap/install-man.js b/deps/npm/test/tap/install-man.js index 70879d81f1..ebba5d87b0 100644 --- a/deps/npm/test/tap/install-man.js +++ b/deps/npm/test/tap/install-man.js @@ -15,6 +15,12 @@ var EXEC_OPTS = { cwd: target } +var json = { + name : "install-man", + version : "1.2.3", + man : [ "./install-man.1" ] +} + test("setup", function (t) { setup() t.pass("setup ran") @@ -50,12 +56,6 @@ test("clean", function (t) { t.end() }) -var json = { - name : "install-man", - version : "1.2.3", - man : [ "./install-man.1" ] -} - function setup () { cleanup() mkdirp.sync(pkg) diff --git a/deps/npm/test/tap/link.js b/deps/npm/test/tap/link.js index 6562e35fd3..ea47e8296a 100644 --- a/deps/npm/test/tap/link.js +++ b/deps/npm/test/tap/link.js @@ -20,6 +20,31 @@ var OPTS = { } } +var readJSON = { + name: 'foo', + version: '1.0.0', + description: '', + main: 'index.js', + scripts: { + test: 'echo \"Error: no test specified\" && exit 1' + }, + author: '', + license: 'ISC' +} + +var installJSON = { + name: 'bar', + version: '1.0.0', + description: '', + main: 'index.js', + scripts: { + test: 'echo \"Error: no test specified\" && exit 1' + }, + author: '', + license: 'ISC' +} + + test('setup', function (t) { setup() common.npm(['ls', '-g', '--depth=0'], OPTS, function (err, c, out) { @@ -72,30 +97,6 @@ test('cleanup', function (t) { }) }) -var readJSON = { - name: 'foo', - version: '1.0.0', - description: '', - main: 'index.js', - scripts: { - test: 'echo \"Error: no test specified\" && exit 1' - }, - author: '', - license: 'ISC' -} - -var installJSON = { - name: 'bar', - version: '1.0.0', - description: '', - main: 'index.js', - scripts: { - test: 'echo \"Error: no test specified\" && exit 1' - }, - author: '', - license: 'ISC' -} - function cleanup () { rimraf.sync(linkRoot) rimraf.sync(link) diff --git a/deps/npm/test/tap/ls-l-depth-0.js b/deps/npm/test/tap/ls-l-depth-0.js index 5bbc1278c4..3b5ae4d202 100644 --- a/deps/npm/test/tap/ls-l-depth-0.js +++ b/deps/npm/test/tap/ls-l-depth-0.js @@ -27,6 +27,18 @@ var server var EXEC_OPTS = { cwd: pkg } +var fixture = { + 'name': 'glock', + 'version': '1.8.7', + 'private': true, + 'description': 'an inexplicably hostile sample package', + 'homepage': 'https://glo.ck', + 'repository': 'https://github.com/npm/glo.ck', + 'dependencies': { + 'underscore': '1.5.1' + } +} + test('setup', function (t) { setup() mr({ port: common.port }, function (er, s) { @@ -85,18 +97,6 @@ test('cleanup', function (t) { t.end() }) -var fixture = { - 'name': 'glock', - 'version': '1.8.7', - 'private': true, - 'description': 'an inexplicably hostile sample package', - 'homepage': 'https://glo.ck', - 'repository': 'https://github.com/npm/glo.ck', - 'dependencies': { - 'underscore': '1.5.1' - } -} - function cleanup () { process.chdir(tmpdir()) rimraf.sync(pkg) diff --git a/deps/npm/test/tap/noargs-install-config-save.js b/deps/npm/test/tap/noargs-install-config-save.js index 15613d7a72..b6900b4317 100644 --- a/deps/npm/test/tap/noargs-install-config-save.js +++ b/deps/npm/test/tap/noargs-install-config-save.js @@ -56,9 +56,8 @@ test("does not update the package.json with empty arguments", function (t) { var child = createChild([npm, "install"]) child.on("close", function () { var text = JSON.stringify(fs.readFileSync(pkg + "/package.json", "utf8")) - t.ok(text.indexOf("\"dependencies") === -1) s.close() - t.end() + t.ok(text.indexOf("\"dependencies") === -1) }) }) }) @@ -70,10 +69,9 @@ test("updates the package.json (adds dependencies) with an argument", function ( mr({port : common.port}, function (er, s) { var child = createChild([npm, "install", "underscore"]) child.on("close", function () { + s.close() var text = JSON.stringify(fs.readFileSync(pkg + "/package.json", "utf8")) t.ok(text.indexOf("\"dependencies") !== -1) - s.close() - t.end() }) }) }) diff --git a/deps/npm/test/tap/optional-metadep-rollback-collision.js b/deps/npm/test/tap/optional-metadep-rollback-collision.js index 929c4fc0fc..4b21f965ed 100644 --- a/deps/npm/test/tap/optional-metadep-rollback-collision.js +++ b/deps/npm/test/tap/optional-metadep-rollback-collision.js @@ -63,87 +63,6 @@ var opdep = { } } -test('setup', function (t) { - cleanup() - - mkdirp.sync(pkg) - fs.writeFileSync( - path.join(pkg, 'package.json'), - JSON.stringify(json, null, 2) - ) - - mkdirp.sync(path.join(deps, 'd1')) - fs.writeFileSync( - path.join(deps, 'd1', 'package.json'), - JSON.stringify(d1, null, 2) - ) - - mkdirp.sync(path.join(deps, 'd2')) - fs.writeFileSync( - path.join(deps, 'd2', 'package.json'), - JSON.stringify(d2, null, 2) - ) - fs.writeFileSync(path.join(deps, 'd2', 'blart.js'), blart) - - mkdirp.sync(path.join(deps, 'opdep')) - fs.writeFileSync( - path.join(deps, 'opdep', 'package.json'), - JSON.stringify(opdep, null, 2) - ) - fs.writeFileSync(path.join(deps, 'opdep', 'bad-server.js'), badServer) - - t.end() -}) - -test('go go test racer', function (t) { - common.npm( - [ - '--prefix', pkg, - '--fetch-retries', '0', - '--loglevel', 'silent', - '--cache', cache, - 'install' - ], - { - cwd: pkg, - env: { - PATH: process.env.PATH, - Path: process.env.Path - }, - stdio: [0, 'pipe', 2] - }, - function (er, code, stdout, stderr) { - t.ifError(er, 'install ran to completion without error') - t.notOk(code, 'npm install exited with code 0') - - t.equal(stdout, 'ok\nok\n') - t.notOk(/not ok/.test(stdout), 'should not contain the string \'not ok\'') - t.end() - } - ) -}) - -test('verify results', function (t) { - t.throws(function () { - fs.statSync(nm) - }) - t.end() -}) - -test('cleanup', function (t) { - cleanup() - t.end() -}) - -function cleanup () { - process.chdir(osenv.tmpdir()) - try { - var pid = +fs.readFileSync(pidfile) - process.kill(pid, 'SIGKILL') - } catch (er) {} - - rimraf.sync(pkg) -} var badServer = function () {/* var createServer = require('http').createServer @@ -235,3 +154,84 @@ mkdirp(BASEDIR, function go () { }, 3 * 1000) }) */}.toString().split('\n').slice(1, -1).join('\n') +test('setup', function (t) { + cleanup() + + mkdirp.sync(pkg) + fs.writeFileSync( + path.join(pkg, 'package.json'), + JSON.stringify(json, null, 2) + ) + + mkdirp.sync(path.join(deps, 'd1')) + fs.writeFileSync( + path.join(deps, 'd1', 'package.json'), + JSON.stringify(d1, null, 2) + ) + + mkdirp.sync(path.join(deps, 'd2')) + fs.writeFileSync( + path.join(deps, 'd2', 'package.json'), + JSON.stringify(d2, null, 2) + ) + fs.writeFileSync(path.join(deps, 'd2', 'blart.js'), blart) + + mkdirp.sync(path.join(deps, 'opdep')) + fs.writeFileSync( + path.join(deps, 'opdep', 'package.json'), + JSON.stringify(opdep, null, 2) + ) + fs.writeFileSync(path.join(deps, 'opdep', 'bad-server.js'), badServer) + + t.end() +}) + +test('go go test racer', function (t) { + common.npm( + [ + '--prefix', pkg, + '--fetch-retries', '0', + '--loglevel', 'silent', + '--cache', cache, + 'install' + ], + { + cwd: pkg, + env: { + PATH: process.env.PATH, + Path: process.env.Path + }, + stdio: [0, 'pipe', 2] + }, + function (er, code, stdout, stderr) { + t.ifError(er, 'install ran to completion without error') + t.notOk(code, 'npm install exited with code 0') + + t.equal(stdout, 'ok\nok\n') + t.notOk(/not ok/.test(stdout), 'should not contain the string \'not ok\'') + t.end() + } + ) +}) + +test('verify results', function (t) { + t.throws(function () { + fs.statSync(nm) + }) + t.end() +}) + +test('cleanup', function (t) { + cleanup() + t.end() +}) + +function cleanup () { + process.chdir(osenv.tmpdir()) + try { + var pid = +fs.readFileSync(pidfile) + process.kill(pid, 'SIGKILL') + } catch (er) {} + + rimraf.sync(pkg) +} diff --git a/deps/npm/test/tap/outdated-local.js b/deps/npm/test/tap/outdated-local.js index 04f1349c2b..f9b8af4420 100644 --- a/deps/npm/test/tap/outdated-local.js +++ b/deps/npm/test/tap/outdated-local.js @@ -14,6 +14,58 @@ var pkgScopedLocal = path.resolve(pkg, 'another-local-module') var pkgLocalUnderscore = path.resolve(pkg, 'underscore') var pkgLocalOptimist = path.resolve(pkg, 'optimist') +var pjParent = JSON.stringify({ + name: 'outdated-local', + version: '1.0.0', + dependencies: { + 'local-module': 'file:local-module', // updated locally, not on repo + '@scoped/another-local-module': 'file:another-local-module', // updated locally, scoped, not on repo + 'underscore': 'file:underscore', // updated locally, updated but lesser version on repo + 'optimist': 'file:optimist' // updated locally, updated and greater version on repo + } +}, null, 2) + '\n' + +var pjLocal = JSON.stringify({ + name: 'local-module', + version: '1.0.0' +}, null, 2) + '\n' + +var pjLocalBumped = JSON.stringify({ + name: 'local-module', + version: '1.1.0' +}, null, 2) + '\n' + +var pjScopedLocal = JSON.stringify({ + name: '@scoped/another-local-module', + version: '1.0.0' +}, null, 2) + '\n' + +var pjScopedLocalBumped = JSON.stringify({ + name: '@scoped/another-local-module', + version: '1.2.0' +}, null, 2) + '\n' + +var pjLocalUnderscore = JSON.stringify({ + name: 'underscore', + version: '1.3.1' +}, null, 2) + '\n' + +var pjLocalUnderscoreBumped = JSON.stringify({ + name: 'underscore', + version: '1.6.1' +}, null, 2) + '\n' + +var pjLocalOptimist = JSON.stringify({ + name: 'optimist', + version: '0.4.0' +}, null, 2) + '\n' + +var pjLocalOptimistBumped = JSON.stringify({ + name: 'optimist', + version: '0.5.0' +}, null, 2) + '\n' + + function mocks (server) { server.get('/local-module') .reply(404) @@ -112,57 +164,6 @@ test('cleanup', function (t) { t.end() }) -var pjParent = JSON.stringify({ - name: 'outdated-local', - version: '1.0.0', - dependencies: { - 'local-module': 'file:local-module', // updated locally, not on repo - '@scoped/another-local-module': 'file:another-local-module', // updated locally, scoped, not on repo - 'underscore': 'file:underscore', // updated locally, updated but lesser version on repo - 'optimist': 'file:optimist' // updated locally, updated and greater version on repo - } -}, null, 2) + '\n' - -var pjLocal = JSON.stringify({ - name: 'local-module', - version: '1.0.0' -}, null, 2) + '\n' - -var pjLocalBumped = JSON.stringify({ - name: 'local-module', - version: '1.1.0' -}, null, 2) + '\n' - -var pjScopedLocal = JSON.stringify({ - name: '@scoped/another-local-module', - version: '1.0.0' -}, null, 2) + '\n' - -var pjScopedLocalBumped = JSON.stringify({ - name: '@scoped/another-local-module', - version: '1.2.0' -}, null, 2) + '\n' - -var pjLocalUnderscore = JSON.stringify({ - name: 'underscore', - version: '1.3.1' -}, null, 2) + '\n' - -var pjLocalUnderscoreBumped = JSON.stringify({ - name: 'underscore', - version: '1.6.1' -}, null, 2) + '\n' - -var pjLocalOptimist = JSON.stringify({ - name: 'optimist', - version: '0.4.0' -}, null, 2) + '\n' - -var pjLocalOptimistBumped = JSON.stringify({ - name: 'optimist', - version: '0.5.0' -}, null, 2) + '\n' - function bootstrap () { mkdirp.sync(pkg) fs.writeFileSync(path.resolve(pkg, 'package.json'), pjParent) diff --git a/deps/npm/test/tap/outdated-private.js b/deps/npm/test/tap/outdated-private.js index 0696988046..882d7d9479 100644 --- a/deps/npm/test/tap/outdated-private.js +++ b/deps/npm/test/tap/outdated-private.js @@ -13,6 +13,39 @@ var pkgLocalPrivate = path.resolve(pkg, "local-private") var pkgScopedLocalPrivate = path.resolve(pkg, "another-local-private") var pkgLocalUnderscore = path.resolve(pkg, "underscore") +var pjParent = JSON.stringify({ + name : "outdated-private", + version : "1.0.0", + dependencies : { + "local-private" : "file:local-private", + "@scoped/another-local-private" : "file:another-local-private", + "underscore" : "file:underscore" + } +}, null, 2) + "\n" + +var pjLocalPrivate = JSON.stringify({ + name : "local-private", + version : "1.0.0", + private : true +}, null, 2) + "\n" + +var pjLocalPrivateBumped = JSON.stringify({ + name : "local-private", + version : "1.1.0", + private : true +}, null, 2) + "\n" + +var pjScopedLocalPrivate = JSON.stringify({ + name : "@scoped/another-local-private", + version : "1.0.0", + private : true +}, null, 2) + "\n" + +var pjLocalUnderscore = JSON.stringify({ + name : "underscore", + version : "1.3.1" +}, null, 2) + "\n" + test("setup", function (t) { bootstrap() t.end() @@ -55,39 +88,6 @@ test("cleanup", function (t) { t.end() }) -var pjParent = JSON.stringify({ - name : "outdated-private", - version : "1.0.0", - dependencies : { - "local-private" : "file:local-private", - "@scoped/another-local-private" : "file:another-local-private", - "underscore" : "file:underscore" - } -}, null, 2) + "\n" - -var pjLocalPrivate = JSON.stringify({ - name : "local-private", - version : "1.0.0", - private : true -}, null, 2) + "\n" - -var pjLocalPrivateBumped = JSON.stringify({ - name : "local-private", - version : "1.1.0", - private : true -}, null, 2) + "\n" - -var pjScopedLocalPrivate = JSON.stringify({ - name : "@scoped/another-local-private", - version : "1.0.0", - private : true -}, null, 2) + "\n" - -var pjLocalUnderscore = JSON.stringify({ - name : "underscore", - version : "1.3.1" -}, null, 2) + "\n" - function bootstrap () { mkdirp.sync(pkg) fs.writeFileSync(path.resolve(pkg, "package.json"), pjParent) diff --git a/deps/npm/test/tap/peer-deps-invalid.js b/deps/npm/test/tap/peer-deps-invalid.js index 7d630f8662..b256b8e2e3 100644 --- a/deps/npm/test/tap/peer-deps-invalid.js +++ b/deps/npm/test/tap/peer-deps-invalid.js @@ -23,6 +23,31 @@ var json = { } } +var fileFail = function () { +/**package +* { "name": "npm-test-peer-deps-file-invalid" +* , "main": "index.js" +* , "version": "1.2.3" +* , "description":"This one should conflict with the other one" +* , "peerDependencies": { "underscore": "1.3.3" } +* } +**/ + module.exports = 'I\'m just a lonely index, naked as the day I was born.' +}.toString().split('\n').slice(1, -1).join('\n') + +var fileOK = function () { +/**package +* { "name": "npm-test-peer-deps-file" +* , "main": "index.js" +* , "version": "1.2.3" +* , "description":"No package.json in sight!" +* , "peerDependencies": { "underscore": "1.3.1" } +* , "dependencies": { "mkdirp": "0.3.5" } +* } +**/ + module.exports = 'I\'m just a lonely index, naked as the day I was born.' +}.toString().split('\n').slice(1, -1).join('\n') + test('setup', function (t) { cleanup() mkdirp.sync(cache) @@ -75,28 +100,3 @@ function cleanup () { process.chdir(osenv.tmpdir()) rimraf.sync(pkg) } - -var fileFail = function () { -/**package -* { "name": "npm-test-peer-deps-file-invalid" -* , "main": "index.js" -* , "version": "1.2.3" -* , "description":"This one should conflict with the other one" -* , "peerDependencies": { "underscore": "1.3.3" } -* } -**/ - module.exports = 'I\'m just a lonely index, naked as the day I was born.' -}.toString().split('\n').slice(1, -1).join('\n') - -var fileOK = function () { -/**package -* { "name": "npm-test-peer-deps-file" -* , "main": "index.js" -* , "version": "1.2.3" -* , "description":"No package.json in sight!" -* , "peerDependencies": { "underscore": "1.3.1" } -* , "dependencies": { "mkdirp": "0.3.5" } -* } -**/ - module.exports = 'I\'m just a lonely index, naked as the day I was born.' -}.toString().split('\n').slice(1, -1).join('\n') diff --git a/deps/npm/test/tap/peer-deps-without-package-json.js b/deps/npm/test/tap/peer-deps-without-package-json.js index 16a3a114f6..08322eefaa 100644 --- a/deps/npm/test/tap/peer-deps-without-package-json.js +++ b/deps/npm/test/tap/peer-deps-without-package-json.js @@ -14,6 +14,20 @@ var pkg = path.resolve(__dirname, 'peer-deps-without-package-json') var cache = path.resolve(pkg, 'cache') var nodeModules = path.resolve(pkg, 'node_modules') +var fileJS = function () { +/**package +* { "name": "npm-test-peer-deps-file" +* , "main": "index.js" +* , "version": "1.2.3" +* , "description":"No package.json in sight!" +* , "peerDependencies": { "underscore": "1.3.1" } +* , "dependencies": { "mkdirp": "0.3.5" } +* } +**/ + + module.exports = 'I\'m just a lonely index, naked as the day I was born.' +}.toString().split('\n').slice(1, -1).join('\n') + test('setup', function (t) { t.comment('test for https://github.com/npm/npm/issues/3049') cleanup() @@ -65,17 +79,3 @@ function cleanup () { process.chdir(osenv.tmpdir()) rimraf.sync(pkg) } - -var fileJS = function () { -/**package -* { "name": "npm-test-peer-deps-file" -* , "main": "index.js" -* , "version": "1.2.3" -* , "description":"No package.json in sight!" -* , "peerDependencies": { "underscore": "1.3.1" } -* , "dependencies": { "mkdirp": "0.3.5" } -* } -**/ - - module.exports = 'I\'m just a lonely index, naked as the day I was born.' -}.toString().split('\n').slice(1, -1).join('\n') diff --git a/deps/npm/test/tap/publish-config.js b/deps/npm/test/tap/publish-config.js index 9e537a9206..fd6dd4a2a4 100644 --- a/deps/npm/test/tap/publish-config.js +++ b/deps/npm/test/tap/publish-config.js @@ -21,9 +21,9 @@ fs.writeFileSync(pkg + "/fixture_npmrc", test(function (t) { var child + t.plan(4) require("http").createServer(function (req, res) { t.pass("got request on the fakey fake registry") - t.end() this.close() res.statusCode = 500 res.end(JSON.stringify({ diff --git a/deps/npm/test/tap/registry.js b/deps/npm/test/tap/registry.js index 20e7bbe811..060d9b67b6 100644 --- a/deps/npm/test/tap/registry.js +++ b/deps/npm/test/tap/registry.js @@ -30,7 +30,7 @@ else { function runTests () { - var env = {} + var env = { TAP: 1 } for (var i in process.env) env[i] = process.env[i] env.npm = npmExec @@ -52,7 +52,7 @@ function runTests () { env: env, stdio: "inherit" } - common.npm(["test"], opts, function (err, code) { + common.npm(["test", "--", "-Rtap"], opts, function (err, code) { if (err) { throw err } if (code) { return test("need test to work", function (t) { diff --git a/deps/npm/test/tap/run-script.js b/deps/npm/test/tap/run-script.js index 60c9d3c4f9..8dfe574e13 100644 --- a/deps/npm/test/tap/run-script.js +++ b/deps/npm/test/tap/run-script.js @@ -13,43 +13,6 @@ var tmp = path.resolve(pkg, 'tmp') var opts = { cwd: pkg } -function testOutput (t, command, er, code, stdout, stderr) { - var lines - - if (er) - throw er - - if (stderr) - throw new Error('npm ' + command + ' stderr: ' + stderr.toString()) - - lines = stdout.trim().split('\n') - stdout = lines.filter(function (line) { - return line.trim() !== '' && line[0] !== '>' - }).join(';') - - t.equal(stdout, command) - t.end() -} - -function writeMetadata (object) { - fs.writeFileSync( - path.resolve(pkg, 'package.json'), - JSON.stringify(object, null, 2) + '\n' - ) -} - -function cleanup () { - rimraf.sync(pkg) -} - -test('setup', function (t) { - cleanup() - mkdirp.sync(cache) - mkdirp.sync(tmp) - writeMetadata(fullyPopulated) - t.end() -}) - var fullyPopulated = { 'name': 'runscript', 'version': '1.2.3', @@ -91,6 +54,44 @@ var both = { } } + +function testOutput (t, command, er, code, stdout, stderr) { + var lines + + if (er) + throw er + + if (stderr) + throw new Error('npm ' + command + ' stderr: ' + stderr.toString()) + + lines = stdout.trim().split('\n') + stdout = lines.filter(function (line) { + return line.trim() !== '' && line[0] !== '>' + }).join(';') + + t.equal(stdout, command) + t.end() +} + +function writeMetadata (object) { + fs.writeFileSync( + path.resolve(pkg, 'package.json'), + JSON.stringify(object, null, 2) + '\n' + ) +} + +function cleanup () { + rimraf.sync(pkg) +} + +test('setup', function (t) { + cleanup() + mkdirp.sync(cache) + mkdirp.sync(tmp) + writeMetadata(fullyPopulated) + t.end() +}) + test('npm run-script start', function (t) { common.npm(['run-script', 'start'], opts, testOutput.bind(null, t, 'start')) }) diff --git a/deps/npm/test/tap/scripts-whitespace-windows.js b/deps/npm/test/tap/scripts-whitespace-windows.js index b4d1f3a34e..d24a24d4d8 100644 --- a/deps/npm/test/tap/scripts-whitespace-windows.js +++ b/deps/npm/test/tap/scripts-whitespace-windows.js @@ -25,7 +25,8 @@ var json = { }, dependencies: { 'scripts-whitespace-windows-dep': '0.0.1' - } + }, + license: 'WTFPL' } var dependency = { @@ -34,6 +35,13 @@ var dependency = { bin: [ 'bin/foo' ] } +var foo = function () {/* +#!/usr/bin/env node + +if (process.argv.length === 8) + console.log('npm-test-fine') +*/}.toString().split('\n').slice(1, -1).join('\n') + test('setup', function (t) { cleanup() mkdirp.sync(tmp) @@ -72,9 +80,12 @@ test('setup', function (t) { test('test', function (t) { common.npm(['run', 'foo'], EXEC_OPTS, function (err, code, stdout, stderr) { + stderr = stderr.trim() + if (stderr) + console.error(stderr) t.ifErr(err, 'npm run finished without error') t.equal(code, 0, 'npm run exited ok') - t.notOk(stderr, 'no output stderr: ', stderr) + t.notOk(stderr, 'no output stderr: ' + stderr) stdout = stdout.trim() t.ok(/npm-test-fine/.test(stdout)) t.end() @@ -91,9 +102,3 @@ function cleanup () { rimraf.sync(pkg) } -var foo = function () {/* -#!/usr/bin/env node - -if (process.argv.length === 8) - console.log('npm-test-fine') -*/}.toString().split('\n').slice(1, -1).join('\n') diff --git a/deps/npm/test/tap/shrinkwrap-local-dependency.js b/deps/npm/test/tap/shrinkwrap-local-dependency.js index d9514e42d3..ffbde6574e 100644 --- a/deps/npm/test/tap/shrinkwrap-local-dependency.js +++ b/deps/npm/test/tap/shrinkwrap-local-dependency.js @@ -10,6 +10,34 @@ var PKG_DIR = path.resolve(__dirname, "shrinkwrap-local-dependency") var CACHE_DIR = path.resolve(PKG_DIR, "cache") var DEP_DIR = path.resolve(PKG_DIR, "dep") +var desired = { + "name": "npm-test-shrinkwrap-local-dependency", + "version": "0.0.0", + "dependencies": { + "npm-test-shrinkwrap-local-dependency-dep": { + "version": "0.0.0", + "from": "dep", + "resolved": "file:dep" + } + } +} + +var root = { + "author": "Thomas Torp", + "name": "npm-test-shrinkwrap-local-dependency", + "version": "0.0.0", + "dependencies": { + "npm-test-shrinkwrap-local-dependency-dep": "file:./dep" + } +} + +var dependency = { + "author": "Thomas Torp", + "name": "npm-test-shrinkwrap-local-dependency-dep", + "version": "0.0.0" +} + + test("shrinkwrap uses resolved with file: on local deps", function(t) { setup() @@ -67,33 +95,6 @@ test("cleanup", function(t) { t.end() }) -var desired = { - "name": "npm-test-shrinkwrap-local-dependency", - "version": "0.0.0", - "dependencies": { - "npm-test-shrinkwrap-local-dependency-dep": { - "version": "0.0.0", - "from": "dep", - "resolved": "file:dep" - } - } -} - -var root = { - "author": "Thomas Torp", - "name": "npm-test-shrinkwrap-local-dependency", - "version": "0.0.0", - "dependencies": { - "npm-test-shrinkwrap-local-dependency-dep": "file:./dep" - } -} - -var dependency = { - "author": "Thomas Torp", - "name": "npm-test-shrinkwrap-local-dependency-dep", - "version": "0.0.0" -} - function setup() { cleanup() mkdirp.sync(PKG_DIR) diff --git a/deps/npm/test/tap/unpublish-config.js b/deps/npm/test/tap/unpublish-config.js index e4d41800ae..58550ec4e5 100644 --- a/deps/npm/test/tap/unpublish-config.js +++ b/deps/npm/test/tap/unpublish-config.js @@ -36,6 +36,7 @@ test('setup', function (t) { test('cursory test of unpublishing with config', function (t) { var child + t.plan(4) http.createServer(function (req, res) { t.pass('got request on the fakey fake registry') this.close() @@ -44,7 +45,6 @@ test('cursory test of unpublishing with config', function (t) { error: 'shh no tears, only dreams now' })) child.kill() - t.end() }).listen(common.port, function () { t.pass('server is listening') diff --git a/deps/npm/test/tap/update-index.js b/deps/npm/test/tap/update-index.js index 0586269722..fe4244c308 100644 --- a/deps/npm/test/tap/update-index.js +++ b/deps/npm/test/tap/update-index.js @@ -13,74 +13,6 @@ var CACHE_DIR = path.resolve(PKG_DIR, 'cache') var server -function setup (t, mock, extra) { - mkdirp.sync(CACHE_DIR) - mr({ port: common.port, plugin: mock }, function (er, s) { - npm.load({ cache: CACHE_DIR, registry: common.registry }, function (err) { - if (extra) { - Object.keys(extra).forEach(function (k) { - npm.config.set(k, extra[k], 'user') - }) - } - t.ifError(err, 'no error') - server = s - t.end() - }) - }) -} - -function cleanup (t) { - server.close(function () { - rimraf.sync(PKG_DIR) - - t.end() - }) -} - -test('setup basic', function (t) { - setup(t, mocks.basic) -}) - -test('request basic', function (t) { - updateIndex(0, function (er) { - t.ifError(er, 'no error') - t.end() - }) -}) - -test('cleanup basic', cleanup) - -test('setup auth', function (t) { - setup(t, mocks.auth) -}) - -test('request auth failure', function (t) { - updateIndex(0, function (er) { - t.equals(er.code, 'E401', 'gotta get that auth') - t.ok(/^unauthorized/.test(er.message), 'unauthorized message') - t.end() - }) -}) - -test('cleanup auth failure', cleanup) - -test('setup auth', function (t) { - // mimic as if alwaysAuth had been set - setup(t, mocks.auth, { - _auth: new Buffer('bobby:tables').toString('base64'), - 'always-auth': true - }) -}) - -test('request auth success', function (t) { - updateIndex(0, function (er) { - t.ifError(er, 'no error') - t.end() - }) -}) - -test('cleanup auth', cleanup) - var mocks = { basic: function (mock) { mock.get('/-/all').reply(200, allMock) @@ -193,3 +125,71 @@ var allMock = { } } } + +function setup (t, mock, extra) { + mkdirp.sync(CACHE_DIR) + mr({ port: common.port, plugin: mock }, function (er, s) { + npm.load({ cache: CACHE_DIR, registry: common.registry }, function (err) { + if (extra) { + Object.keys(extra).forEach(function (k) { + npm.config.set(k, extra[k], 'user') + }) + } + t.ifError(err, 'no error') + server = s + t.end() + }) + }) +} + +function cleanup (t) { + server.close(function () { + rimraf.sync(PKG_DIR) + + t.end() + }) +} + +test('setup basic', function (t) { + setup(t, mocks.basic) +}) + +test('request basic', function (t) { + updateIndex(0, function (er) { + t.ifError(er, 'no error') + t.end() + }) +}) + +test('cleanup basic', cleanup) + +test('setup auth', function (t) { + setup(t, mocks.auth) +}) + +test('request auth failure', function (t) { + updateIndex(0, function (er) { + t.equals(er.code, 'E401', 'gotta get that auth') + t.ok(/^unauthorized/.test(er.message), 'unauthorized message') + t.end() + }) +}) + +test('cleanup auth failure', cleanup) + +test('setup auth', function (t) { + // mimic as if alwaysAuth had been set + setup(t, mocks.auth, { + _auth: new Buffer('bobby:tables').toString('base64'), + 'always-auth': true + }) +}) + +test('request auth success', function (t) { + updateIndex(0, function (er) { + t.ifError(er, 'no error') + t.end() + }) +}) + +test('cleanup auth', cleanup) |