Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorForrest L Norvell <forrest@npmjs.com>2015-04-10 07:03:23 +0300
committerForrest L Norvell <forrest@npmjs.com>2015-04-10 13:24:07 +0300
commit6b0f58877f37df9904490ffbaaad33862bd36dce (patch)
tree3b78a7361f2ac6ccf1644fb6276639a86a236e5c /test
parent33d1420bf2f629332fceb2ac7e174e63ac48f96a (diff)
git: use paths as presented by user
* Save the lightest-possibly normalized URL into `package.json` and package.json _from fields, because read-package-json, read-installed, and the cache all know how to handle them now. * Add support for github:, gist:, bitbucket:, and gitlab: shortcut syntax. GitHub shortcuts will continue to be normalized to org/repo instead of being saved with a github: prefix (for now). * If presented with shortcuts, try cloning via git, SSH, and HTTPS (in that order, skipping any methods that aren't supported by a given hosting provider). * No longer prompt for credentials -- it didn't work right with the spinner, and wasn't guaranteed to work anyway. We may experiment with doing this a better way in the future. Users can override this by setting GIT_ASKPASS in their environment if they want to experiment with interactive cloning, but should also set --no-spin on the npm command line (or run `npm config set spin=false`).
Diffstat (limited to 'test')
-rw-r--r--test/tap/add-remote-git-file.js2
-rw-r--r--test/tap/git-cache-locking.js44
-rw-r--r--test/tap/github-shortcut.js5
-rw-r--r--test/tap/ls-l-depth-0.js2
-rw-r--r--test/tap/maybe-github.js72
-rw-r--r--test/tap/outdated-git.js35
6 files changed, 43 insertions, 117 deletions
diff --git a/test/tap/add-remote-git-file.js b/test/tap/add-remote-git-file.js
index fc102faac..b2a7be903 100644
--- a/test/tap/add-remote-git-file.js
+++ b/test/tap/add-remote-git-file.js
@@ -28,7 +28,7 @@ test('setup', function (t) {
test('cache from repo', function (t) {
process.chdir(pkg)
var addRemoteGit = require('../../lib/cache/add-remote-git.js')
- addRemoteGit(cloneURL, false, function (er, data) {
+ addRemoteGit(cloneURL, function (er, data) {
t.ifError(er, 'cached via git')
t.equal(
url.parse(data._resolved).protocol,
diff --git a/test/tap/git-cache-locking.js b/test/tap/git-cache-locking.js
index 39f8b279c..e08c96e1b 100644
--- a/test/tap/git-cache-locking.js
+++ b/test/tap/git-cache-locking.js
@@ -1,48 +1,46 @@
-var test = require("tap").test
- , common = require("../common-tap")
- , path = require("path")
- , rimraf = require("rimraf")
- , mkdirp = require("mkdirp")
- , pkg = path.resolve(__dirname, "git-cache-locking")
- , tmp = path.join(pkg, "tmp")
- , cache = path.join(pkg, "cache")
+var test = require('tap').test
+var common = require('../common-tap')
+var path = require('path')
+var rimraf = require('rimraf')
+var mkdirp = require('mkdirp')
+var pkg = path.resolve(__dirname, 'git-cache-locking')
+var tmp = path.join(pkg, 'tmp')
+var cache = path.join(pkg, 'cache')
-
-test("setup", function (t) {
+test('setup', function (t) {
rimraf.sync(pkg)
- mkdirp.sync(path.resolve(pkg, "node_modules"))
+ mkdirp.sync(path.resolve(pkg, 'node_modules'))
t.end()
})
-test("git-cache-locking: install a git dependency", function (t) {
-
+test('git-cache-locking: install a git dependency', function (t) {
// disable git integration tests on Travis.
if (process.env.TRAVIS) return t.end()
// package c depends on a.git#master and b.git#master
// package b depends on a.git#master
common.npm([
- "install",
- "git://github.com/nigelzor/npm-4503-c.git"
+ 'install',
+ 'git://github.com/nigelzor/npm-4503-c.git'
], {
cwd: pkg,
env: {
- "npm_config_cache": cache,
- "npm_config_tmp": tmp,
- "npm_config_prefix": pkg,
- "npm_config_global": "false",
+ npm_config_cache: cache,
+ npm_config_tmp: tmp,
+ npm_config_prefix: pkg,
+ npm_config_global: 'false',
HOME: process.env.HOME,
Path: process.env.PATH,
PATH: process.env.PATH
}
- }, function (err, code) {
- t.ifErr(err, "npm install finished without error")
- t.equal(0, code, "npm install should succeed")
+ }, function (err, code, stdout, stderr) {
+ t.ifErr(err, 'npm install finished without error')
+ t.equal(0, code, 'npm install should succeed')
t.end()
})
})
-test("cleanup", function(t) {
+test('cleanup', function (t) {
rimraf.sync(pkg)
t.end()
})
diff --git a/test/tap/github-shortcut.js b/test/tap/github-shortcut.js
index accc16f39..e95b8bdfb 100644
--- a/test/tap/github-shortcut.js
+++ b/test/tap/github-shortcut.js
@@ -4,8 +4,9 @@ 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']
+ ['git://github.com/foo/private.git', 'github shortcuts try git URLs first'],
+ ['git@github.com:foo/private.git', 'github shortcuts try SSH second'],
+ ['https://github.com/foo/private.git', 'github shortcuts try HTTPS URLs third']
]
var npm = requireInject.installGlobally('../../lib/npm.js', {
'child_process': {
diff --git a/test/tap/ls-l-depth-0.js b/test/tap/ls-l-depth-0.js
index 09298bdd7..5bbc1278c 100644
--- a/test/tap/ls-l-depth-0.js
+++ b/test/tap/ls-l-depth-0.js
@@ -19,7 +19,7 @@ var expected =
'│ \n' +
'└── glock@1.8.7\n' +
' an inexplicably hostile sample package\n' +
- ' https://github.com/npm/glo.ck\n' +
+ ' git+https://github.com/npm/glo.ck.git\n' +
' https://glo.ck\n' +
'\n'
diff --git a/test/tap/maybe-github.js b/test/tap/maybe-github.js
deleted file mode 100644
index 52a62e11b..000000000
--- a/test/tap/maybe-github.js
+++ /dev/null
@@ -1,72 +0,0 @@
-require("../common-tap.js")
-var test = require("tap").test
-var npm = require("../../lib/npm.js")
-
-// this is the narrowest way to replace a function in the module cache
-var found = true
-var remoteGitPath = require.resolve("../../lib/cache/add-remote-git.js")
-require("module")._cache[remoteGitPath] = {
- id: remoteGitPath,
- exports: function stub(_, __, cb) {
- if (found) {
- cb(null, {})
- }
- else {
- cb(new Error("not on filesystem"))
- }
- }
-}
-
-// only load maybeGithub now, so it gets the stub from cache
-var maybeGithub = require("../../lib/cache/maybe-github.js")
-
-test("should throw with no parameters", function (t) {
- t.plan(1)
-
- t.throws(function () {
- maybeGithub()
- }, "throws when called without parameters")
-})
-
-test("should throw with wrong parameter types", function (t) {
- t.plan(2)
-
- t.throws(function () {
- maybeGithub({}, function () {})
- }, "expects only a package name")
-
- t.throws(function () {
- maybeGithub("npm/xxx-noexist", "ham")
- }, "is always async")
-})
-
-test("should find an existing package on Github", function (t) {
- found = true
- npm.load({}, function (error) {
- t.notOk(error, "bootstrapping succeeds")
- t.doesNotThrow(function () {
- maybeGithub("npm/npm", function (error, data) {
- t.notOk(error, "no issues in looking things up")
- t.ok(data, "received metadata from Github")
- t.end()
- })
- })
- })
-})
-
-test("shouldn't find a nonexistent package on Github", function (t) {
- found = false
- npm.load({}, function () {
- t.doesNotThrow(function () {
- maybeGithub("npm/xxx-noexist", function (error, data) {
- t.equal(
- error.message,
- "not on filesystem",
- "passed through original error message"
- )
- t.notOk(data, "didn't pass any metadata")
- t.end()
- })
- })
- })
-})
diff --git a/test/tap/outdated-git.js b/test/tap/outdated-git.js
index 32bfead67..0ef243bee 100644
--- a/test/tap/outdated-git.js
+++ b/test/tap/outdated-git.js
@@ -11,6 +11,18 @@ var npm = require('../../')
// config
var pkg = path.resolve(__dirname, 'outdated-git')
var cache = path.resolve(pkg, 'cache')
+var json = {
+ name: 'outdated-git',
+ author: 'Rocko Artischocko',
+ description: 'fixture',
+ version: '0.0.1',
+ main: 'index.js',
+ dependencies: {
+ 'foo-private': 'git://github.com/robertkowalski/foo-private.git',
+ 'foo-private-credentials': 'git://user:pass@github.com/robertkowalski/foo-private.git',
+ 'foo-github': 'robertkowalski/foo'
+ }
+}
test('setup', function (t) {
setup()
@@ -22,11 +34,11 @@ test('discovers new versions in outdated', function (t) {
t.plan(5)
npm.load({cache: cache, registry: common.registry, loglevel: 'silent'}, function () {
npm.commands.outdated([], function (er, d) {
- t.equal('git', d[0][3])
- t.equal('git', d[0][4])
- t.equal('git://github.com/robertkowalski/foo-private.git', d[0][5])
- t.equal('git://user:pass@github.com/robertkowalski/foo-private.git', d[1][5])
- t.equal('git+https://github.com/robertkowalski/foo', d[2][5])
+ t.equal(d[0][3], 'git')
+ t.equal(d[0][4], 'git')
+ t.equal(d[0][5], 'git://github.com/robertkowalski/foo-private.git')
+ t.equal(d[1][5], 'git://user:pass@github.com/robertkowalski/foo-private.git')
+ t.equal(d[2][5], 'github:robertkowalski/foo')
})
})
})
@@ -36,19 +48,6 @@ test('cleanup', function (t) {
t.end()
})
-var json = {
- name: 'outdated-git',
- author: 'Rocko Artischocko',
- description: 'fixture',
- version: '0.0.1',
- main: 'index.js',
- dependencies: {
- 'foo-private': 'git://github.com/robertkowalski/foo-private.git',
- 'foo-private-credentials': 'git://user:pass@github.com/robertkowalski/foo-private.git',
- 'foo-github': 'robertkowalski/foo'
- }
-}
-
function setup () {
mkdirp.sync(cache)
fs.writeFileSync(path.join(pkg, 'package.json'), JSON.stringify(json, null, 2), 'utf8')