2 var fs = require('graceful-fs')
3 var path = require('path')
5 var mkdirp = require('mkdirp')
6 var osenv = require('osenv')
7 var requireInject = require('require-inject')
8 var rimraf = require('rimraf')
9 var test = require('tap').test
11 var common = require('../common-tap.js')
13 var pkg = path.resolve(__dirname, 'gist-shortcut')
16 name: 'gist-shortcut',
20 test('setup', function (t) {
25 test('gist-shortcut', function (t) {
27 ['git://gist.github.com/deadbeef.git', 'GitHub gist shortcuts try git URLs first'],
28 ['https://gist.github.com/deadbeef.git', 'GitHub gist shortcuts try HTTPS URLs second'],
29 ['git@gist.github.com:/deadbeef.git', 'GitHub gist shortcuts try SSH third']
31 var npm = requireInject.installGlobally('../../lib/npm.js', {
33 'execFile': function (cmd, args, options, cb) {
34 process.nextTick(function () {
35 if (args[0] !== 'clone') return cb(null, '', '')
36 var cloneUrl = cloneUrls.shift()
38 t.is(args[3], cloneUrl[0], cloneUrl[1])
40 t.fail('too many attempts to clone')
49 cache: path.resolve(pkg, 'cache'),
51 registry: common.registry,
54 npm.load(opts, function (er) {
55 t.ifError(er, 'npm loaded without error')
56 npm.commands.install(['gist:foo/deadbeef'], function (er, result) {
57 t.ok(er, 'mocked install failed as expected')
63 test('cleanup', function (t) {
72 path.join(pkg, 'package.json'),
73 JSON.stringify(json, null, 2)
79 process.chdir(osenv.tmpdir())