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