]> 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-shrinkwrap.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-shrinkwrap.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-shrinkwrap')
13 var repo = resolve(__dirname, 'add-remote-git-shrinkwrap-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#master'
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('shrinkwrap gets correct _from and _resolved (#7121)', function (t) {
56   common.npm(
57     [
58       'shrinkwrap',
59       '--loglevel', 'silent'
60     ],
61     { cwd: pkg },
62     function (er, code, stdout, stderr) {
63       t.ifError(er, 'npm shrinkwrapped without errors')
64       t.notOk(code, '`npm shrinkwrap` exited with 0')
65       t.equal(stdout.trim(), 'wrote npm-shrinkwrap.json')
66       t.notOk(stderr, 'no error output on successful shrinkwrap')
67
68       var shrinkwrap = require(resolve(pkg, 'npm-shrinkwrap.json'))
69       t.equal(
70         shrinkwrap.dependencies.child.from,
71         'git://localhost:1234/child.git#master',
72         'npm shrinkwrapped from correctly'
73       )
74
75       git.whichAndExec(
76         ['rev-list', '-n1', 'master'],
77         { cwd: repo, env: process.env },
78         function (er, stdout, stderr) {
79           t.ifErr(er, 'git rev-list ran without error')
80           t.notOk(stderr, 'no error output')
81           var treeish = stdout.trim()
82
83           t.equal(
84             shrinkwrap.dependencies.child.resolved,
85             'git://localhost:1234/child.git#' + treeish,
86             'npm shrinkwrapped resolved correctly'
87           )
88
89           t.end()
90         }
91       )
92     }
93   )
94 })
95
96 test('clean', function (t) {
97   daemon.on('close', function () {
98     cleanup()
99     t.end()
100   })
101   process.kill(daemonPID)
102 })
103
104 function bootstrap () {
105   mkdirp.sync(pkg)
106   fs.writeFileSync(resolve(pkg, 'package.json'), pjParent)
107 }
108
109 function setup (cb) {
110   mkdirp.sync(repo)
111   fs.writeFileSync(resolve(repo, 'package.json'), pjChild)
112   npm.load({ prefix: pkg, registry: common.registry, loglevel: 'silent' }, function () {
113     git = require('../../lib/utils/git.js')
114
115     function startDaemon (cb) {
116       // start git server
117       var d = git.spawn(
118         [
119           'daemon',
120           '--verbose',
121           '--listen=localhost',
122           '--export-all',
123           '--base-path=.',
124           '--reuseaddr',
125           '--port=1234'
126         ],
127         {
128           cwd: pkg,
129           env: process.env,
130           stdio: ['pipe', 'pipe', 'pipe']
131         }
132       )
133       d.stderr.on('data', childFinder)
134
135       function childFinder (c) {
136         var cpid = c.toString().match(/^\[(\d+)\]/)
137         if (cpid[1]) {
138           this.removeListener('data', childFinder)
139           cb(null, [d, cpid[1]])
140         }
141       }
142     }
143
144     common.makeGitRepo({
145       path: repo,
146       commands: [
147         git.chainableExec(
148           ['clone', '--bare', repo, 'child.git'],
149           { cwd: pkg, env: process.env }
150         ),
151         startDaemon
152       ]
153     }, cb)
154   })
155 }
156
157 function cleanup () {
158   process.chdir(osenv.tmpdir())
159   rimraf.sync(repo)
160   rimraf.sync(pkg)
161 }