• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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: 'gitlab-shortcut',
14  version: '0.0.0'
15}
16
17test('gitlab-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    ['https://gitlab.com/foo/private.git', 'GitLab shortcuts try HTTPS URLs second'],
25    ['ssh://git@gitlab.com/foo/private.git', 'GitLab shortcuts try SSH first']
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('execFile mock fails on purpose'))
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(['gitlab:foo/private'], function (er, result) {
53      t.ok(er, 'mocked install failed as expected')
54      t.end()
55    })
56  })
57})
58