]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/test/tap/gitlab-shortcut.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / test / tap / gitlab-shortcut.js
1 'use strict'
2 var fs = require('graceful-fs')
3 var path = require('path')
4
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
10
11 var common = require('../common-tap.js')
12
13 var pkg = path.resolve(__dirname, 'gitlab-shortcut')
14
15 var json = {
16   name: 'gitlab-shortcut',
17   version: '0.0.0'
18 }
19
20 test('setup', function (t) {
21   setup()
22   t.end()
23 })
24
25 test('gitlab-shortcut', function (t) {
26   var cloneUrls = [
27     ['git@gitlab.com:foo/private.git', 'GitLab shortcuts try SSH first'],
28     ['https://gitlab.com/foo/private.git', 'GitLab shortcuts try HTTPS URLs second']
29   ]
30   var npm = requireInject.installGlobally('../../lib/npm.js', {
31     'child_process': {
32       'execFile': function (cmd, args, options, cb) {
33         process.nextTick(function () {
34           if (args[0] !== 'clone') return cb(null, '', '')
35           var cloneUrl = cloneUrls.shift()
36           if (cloneUrl) {
37             t.is(args[3], cloneUrl[0], cloneUrl[1])
38           } else {
39             t.fail('too many attempts to clone')
40           }
41           cb(new Error())
42         })
43       }
44     }
45   })
46
47   var opts = {
48     cache: path.resolve(pkg, 'cache'),
49     prefix: pkg,
50     registry: common.registry,
51     loglevel: 'silent'
52   }
53   npm.load(opts, function (er) {
54     t.ifError(er, 'npm loaded without error')
55     npm.commands.install(['gitlab:foo/private'], function (er, result) {
56       t.ok(er, 'mocked install failed as expected')
57       t.end()
58     })
59   })
60 })
61
62 test('cleanup', function (t) {
63   cleanup()
64   t.end()
65 })
66
67 function setup () {
68   cleanup()
69   mkdirp.sync(pkg)
70   fs.writeFileSync(
71     path.join(pkg, 'package.json'),
72     JSON.stringify(json, null, 2)
73   )
74   process.chdir(pkg)
75 }
76
77 function cleanup () {
78   process.chdir(osenv.tmpdir())
79   rimraf.sync(pkg)
80 }