]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/test/tap/add-remote-git.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / test / tap / add-remote-git.js
1 var fs = require('fs')
2 var resolve = require('path').resolve
3
4 var osenv = require('osenv')
5 var mkdirp = require('mkdirp')
6 var rimraf = require('rimraf')
7 var test = require('tap').test
8
9 var npm = require('../../lib/npm.js')
10 var common = require('../common-tap.js')
11
12 var pkg = resolve(__dirname, 'add-remote-git')
13 var repo = resolve(__dirname, 'add-remote-git-repo')
14
15 var daemon
16 var daemonPID
17 var git
18
19 var pjParent = JSON.stringify({
20   name: 'parent',
21   version: '1.2.3',
22   dependencies: {
23     child: 'git://localhost:1234/child.git'
24   }
25 }, null, 2) + '\n'
26
27 var pjChild = JSON.stringify({
28   name: 'child',
29   version: '1.0.3'
30 }, null, 2) + '\n'
31
32 test('setup', function (t) {
33   bootstrap()
34   setup(function (er, r) {
35     t.ifError(er, 'git started up successfully')
36
37     if (!er) {
38       daemon = r[r.length - 2]
39       daemonPID = r[r.length - 1]
40     }
41
42     t.end()
43   })
44 })
45
46 test('install from repo', function (t) {
47   process.chdir(pkg)
48   npm.commands.install('.', [], function (er) {
49     t.ifError(er, 'npm installed via git')
50
51     t.end()
52   })
53 })
54
55 test('clean', function (t) {
56   daemon.on('close', function () {
57     cleanup()
58     t.end()
59   })
60   process.kill(daemonPID)
61 })
62
63 function bootstrap () {
64   mkdirp.sync(pkg)
65   fs.writeFileSync(resolve(pkg, 'package.json'), pjParent)
66 }
67
68 function setup (cb) {
69   mkdirp.sync(repo)
70   fs.writeFileSync(resolve(repo, 'package.json'), pjChild)
71   npm.load({ registry: common.registry, loglevel: 'silent' }, function () {
72     git = require('../../lib/utils/git.js')
73
74     function startDaemon (cb) {
75       // start git server
76       var d = git.spawn(
77         [
78           'daemon',
79           '--verbose',
80           '--listen=localhost',
81           '--export-all',
82           '--base-path=.',
83           '--reuseaddr',
84           '--port=1234'
85         ],
86         {
87           cwd: pkg,
88           env: process.env,
89           stdio: ['pipe', 'pipe', 'pipe']
90         }
91       )
92       d.stderr.on('data', childFinder)
93
94       function childFinder (c) {
95         var cpid = c.toString().match(/^\[(\d+)\]/)
96         if (cpid[1]) {
97           this.removeListener('data', childFinder)
98           cb(null, [d, cpid[1]])
99         }
100       }
101     }
102
103     common.makeGitRepo({
104       path: repo,
105       commands: [
106         git.chainableExec(
107           ['clone', '--bare', repo, 'child.git'],
108           { cwd: pkg, env: process.env }
109         ),
110         startDaemon
111       ]
112     }, cb)
113   })
114 }
115
116 function cleanup () {
117   process.chdir(osenv.tmpdir())
118   rimraf.sync(repo)
119   rimraf.sync(pkg)
120 }