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