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