1'use strict' 2var fs = require('graceful-fs') 3var path = require('path') 4 5var requireInject = require('require-inject') 6var test = require('tap').test 7 8var common = require('../common-tap.js') 9 10var pkg = common.pkg 11 12var json = { 13 name: 'gitlab-shortcut-package', 14 version: '0.0.0', 15 dependencies: { 16 'private': 'gitlab:foo/private' 17 } 18} 19 20test('gitlab-shortcut-package', function (t) { 21 fs.writeFileSync( 22 path.join(pkg, 'package.json'), 23 JSON.stringify(json, null, 2) 24 ) 25 process.chdir(pkg) 26 var cloneUrls = [ 27 ['https://gitlab.com/foo/private.git', 'GitLab shortcuts try HTTPS URLs second'], 28 ['ssh://git@gitlab.com/foo/private.git', 'GitLab shortcuts try SSH first'] 29 ] 30 var npm = requireInject.installGlobally('../../lib/npm.js', { 31 'child_process': { 32 'execFile': function (cmd, args, options, cb) { 33 process.nextTick(function () { 34 if (args.indexOf('clone') === -1) return cb(null, '', '') 35 var cloneUrl = cloneUrls.shift() 36 if (cloneUrl) { 37 t.is(args[args.length - 2], cloneUrl[0], cloneUrl[1]) 38 } else { 39 t.fail('too many attempts to clone') 40 } 41 cb(new Error()) 42 }) 43 } 44 } 45 }) 46 47 var opts = { 48 cache: common.cache, 49 prefix: pkg, 50 registry: common.registry, 51 loglevel: 'silent' 52 } 53 npm.load(opts, function (er) { 54 t.ifError(er, 'npm loaded without error') 55 npm.commands.install([], function (er, result) { 56 t.ok(er, 'mocked install failed as expected') 57 t.end() 58 }) 59 }) 60}) 61