]> 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-fake-windows.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-fake-windows.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
33 test('setup', function (t) {
34   bootstrap()
35   setup(function (er, r) {
36     if (er) {
37       throw er
38     }
39
40     if (!er) {
41       daemon = r[r.length - 2]
42       daemonPID = r[r.length - 1]
43     }
44
45     t.end()
46   })
47 })
48
49 test('install from repo on \'Windows\'', function (t) {
50   // before we confuse everything by switching the platform
51   require('../../lib/install.js')
52   require('../../lib/unbuild.js')
53   process.platform = 'win32'
54   process.chdir(pkg)
55   npm.commands.install('.', [], function (er) {
56     t.ifError(er, 'npm installed via git')
57
58     t.end()
59   })
60 })
61
62 test('clean', function (t) {
63   daemon.on('close', function () {
64     cleanup()
65     t.end()
66   })
67   process.kill(daemonPID)
68 })
69
70 function bootstrap () {
71   rimraf.sync(pkg)
72   mkdirp.sync(pkg)
73   fs.writeFileSync(resolve(pkg, 'package.json'), pjParent)
74 }
75
76 function setup (cb) {
77   rimraf.sync(repo)
78   mkdirp.sync(repo)
79   fs.writeFileSync(resolve(repo, 'package.json'), pjChild)
80   npm.load({ registry: common.registry, loglevel: 'silent' }, function () {
81     // some really cheesy monkeypatching
82     require('module')._cache[require.resolve('which')] = {
83       exports: function (_, cb) { cb() }
84     }
85     git = require('../../lib/utils/git.js')
86
87     function startDaemon (cb) {
88       // start git server
89       var d = git.spawn(
90         [
91           'daemon',
92           '--verbose',
93           '--listen=localhost',
94           '--export-all',
95           '--base-path=.',
96           '--reuseaddr',
97           '--port=1234'
98         ],
99         {
100           cwd: pkg,
101           env: process.env,
102           stdio: ['pipe', 'pipe', 'pipe']
103         }
104       )
105       d.stderr.on('data', childFinder)
106
107       function childFinder (c) {
108         var cpid = c.toString().match(/^\[(\d+)\]/)
109         if (cpid[1]) {
110           this.removeListener('data', childFinder)
111           cb(null, [d, cpid[1]])
112         }
113       }
114     }
115
116     common.makeGitRepo({
117       path: repo,
118       commands: [
119         git.chainableExec(
120           ['clone', '--bare', repo, 'child.git'],
121           { cwd: pkg, env: process.env }
122         ),
123         startDaemon
124       ]
125     }, cb)
126   })
127 }
128
129 function cleanup () {
130   process.chdir(osenv.tmpdir())
131   rimraf.sync(repo)
132   rimraf.sync(pkg)
133 }