2 var resolve = require('path').resolve
4 var osenv = require('osenv')
5 var mkdirp = require('mkdirp')
6 var rimraf = require('rimraf')
7 var test = require('tap').test
8 var readJson = require('read-package-json')
9 var mr = require('npm-registry-mock')
11 var npm = require('../../lib/npm.js')
12 var common = require('../common-tap.js')
14 var pkg = resolve(__dirname, 'git-dependency-install-link')
15 var repo = resolve(__dirname, 'git-dependency-install-link-repo')
16 var cache = resolve(pkg, 'cache')
24 registry: common.registry,
29 var pjParent = JSON.stringify({
33 'child': 'git://localhost:1234/child.git'
37 var pjChild = JSON.stringify({
43 test('setup', function (t) {
45 setup(function (er, r) {
46 t.ifError(er, 'git started up successfully')
49 daemon = r[r.length - 2]
50 daemonPID = r[r.length - 1]
55 }, function (er, server) {
56 t.ifError(er, 'started mock registry')
64 test('install from git repo [no --link]', function (t) {
67 common.npm(['install', '--loglevel', 'error'], EXEC_OPTS, function (err, code, stdout, stderr) {
68 t.ifError(err, 'npm install failed')
70 t.dissimilar(stderr, /Command failed:/, 'expect git to succeed')
71 t.dissimilar(stderr, /version not found/, 'should not go to repository')
73 readJson(resolve(pkg, 'node_modules', 'child', 'package.json'), function (err, data) {
74 t.ifError(err, 'error reading child package.json')
76 t.equal(data && data.version, '1.0.3')
82 test('install from git repo [with --link]', function (t) {
84 rimraf.sync(resolve(pkg, 'node_modules'))
86 common.npm(['install', '--link', '--loglevel', 'error'], EXEC_OPTS, function (err, code, stdout, stderr) {
87 t.ifError(err, 'npm install --link failed')
89 t.dissimilar(stderr, /Command failed:/, 'expect git to succeed')
90 t.dissimilar(stderr, /version not found/, 'should not go to repository')
92 readJson(resolve(pkg, 'node_modules', 'child', 'package.json'), function (err, data) {
93 t.ifError(err, 'error reading child package.json')
95 t.equal(data && data.version, '1.0.3')
101 test('clean', function (t) {
103 daemon.on('close', function () {
107 process.kill(daemonPID)
110 function bootstrap () {
116 fs.writeFileSync(resolve(pkg, 'package.json'), pjParent)
119 function setup (cb) {
121 fs.writeFileSync(resolve(repo, 'package.json'), pjChild)
127 git = require('../../lib/utils/git.js')
129 function startDaemon (cb) {
135 '--listen=localhost',
144 stdio: ['pipe', 'pipe', 'pipe']
147 d.stderr.on('data', childFinder)
149 function childFinder (c) {
150 var cpid = c.toString().match(/^\[(\d+)\]/)
152 this.removeListener('data', childFinder)
153 cb(null, [d, cpid[1]])
162 ['clone', '--bare', repo, 'child.git'],
163 { cwd: pkg, env: process.env }
171 function cleanup () {
172 process.chdir(osenv.tmpdir())