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: 'github-shortcut-package', 14 version: '0.0.0', 15 dependencies: { 16 'private': 'foo/private' 17 } 18} 19 20test('github-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 ['git://github.com/foo/private.git', 'GitHub shortcuts try git URLs first'], 28 ['https://github.com/foo/private.git', 'GitHub shortcuts try HTTPS URLs second'], 29 ['ssh://git@github.com/foo/private.git', 'GitHub shortcuts try SSH third'] 30 ] 31 var npm = requireInject.installGlobally('../../lib/npm.js', { 32 'child_process': { 33 'execFile': function (cmd, args, options, cb) { 34 process.nextTick(function () { 35 if (args.indexOf('clone') === -1) return cb(null, '', '') 36 var cloneUrl = cloneUrls.shift() 37 if (cloneUrl) { 38 t.is(args[args.length - 2], cloneUrl[0], cloneUrl[1]) 39 } else { 40 t.fail('too many attempts to clone') 41 } 42 cb(new Error()) 43 }) 44 } 45 } 46 }) 47 48 var opts = { 49 cache: common.cache, 50 prefix: pkg, 51 registry: common.registry, 52 loglevel: 'silent' 53 } 54 npm.load(opts, function (er) { 55 t.ifError(er, 'npm loaded without error') 56 npm.commands.install([], function (er, result) { 57 t.ok(er, 'mocked install failed as expected') 58 t.end() 59 }) 60 }) 61}) 62