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