1'use strict' 2 3const BB = require('bluebird') 4 5const fs = require('graceful-fs') 6const path = require('path') 7 8const requireInject = require('require-inject') 9const test = require('tap').test 10 11const common = require('../common-tap.js') 12 13const pkg = common.pkg 14 15const json = { 16 name: 'github-shortcut', 17 version: '0.0.0' 18} 19 20test('github-shortcut', function (t) { 21 fs.writeFileSync( 22 path.join(pkg, 'package.json'), 23 JSON.stringify(json, null, 2) 24 ) 25 process.chdir(pkg) 26 const 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 const npm = requireInject.installGlobally('../../lib/npm.js', { 32 'pacote/lib/util/git': { 33 'revs': (repo, opts) => { 34 return BB.resolve().then(() => { 35 const cloneUrl = cloneUrls.shift() 36 if (cloneUrl) { 37 t.is(repo, cloneUrl[0], cloneUrl[1]) 38 } else { 39 t.fail('too many attempts to clone') 40 } 41 throw new Error('git.revs mock fails on purpose') 42 }) 43 } 44 } 45 }) 46 47 const opts = { 48 cache: common.cache, 49 prefix: pkg, 50 registry: common.registry, 51 loglevel: 'silent' 52 } 53 t.plan(2 + cloneUrls.length) 54 npm.load(opts, function (err) { 55 t.ifError(err, 'npm loaded without error') 56 npm.commands.install(['foo/private'], function (err, result) { 57 t.match(err.message, /mock fails on purpose/, 'mocked install failed as expected') 58 t.end() 59 }) 60 }) 61}) 62