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