1var fs = require('fs') 2var resolve = require('path').resolve 3 4var mkdirp = require('mkdirp') 5var test = require('tap').test 6 7var npm = require('../../lib/npm.js') 8var common = require('../common-tap.js') 9 10var pkg = resolve(common.pkg, 'package') 11var repo = resolve(pkg, 'repo') 12 13var daemon 14var daemonPID 15var git 16 17var pjParent = JSON.stringify({ 18 name: 'parent', 19 version: '1.2.3', 20 dependencies: { 21 child: 'git://localhost:' + common.gitPort + '/child.git' 22 } 23}, null, 2) + '\n' 24 25var pjChild = JSON.stringify({ 26 name: 'child', 27 version: '1.0.3' 28}, null, 2) + '\n' 29 30test('setup', function (t) { 31 mkdirp.sync(pkg) 32 fs.writeFileSync(resolve(pkg, 'package.json'), pjParent) 33 setup(function (er, r) { 34 t.ifError(er, 'git started up successfully') 35 36 if (!er) { 37 daemon = r[r.length - 2] 38 daemonPID = r[r.length - 1] 39 } 40 41 t.end() 42 }) 43}) 44 45test('install from repo', function (t) { 46 process.chdir(pkg) 47 npm.commands.install('.', [], function (er) { 48 t.ifError(er, 'npm installed via git') 49 t.end() 50 }) 51}) 52 53test('clean', function (t) { 54 daemon.on('close', t.end) 55 process.kill(daemonPID) 56}) 57 58function 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 function startDaemon (cb) { 65 // start git server 66 var d = git.spawn( 67 [ 68 'daemon', 69 '--verbose', 70 '--listen=localhost', 71 '--export-all', 72 '--base-path=.', 73 '--reuseaddr', 74 '--port=' + common.gitPort 75 ], 76 { 77 cwd: pkg, 78 env: process.env, 79 stdio: ['pipe', 1, 'pipe'] 80 } 81 ) 82 d.stderr.on('data', childFinder) 83 84 function childFinder (c) { 85 var cpid = c.toString().match(/^\[(\d+)\]/) 86 if (cpid[1]) { 87 this.removeListener('data', childFinder) 88 cb(null, [d, cpid[1]]) 89 } 90 } 91 } 92 93 common.makeGitRepo({ 94 path: repo, 95 commands: [ 96 git.chainableExec( 97 ['clone', '--bare', repo, 'child.git'], 98 { cwd: pkg, env: process.env } 99 ), 100 startDaemon 101 ] 102 }, cb) 103 }) 104} 105