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