diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2015-04-03 01:52:11 -0700 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2015-04-03 17:09:21 -0700 |
commit | 5eb983e0b37ca88fc3c08af518edbab7d9a55a9c (patch) | |
tree | a9488e26955c6461082f7cacb18975115a2762a5 /deps/npm/test/tap | |
parent | 416499c872ba3db45a4dd4b88e015b679931c15f (diff) | |
download | node-new-5eb983e0b37ca88fc3c08af518edbab7d9a55a9c.tar.gz |
deps: upgrade npm to 2.7.5
PR-URL: https://github.com/iojs/io.js/pull/1337
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'deps/npm/test/tap')
-rw-r--r-- | deps/npm/test/tap/config-new-cafile.js | 56 | ||||
-rw-r--r-- | deps/npm/test/tap/github-shortcut.js | 32 | ||||
-rw-r--r-- | deps/npm/test/tap/link.js | 119 | ||||
-rw-r--r-- | deps/npm/test/tap/update-index.js | 226 |
4 files changed, 323 insertions, 110 deletions
diff --git a/deps/npm/test/tap/config-new-cafile.js b/deps/npm/test/tap/config-new-cafile.js new file mode 100644 index 0000000000..9cffb19008 --- /dev/null +++ b/deps/npm/test/tap/config-new-cafile.js @@ -0,0 +1,56 @@ +require('./00-config-setup.js') + +var path = require('path') +var fs = require('graceful-fs') +var test = require('tap').test +var mkdirp = require('mkdirp') +var rimraf = require('rimraf') +var osenv = require('osenv') +var npmconf = require('../../lib/config/core.js') + +var dir = path.resolve(__dirname, 'config-new-cafile') +var beep = path.resolve(dir, 'beep.pem') + +test('setup', function (t) { + bootstrap() + t.end() +}) + +test('can set new cafile when old is gone', function (t) { + t.plan(5) + npmconf.load(function (error, conf) { + npmconf.loaded = false + t.ifError(error) + conf.set('cafile', beep, 'user') + conf.save('user', function (error) { + t.ifError(error) + t.equal(conf.get('cafile'), beep) + rimraf.sync(beep) + npmconf.load(function (error, conf) { + if (error) { + throw error + } + t.equal(conf.get('cafile'), beep) + conf.del('cafile') + conf.save('user', function (error) { + t.ifError(error) + }) + }) + }) + }) +}) + +test('cleanup', function (t) { + cleanup() + t.end() +}) + +function bootstrap () { + mkdirp.sync(dir) + fs.writeFileSync(beep, '') +} + +function cleanup () { + process.chdir(osenv.tmpdir()) + rimraf.sync(dir) +} diff --git a/deps/npm/test/tap/github-shortcut.js b/deps/npm/test/tap/github-shortcut.js new file mode 100644 index 0000000000..accc16f397 --- /dev/null +++ b/deps/npm/test/tap/github-shortcut.js @@ -0,0 +1,32 @@ +'use strict' +var requireInject = require('require-inject') +var test = require('tap').test + +test('github-shortcut', function (t) { + var cloneUrls = [ + ['git://github.com/foo/private.git', 'github shortcuts try git:// first'], + ['ssh://git@github.com/foo/private.git', 'github shortcuts try ssh:// urls second'] + ] + var npm = requireInject.installGlobally('../../lib/npm.js', { + 'child_process': { + 'execFile': function (cmd, args, options, cb) { + process.nextTick(function () { + if (args[0] !== 'clone') return cb(null, '', '') + var cloneUrl = cloneUrls.shift() + if (cloneUrl) { + t.is(args[3], cloneUrl[0], cloneUrl[1]) + } else { + t.fail('too many attempts to clone') + } + cb(new Error()) + }) + } + } + }) + + npm.load({loglevel: 'silent'}, function () { + npm.commands.install(['foo/private'], function (er, result) { + t.end() + }) + }) +}) diff --git a/deps/npm/test/tap/link.js b/deps/npm/test/tap/link.js new file mode 100644 index 0000000000..6562e35fd3 --- /dev/null +++ b/deps/npm/test/tap/link.js @@ -0,0 +1,119 @@ +var mkdirp = require('mkdirp') +var osenv = require('osenv') +var path = require('path') +var rimraf = require('rimraf') +var test = require('tap').test +var writeFileSync = require('fs').writeFileSync + +var common = require('../common-tap.js') + +var link = path.join(__dirname, 'link') +var linkInstall = path.join(__dirname, 'link-install') +var linkRoot = path.join(__dirname, 'link-root') + +var config = 'prefix = ' + linkRoot +var configPath = path.join(link, '_npmrc') + +var OPTS = { + env: { + 'npm_config_userconfig': configPath + } +} + +test('setup', function (t) { + setup() + common.npm(['ls', '-g', '--depth=0'], OPTS, function (err, c, out) { + t.ifError(err) + t.equal(c, 0, 'set up ok') + t.notOk(out.match(/UNMET DEPENDENCY foo@/), "foo isn't in global") + t.end() + }) +}) + +test('creates global link', function (t) { + process.chdir(link) + common.npm(['link'], OPTS, function (err, c, out) { + t.ifError(err, 'link has no error') + common.npm(['ls', '-g'], OPTS, function (err, c, out, stderr) { + t.ifError(err) + t.equal(c, 0) + t.equal(stderr, '', 'got expected stderr') + t.has(out, /foo@1.0.0/, 'creates global link ok') + t.end() + }) + }) +}) + +test('link-install the package', function (t) { + process.chdir(linkInstall) + common.npm(['link', 'foo'], OPTS, function (err) { + t.ifError(err, 'link-install has no error') + common.npm(['ls'], OPTS, function (err, c, out) { + t.ifError(err) + t.equal(c, 1) + t.has(out, /foo@1.0.0/, 'link-install ok') + t.end() + }) + }) +}) + +test('cleanup', function (t) { + process.chdir(osenv.tmpdir()) + common.npm(['rm', 'foo'], OPTS, function (err, code) { + t.ifError(err, 'npm removed the linked package without error') + t.equal(code, 0, 'cleanup foo in local ok') + common.npm(['rm', '-g', 'foo'], OPTS, function (err, code) { + t.ifError(err, 'npm removed the global package without error') + t.equal(code, 0, 'cleanup foo in global ok') + + cleanup() + t.end() + }) + }) +}) + +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) + rimraf.sync(linkInstall) +} + +function setup () { + cleanup() + mkdirp.sync(linkRoot) + mkdirp.sync(link) + writeFileSync( + path.join(link, 'package.json'), + JSON.stringify(readJSON, null, 2) + ) + mkdirp.sync(linkInstall) + writeFileSync( + path.join(linkInstall, 'package.json'), + JSON.stringify(installJSON, null, 2) + ) + writeFileSync(configPath, config) +} diff --git a/deps/npm/test/tap/update-index.js b/deps/npm/test/tap/update-index.js index cf305900c7..0586269722 100644 --- a/deps/npm/test/tap/update-index.js +++ b/deps/npm/test/tap/update-index.js @@ -1,23 +1,28 @@ -var common = require("../common-tap.js") -var test = require("tap").test -var npm = require("../../") -var mkdirp = require("mkdirp") -var rimraf = require("rimraf") -var path = require("path") -var mr = require("npm-registry-mock") +var common = require('../common-tap.js') +var test = require('tap').test +var npm = require('../../') +var mkdirp = require('mkdirp') +var rimraf = require('rimraf') +var path = require('path') +var mr = require('npm-registry-mock') -var updateIndex = require("../../lib/cache/update-index.js") +var updateIndex = require('../../lib/cache/update-index.js') -var PKG_DIR = path.resolve(__dirname, "get-basic") -var CACHE_DIR = path.resolve(PKG_DIR, "cache") +var PKG_DIR = path.resolve(__dirname, 'get-basic') +var CACHE_DIR = path.resolve(PKG_DIR, 'cache') var server -function setup (t, mock) { +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) { - t.ifError(err, "no error") + if (extra) { + Object.keys(extra).forEach(function (k) { + npm.config.set(k, extra[k], 'user') + }) + } + t.ifError(err, 'no error') server = s t.end() }) @@ -32,158 +37,159 @@ function cleanup (t) { }) } -test("setup basic", function (t) { +test('setup basic', function (t) { setup(t, mocks.basic) }) -test("request basic", function (t) { - updateIndex("http://localhost:1337/-/all", {}, function (er) { - t.ifError(er, "no error") +test('request basic', function (t) { + updateIndex(0, function (er) { + t.ifError(er, 'no error') t.end() }) }) -test("cleanup basic", cleanup) +test('cleanup basic', cleanup) -test("setup auth", function (t) { +test('setup auth', function (t) { setup(t, mocks.auth) }) -test("request auth failure", function (t) { - updateIndex("http://localhost:1337/-/all", {}, function (er) { - t.ok(er.code, "E401") - t.ok(/^unauthorized/.test(er.message), "unauthorized message") +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("request auth success", function (t) { +test('cleanup auth failure', cleanup) + +test('setup auth', function (t) { // mimic as if alwaysAuth had been set - var params = { - auth: { - username: "bobby", - password: "tables", - alwaysAuth: true - } - } + setup(t, mocks.auth, { + _auth: new Buffer('bobby:tables').toString('base64'), + 'always-auth': true + }) +}) - updateIndex("http://localhost:1337/-/all", params, function (er) { - t.ifError(er, "no error") +test('request auth success', function (t) { + updateIndex(0, function (er) { + t.ifError(er, 'no error') t.end() }) }) -test("cleanup auth", cleanup) +test('cleanup auth', cleanup) var mocks = { basic: function (mock) { - mock.get("/-/all").reply(200, allMock) + mock.get('/-/all').reply(200, allMock) }, auth: function (mock) { - var littleBobbyTablesAuth = new Buffer("bobby:tables").toString("base64") - var auth = "Basic " + littleBobbyTablesAuth - mock.get("/-/all", { authorization: auth }).reply(200, allMock) - mock.get("/-/all").reply(401, { - error: "unauthorized", - reason: "You are not authorized to access this db." + var littleBobbyTablesAuth = new Buffer('bobby:tables').toString('base64') + var auth = 'Basic ' + littleBobbyTablesAuth + mock.get('/-/all', { authorization: auth }).reply(200, allMock) + mock.get('/-/all').reply(401, { + error: 'unauthorized', + reason: 'You are not authorized to access this db.' }) } } var allMock = { - "_updated": 1411727900+25, - "generator-frontcow": { - "name": "generator-frontcow", - "description": "f36b6a6123da50959741e2ce4d634f96ec668c56 This is a fake description to ensure we do not accidentally search the real npm registry or use some kind of cache", - "dist-tags": { - "latest": "0.1.19" + '_updated': 1411727900 + 25, + 'generator-frontcow': { + 'name': 'generator-frontcow', + 'description': 'f36b6a6123da50959741e2ce4d634f96ec668c56 This is a fake description to ensure we do not accidentally search the real npm registry or use some kind of cache', + 'dist-tags': { + 'latest': '0.1.19' }, - "maintainers": [ + 'maintainers': [ { - "name": "bcabanes", - "email": "contact@benjamincabanes.com" + 'name': 'bcabanes', + 'email': 'contact@benjamincabanes.com' } ], - "homepage": "https://github.com/bcabanes/generator-frontcow", - "keywords": [ - "sass", - "frontend", - "yeoman-generator", - "atomic", - "design", - "sass", - "foundation", - "foundation5", - "atomic design", - "bourbon", - "polyfill", - "font awesome" + 'homepage': 'https://github.com/bcabanes/generator-frontcow', + 'keywords': [ + 'sass', + 'frontend', + 'yeoman-generator', + 'atomic', + 'design', + 'sass', + 'foundation', + 'foundation5', + 'atomic design', + 'bourbon', + 'polyfill', + 'font awesome' ], - "repository": { - "type": "git", - "url": "https://github.com/bcabanes/generator-frontcow" + 'repository': { + 'type': 'git', + 'url': 'https://github.com/bcabanes/generator-frontcow' }, - "author": { - "name": "ben", - "email": "contact@benjamincabanes.com", - "url": "https://github.com/bcabanes" + 'author': { + 'name': 'ben', + 'email': 'contact@benjamincabanes.com', + 'url': 'https://github.com/bcabanes' }, - "bugs": { - "url": "https://github.com/bcabanes/generator-frontcow/issues" + 'bugs': { + 'url': 'https://github.com/bcabanes/generator-frontcow/issues' }, - "license": "MIT", - "readmeFilename": "README.md", - "time": { - "modified": "2014-10-03T02:26:18.406Z" + 'license': 'MIT', + 'readmeFilename': 'README.md', + 'time': { + 'modified': '2014-10-03T02:26:18.406Z' }, - "versions": { - "0.1.19": "latest" + 'versions': { + '0.1.19': 'latest' } }, - "marko": { - "name": "marko", - "description": "Marko is an extensible, streaming, asynchronous, high performance, HTML-based templating language that can be used in Node.js or in the browser.", - "dist-tags": { - "latest": "1.2.16" + 'marko': { + 'name': 'marko', + 'description': 'Marko is an extensible, streaming, asynchronous, high performance, HTML-based templating language that can be used in Node.js or in the browser.', + 'dist-tags': { + 'latest': '1.2.16' }, - "maintainers": [ + 'maintainers': [ { - "name": "pnidem", - "email": "pnidem@gmail.com" + 'name': 'pnidem', + 'email': 'pnidem@gmail.com' }, { - "name": "philidem", - "email": "phillip.idem@gmail.com" + 'name': 'philidem', + 'email': 'phillip.idem@gmail.com' } ], - "homepage": "https://github.com/raptorjs/marko", - "keywords": [ - "templating", - "template", - "async", - "streaming" + 'homepage': 'https://github.com/raptorjs/marko', + 'keywords': [ + 'templating', + 'template', + 'async', + 'streaming' ], - "repository": { - "type": "git", - "url": "https://github.com/raptorjs/marko.git" + 'repository': { + 'type': 'git', + 'url': 'https://github.com/raptorjs/marko.git' }, - "author": { - "name": "Patrick Steele-Idem", - "email": "pnidem@gmail.com" + 'author': { + 'name': 'Patrick Steele-Idem', + 'email': 'pnidem@gmail.com' }, - "bugs": { - "url": "https://github.com/raptorjs/marko/issues" + 'bugs': { + 'url': 'https://github.com/raptorjs/marko/issues' }, - "license": "Apache License v2.0", - "readmeFilename": "README.md", - "users": { - "pnidem": true + 'license': 'Apache License v2.0', + 'readmeFilename': 'README.md', + 'users': { + 'pnidem': true }, - "time": { - "modified": "2014-10-03T02:27:31.775Z" + 'time': { + 'modified': '2014-10-03T02:27:31.775Z' }, - "versions": { - "1.2.16": "latest" + 'versions': { + '1.2.16': 'latest' } } } |