]> 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-file.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-file.js
1 var fs = require('fs')
2 var resolve = require('path').resolve
3 var url = require('url')
4
5 var osenv = require('osenv')
6 var mkdirp = require('mkdirp')
7 var rimraf = require('rimraf')
8 var test = require('tap').test
9
10 var npm = require('../../lib/npm.js')
11 var common = require('../common-tap.js')
12
13 var pkg = resolve(__dirname, 'add-remote-git-file')
14 var repo = resolve(__dirname, 'add-remote-git-file-repo')
15
16 var git
17 var cloneURL = 'git+file://' + resolve(pkg, 'child.git')
18
19 var pjChild = JSON.stringify({
20   name: 'child',
21   version: '1.0.3'
22 }, null, 2) + '\n'
23
24 test('setup', function (t) {
25   bootstrap()
26   setup(function (er, r) {
27     t.ifError(er, 'git started up successfully')
28
29     t.end()
30   })
31 })
32
33 test('cache from repo', function (t) {
34   process.chdir(pkg)
35   var addRemoteGit = require('../../lib/cache/add-remote-git.js')
36   addRemoteGit(cloneURL, function (er, data) {
37     t.ifError(er, 'cached via git')
38     t.equal(
39       url.parse(data._resolved).protocol,
40       'git+file:',
41       'npm didn\'t go crazy adding git+git+git+git'
42     )
43
44     t.end()
45   })
46 })
47
48 test('clean', function (t) {
49   cleanup()
50   t.end()
51 })
52
53 function bootstrap () {
54   cleanup()
55   mkdirp.sync(pkg)
56 }
57
58 function setup (cb) {
59   mkdirp.sync(repo)
60   fs.writeFileSync(resolve(repo, 'package.json'), pjChild)
61   npm.load({ registry: common.registry, loglevel: 'silent' }, function () {
62     git = require('../../lib/utils/git.js')
63
64     common.makeGitRepo({
65       path: repo,
66       commands: [git.chainableExec(
67         ['clone', '--bare', repo, 'child.git'],
68         { cwd: pkg, env: process.env }
69       )]
70     }, cb)
71   })
72 }
73
74 function cleanup () {
75   process.chdir(osenv.tmpdir())
76   rimraf.sync(repo)
77   rimraf.sync(pkg)
78 }