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 13:22:26 +0300
committerForrest L Norvell <forrest@npmjs.com>2015-04-10 13:24:08 +0300
commita05e99360c54336263de68c7cfb34d8fe8087f72 (patch)
tree832caedaae1771d72a5d78de3437738baf41a97e /test
parentdd398e98a8eba27eeba84378200da3d078fdf980 (diff)
git: test all the shorthands
Diffstat (limited to 'test')
-rw-r--r--test/tap/bitbucket-shortcut-package.js84
-rw-r--r--test/tap/bitbucket-shortcut.js81
-rw-r--r--test/tap/gist-short-shortcut-package.js84
-rw-r--r--test/tap/gist-short-shortcut.js81
-rw-r--r--test/tap/gist-shortcut-package.js84
-rw-r--r--test/tap/gist-shortcut.js81
-rw-r--r--test/tap/github-shortcut-package.js84
-rw-r--r--test/tap/github-shortcut.js56
-rw-r--r--test/tap/gitlab-shortcut-package.js83
-rw-r--r--test/tap/gitlab-shortcut.js80
10 files changed, 794 insertions, 4 deletions
diff --git a/test/tap/bitbucket-shortcut-package.js b/test/tap/bitbucket-shortcut-package.js
new file mode 100644
index 000000000..bc38bd02f
--- /dev/null
+++ b/test/tap/bitbucket-shortcut-package.js
@@ -0,0 +1,84 @@
+'use strict'
+var fs = require('graceful-fs')
+var path = require('path')
+
+var mkdirp = require('mkdirp')
+var osenv = require('osenv')
+var requireInject = require('require-inject')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var common = require('../common-tap.js')
+
+var pkg = path.resolve(__dirname, 'bitbucket-shortcut-package')
+
+var json = {
+ name: 'bitbucket-shortcut-package',
+ version: '0.0.0',
+ dependencies: {
+ 'private': 'bitbucket:foo/private'
+ }
+}
+
+test('setup', function (t) {
+ setup()
+ t.end()
+})
+
+test('bitbucket-shortcut', function (t) {
+ var cloneUrls = [
+ ['git@bitbucket.org:foo/private.git', 'Bitbucket shortcuts try SSH first'],
+ ['https://bitbucket.org/foo/private.git', 'Bitbucket shortcuts try HTTPS 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())
+ })
+ }
+ }
+ })
+
+ var opts = {
+ cache: path.resolve(pkg, 'cache'),
+ prefix: pkg,
+ registry: common.registry,
+ loglevel: 'silent'
+ }
+ npm.load(opts, function (er) {
+ t.ifError(er, 'npm loaded without error')
+ npm.commands.install([], function (er) {
+ t.ok(er, 'mocked install failed as expected')
+ t.end()
+ })
+ })
+})
+
+test('cleanup', function (t) {
+ cleanup()
+ t.end()
+})
+
+function setup () {
+ cleanup()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ process.chdir(pkg)
+}
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
diff --git a/test/tap/bitbucket-shortcut.js b/test/tap/bitbucket-shortcut.js
new file mode 100644
index 000000000..51afe1992
--- /dev/null
+++ b/test/tap/bitbucket-shortcut.js
@@ -0,0 +1,81 @@
+'use strict'
+var fs = require('graceful-fs')
+var path = require('path')
+
+var mkdirp = require('mkdirp')
+var osenv = require('osenv')
+var requireInject = require('require-inject')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var common = require('../common-tap.js')
+
+var pkg = path.resolve(__dirname, 'bitbucket-shortcut')
+
+var json = {
+ name: 'bitbucket-shortcut',
+ version: '0.0.0'
+}
+
+test('setup', function (t) {
+ setup()
+ t.end()
+})
+
+test('bitbucket-shortcut', function (t) {
+ var cloneUrls = [
+ ['git@bitbucket.org:foo/private.git', 'Bitbucket shortcuts try SSH first'],
+ ['https://bitbucket.org/foo/private.git', 'Bitbucket shortcuts try HTTPS 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())
+ })
+ }
+ }
+ })
+
+ var opts = {
+ cache: path.resolve(pkg, 'cache'),
+ prefix: pkg,
+ registry: common.registry,
+ loglevel: 'silent'
+ }
+ npm.load(opts, function (er) {
+ t.ifError(er, 'npm loaded without error')
+ npm.commands.install(['bitbucket:foo/private'], function (er) {
+ t.ok(er, 'mocked install failed as expected')
+ t.end()
+ })
+ })
+})
+
+test('cleanup', function (t) {
+ cleanup()
+ t.end()
+})
+
+function setup () {
+ cleanup()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ process.chdir(pkg)
+}
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
diff --git a/test/tap/gist-short-shortcut-package.js b/test/tap/gist-short-shortcut-package.js
new file mode 100644
index 000000000..bf19bc684
--- /dev/null
+++ b/test/tap/gist-short-shortcut-package.js
@@ -0,0 +1,84 @@
+'use strict'
+var fs = require('graceful-fs')
+var path = require('path')
+
+var mkdirp = require('mkdirp')
+var osenv = require('osenv')
+var requireInject = require('require-inject')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var common = require('../common-tap.js')
+
+var pkg = path.resolve(__dirname, 'gist-short-shortcut-package')
+
+var json = {
+ name: 'gist-short-shortcut-package',
+ version: '0.0.0',
+ dependencies: {
+ 'private-gist': 'gist:deadbeef'
+ }
+}
+
+test('setup', function (t) {
+ setup()
+ t.end()
+})
+
+test('gist-short-shortcut-package', function (t) {
+ var cloneUrls = [
+ ['git://gist.github.com/deadbeef.git', 'GitHub gist shortcuts try git URLs first'],
+ ['git@gist.github.com:/deadbeef.git', 'GitHub gist shortcuts try SSH second'],
+ ['https://gist.github.com/deadbeef.git', 'GitHub gist shortcuts try HTTPS URLs third']
+ ]
+ 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())
+ })
+ }
+ }
+ })
+
+ var opts = {
+ cache: path.resolve(pkg, 'cache'),
+ prefix: pkg,
+ registry: common.registry,
+ loglevel: 'silent'
+ }
+ npm.load(opts, function (er) {
+ t.ifError(er, 'npm loaded without error')
+ npm.commands.install([], function (er, result) {
+ t.ok(er, 'mocked install failed as expected')
+ t.end()
+ })
+ })
+})
+
+test('cleanup', function (t) {
+ cleanup()
+ t.end()
+})
+
+function setup () {
+ cleanup()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ process.chdir(pkg)
+}
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
diff --git a/test/tap/gist-short-shortcut.js b/test/tap/gist-short-shortcut.js
new file mode 100644
index 000000000..0a1d322b0
--- /dev/null
+++ b/test/tap/gist-short-shortcut.js
@@ -0,0 +1,81 @@
+'use strict'
+var fs = require('graceful-fs')
+var path = require('path')
+
+var mkdirp = require('mkdirp')
+var osenv = require('osenv')
+var requireInject = require('require-inject')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var common = require('../common-tap.js')
+
+var pkg = path.resolve(__dirname, 'gist-short-shortcut')
+
+var json = {
+ name: 'gist-short-shortcut',
+ version: '0.0.0'
+}
+
+test('setup', function (t) {
+ setup()
+ t.end()
+})
+
+test('gist-shortcut', function (t) {
+ var cloneUrls = [
+ ['git://gist.github.com/deadbeef.git', 'GitHub gist shortcuts try git URLs first'],
+ ['git@gist.github.com:/deadbeef.git', 'GitHub gist shortcuts try SSH second'],
+ ['https://gist.github.com/deadbeef.git', 'GitHub gist shortcuts try HTTPS URLs third']
+ ]
+ 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())
+ })
+ }
+ }
+ })
+
+ var opts = {
+ cache: path.resolve(pkg, 'cache'),
+ prefix: pkg,
+ registry: common.registry,
+ loglevel: 'silent'
+ }
+ npm.load(opts, function (er) {
+ t.ifError(er, 'npm loaded without error')
+ npm.commands.install(['gist:deadbeef'], function (er, result) {
+ t.ok(er, 'mocked install failed as expected')
+ t.end()
+ })
+ })
+})
+
+test('cleanup', function (t) {
+ cleanup()
+ t.end()
+})
+
+function setup () {
+ cleanup()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ process.chdir(pkg)
+}
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
diff --git a/test/tap/gist-shortcut-package.js b/test/tap/gist-shortcut-package.js
new file mode 100644
index 000000000..2d7664ad5
--- /dev/null
+++ b/test/tap/gist-shortcut-package.js
@@ -0,0 +1,84 @@
+'use strict'
+var fs = require('graceful-fs')
+var path = require('path')
+
+var mkdirp = require('mkdirp')
+var osenv = require('osenv')
+var requireInject = require('require-inject')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var common = require('../common-tap.js')
+
+var pkg = path.resolve(__dirname, 'gist-shortcut-package')
+
+var json = {
+ name: 'gist-shortcut-package',
+ version: '0.0.0',
+ dependencies: {
+ 'private-gist': 'gist:foo/deadbeef'
+ }
+}
+
+test('setup', function (t) {
+ setup()
+ t.end()
+})
+
+test('gist-shortcut-package', function (t) {
+ var cloneUrls = [
+ ['git://gist.github.com/deadbeef.git', 'GitHub gist shortcuts try git URLs first'],
+ ['git@gist.github.com:/deadbeef.git', 'GitHub gist shortcuts try SSH second'],
+ ['https://gist.github.com/deadbeef.git', 'GitHub gist shortcuts try HTTPS URLs third']
+ ]
+ 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())
+ })
+ }
+ }
+ })
+
+ var opts = {
+ cache: path.resolve(pkg, 'cache'),
+ prefix: pkg,
+ registry: common.registry,
+ loglevel: 'silent'
+ }
+ npm.load(opts, function (er) {
+ t.ifError(er, 'npm loaded without error')
+ npm.commands.install([], function (er, result) {
+ t.ok(er, 'mocked install failed as expected')
+ t.end()
+ })
+ })
+})
+
+test('cleanup', function (t) {
+ cleanup()
+ t.end()
+})
+
+function setup () {
+ cleanup()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ process.chdir(pkg)
+}
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
diff --git a/test/tap/gist-shortcut.js b/test/tap/gist-shortcut.js
new file mode 100644
index 000000000..8cbb3ad62
--- /dev/null
+++ b/test/tap/gist-shortcut.js
@@ -0,0 +1,81 @@
+'use strict'
+var fs = require('graceful-fs')
+var path = require('path')
+
+var mkdirp = require('mkdirp')
+var osenv = require('osenv')
+var requireInject = require('require-inject')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var common = require('../common-tap.js')
+
+var pkg = path.resolve(__dirname, 'gist-shortcut')
+
+var json = {
+ name: 'gist-shortcut',
+ version: '0.0.0'
+}
+
+test('setup', function (t) {
+ setup()
+ t.end()
+})
+
+test('gist-shortcut', function (t) {
+ var cloneUrls = [
+ ['git://gist.github.com/deadbeef.git', 'GitHub gist shortcuts try git URLs first'],
+ ['git@gist.github.com:/deadbeef.git', 'GitHub gist shortcuts try SSH second'],
+ ['https://gist.github.com/deadbeef.git', 'GitHub gist shortcuts try HTTPS URLs third']
+ ]
+ 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())
+ })
+ }
+ }
+ })
+
+ var opts = {
+ cache: path.resolve(pkg, 'cache'),
+ prefix: pkg,
+ registry: common.registry,
+ loglevel: 'silent'
+ }
+ npm.load(opts, function (er) {
+ t.ifError(er, 'npm loaded without error')
+ npm.commands.install(['gist:foo/deadbeef'], function (er, result) {
+ t.ok(er, 'mocked install failed as expected')
+ t.end()
+ })
+ })
+})
+
+test('cleanup', function (t) {
+ cleanup()
+ t.end()
+})
+
+function setup () {
+ cleanup()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ process.chdir(pkg)
+}
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
diff --git a/test/tap/github-shortcut-package.js b/test/tap/github-shortcut-package.js
new file mode 100644
index 000000000..11f4dabdc
--- /dev/null
+++ b/test/tap/github-shortcut-package.js
@@ -0,0 +1,84 @@
+'use strict'
+var fs = require('graceful-fs')
+var path = require('path')
+
+var mkdirp = require('mkdirp')
+var osenv = require('osenv')
+var requireInject = require('require-inject')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var common = require('../common-tap.js')
+
+var pkg = path.resolve(__dirname, 'github-shortcut-package')
+
+var json = {
+ name: 'github-shortcut-package',
+ version: '0.0.0',
+ dependencies: {
+ 'private': 'foo/private'
+ }
+}
+
+test('setup', function (t) {
+ setup()
+ t.end()
+})
+
+test('github-shortcut-package', function (t) {
+ var cloneUrls = [
+ ['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': {
+ '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())
+ })
+ }
+ }
+ })
+
+ var opts = {
+ cache: path.resolve(pkg, 'cache'),
+ prefix: pkg,
+ registry: common.registry,
+ loglevel: 'silent'
+ }
+ npm.load(opts, function (er) {
+ t.ifError(er, 'npm loaded without error')
+ npm.commands.install([], function (er, result) {
+ t.ok(er, 'mocked install failed as expected')
+ t.end()
+ })
+ })
+})
+
+test('cleanup', function (t) {
+ cleanup()
+ t.end()
+})
+
+function setup () {
+ cleanup()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ process.chdir(pkg)
+}
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
diff --git a/test/tap/github-shortcut.js b/test/tap/github-shortcut.js
index e95b8bdfb..4849c680e 100644
--- a/test/tap/github-shortcut.js
+++ b/test/tap/github-shortcut.js
@@ -1,12 +1,32 @@
'use strict'
+var fs = require('graceful-fs')
+var path = require('path')
+
+var mkdirp = require('mkdirp')
+var osenv = require('osenv')
var requireInject = require('require-inject')
+var rimraf = require('rimraf')
var test = require('tap').test
+var common = require('../common-tap.js')
+
+var pkg = path.resolve(__dirname, 'github-shortcut')
+
+var json = {
+ name: 'github-shortcut',
+ version: '0.0.0'
+}
+
+test('setup', function (t) {
+ setup()
+ t.end()
+})
+
test('github-shortcut', function (t) {
var cloneUrls = [
- ['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']
+ ['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': {
@@ -25,9 +45,37 @@ test('github-shortcut', function (t) {
}
})
- npm.load({loglevel: 'silent'}, function () {
+ var opts = {
+ cache: path.resolve(pkg, 'cache'),
+ prefix: pkg,
+ registry: common.registry,
+ loglevel: 'silent'
+ }
+ npm.load(opts, function (er) {
+ t.ifError(er, 'npm loaded without error')
npm.commands.install(['foo/private'], function (er, result) {
+ t.ok(er, 'mocked install failed as expected')
t.end()
})
})
})
+
+test('cleanup', function (t) {
+ cleanup()
+ t.end()
+})
+
+function setup () {
+ cleanup()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ process.chdir(pkg)
+}
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
diff --git a/test/tap/gitlab-shortcut-package.js b/test/tap/gitlab-shortcut-package.js
new file mode 100644
index 000000000..657808447
--- /dev/null
+++ b/test/tap/gitlab-shortcut-package.js
@@ -0,0 +1,83 @@
+'use strict'
+var fs = require('graceful-fs')
+var path = require('path')
+
+var mkdirp = require('mkdirp')
+var osenv = require('osenv')
+var requireInject = require('require-inject')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var common = require('../common-tap.js')
+
+var pkg = path.resolve(__dirname, 'gitlab-shortcut-package')
+
+var json = {
+ name: 'gitlab-shortcut-package',
+ version: '0.0.0',
+ dependencies: {
+ 'private': 'gitlab:foo/private'
+ }
+}
+
+test('setup', function (t) {
+ setup()
+ t.end()
+})
+
+test('gitlab-shortcut-package', function (t) {
+ var cloneUrls = [
+ ['git@gitlab.com:foo/private.git', 'GitLab shortcuts try SSH first'],
+ ['https://gitlab.com/foo/private.git', 'GitLab shortcuts try HTTPS 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())
+ })
+ }
+ }
+ })
+
+ var opts = {
+ cache: path.resolve(pkg, 'cache'),
+ prefix: pkg,
+ registry: common.registry,
+ loglevel: 'silent'
+ }
+ npm.load(opts, function (er) {
+ t.ifError(er, 'npm loaded without error')
+ npm.commands.install([], function (er, result) {
+ t.ok(er, 'mocked install failed as expected')
+ t.end()
+ })
+ })
+})
+
+test('cleanup', function (t) {
+ cleanup()
+ t.end()
+})
+
+function setup () {
+ cleanup()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ process.chdir(pkg)
+}
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
diff --git a/test/tap/gitlab-shortcut.js b/test/tap/gitlab-shortcut.js
new file mode 100644
index 000000000..4a1e2b0bb
--- /dev/null
+++ b/test/tap/gitlab-shortcut.js
@@ -0,0 +1,80 @@
+'use strict'
+var fs = require('graceful-fs')
+var path = require('path')
+
+var mkdirp = require('mkdirp')
+var osenv = require('osenv')
+var requireInject = require('require-inject')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var common = require('../common-tap.js')
+
+var pkg = path.resolve(__dirname, 'gitlab-shortcut')
+
+var json = {
+ name: 'gitlab-shortcut',
+ version: '0.0.0'
+}
+
+test('setup', function (t) {
+ setup()
+ t.end()
+})
+
+test('gitlab-shortcut', function (t) {
+ var cloneUrls = [
+ ['git@gitlab.com:foo/private.git', 'GitLab shortcuts try SSH first'],
+ ['https://gitlab.com/foo/private.git', 'GitLab shortcuts try HTTPS 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())
+ })
+ }
+ }
+ })
+
+ var opts = {
+ cache: path.resolve(pkg, 'cache'),
+ prefix: pkg,
+ registry: common.registry,
+ loglevel: 'silent'
+ }
+ npm.load(opts, function (er) {
+ t.ifError(er, 'npm loaded without error')
+ npm.commands.install(['gitlab:foo/private'], function (er, result) {
+ t.ok(er, 'mocked install failed as expected')
+ t.end()
+ })
+ })
+})
+
+test('cleanup', function (t) {
+ cleanup()
+ t.end()
+})
+
+function setup () {
+ cleanup()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ process.chdir(pkg)
+}
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}