diff options
author | smikes <smikes@cubane.com> | 2014-12-20 15:53:48 +0300 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2015-03-06 06:49:48 +0300 |
commit | c618eeda3e321fd454d77c476b53a0330f2344cc (patch) | |
tree | fb07ad8e891781a9b05329c1cf8066fc6b5e8750 /test | |
parent | 7ea564ab4065f77e49f42cb057f4000f21124a9c (diff) |
install: don't try to --link git dependencies
test sets up git repo & mock registry -- fragile
test of install --link=false
test of install --link=true
Diffstat (limited to 'test')
-rw-r--r-- | test/tap/git-dependency-install-link.js | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/test/tap/git-dependency-install-link.js b/test/tap/git-dependency-install-link.js new file mode 100644 index 000000000..2d382dd56 --- /dev/null +++ b/test/tap/git-dependency-install-link.js @@ -0,0 +1,184 @@ +var fs = require('fs') +var resolve = require('path').resolve + +var chain = require('slide').chain +var osenv = require('osenv') +var mkdirp = require('mkdirp') +var rimraf = require('rimraf') +var test = require('tap').test +var readJson = require('read-package-json') +var mr = require('npm-registry-mock') + +var npm = require('../../lib/npm.js') +var common = require('../common-tap.js') + +var pkg = resolve(__dirname, 'git-dependency-install-link') +var repo = resolve(__dirname, 'git-dependency-install-link-repo') +var cache = resolve(pkg, 'cache') + +var daemon +var daemonPID +var git +var mockRegistry + +var EXEC_OPTS = { + registry: common.registry, + cwd: pkg, + cache: cache +} + +test('setup', function (t) { + bootstrap() + setup(function (er, r) { + t.ifError(er, 'git started up successfully') + + if (!er) { + daemon = r[r.length - 2] + daemonPID = r[r.length - 1] + } + + mr({ + port: common.port + }, function (er, server) { + t.ifError(er, 'started mock registry') + mockRegistry = server + + t.end() + }) + }) +}) + +test('install from git repo [no --link]', function (t) { + process.chdir(pkg) + + common.npm(['install', '--loglevel', 'error'], EXEC_OPTS, function (err, code, stdout, stderr) { + t.ifError(err, 'npm install failed') + + t.dissimilar(stderr, /Command failed:/, 'expect git to succeed') + t.dissimilar(stderr, /version not found/, 'should not go to repository') + + readJson(resolve(pkg, 'node_modules', 'child', 'package.json'), function (err, data) { + t.ifError(err, 'error reading child package.json') + + t.equal(data && data.version, '1.0.3') + t.end() + }) + }) +}) + +test('install from git repo [with --link]', function (t) { + process.chdir(pkg) + rimraf.sync(resolve(pkg, 'node_modules')) + + common.npm(['install', '--link', '--loglevel', 'error'], EXEC_OPTS, function (err, code, stdout, stderr) { + t.ifError(err, 'npm install --link failed') + + t.dissimilar(stderr, /Command failed:/, 'expect git to succeed') + t.dissimilar(stderr, /version not found/, 'should not go to repository') + + readJson(resolve(pkg, 'node_modules', 'child', 'package.json'), function (err, data) { + t.ifError(err, 'error reading child package.json') + + t.equal(data && data.version, '1.0.3') + t.end() + }) + }) +}) + +test('clean', function (t) { + mockRegistry.close() + daemon.on('close', function () { + cleanup() + t.end() + }) + process.kill(daemonPID) +}) + +var pjParent = JSON.stringify({ + name: 'parent', + version: '1.2.3', + dependencies: { + 'child': 'git://localhost:1234/child.git' + } +}, null, 2) + '\n' + +var pjChild = JSON.stringify({ + name: 'child', + version: '1.0.3' +}, null, 2) + '\n' + +function bootstrap () { + rimraf.sync(repo) + rimraf.sync(pkg) + mkdirp.sync(pkg) + mkdirp.sync(cache) + + fs.writeFileSync(resolve(pkg, 'package.json'), pjParent) +} + +function setup (cb) { + mkdirp.sync(repo) + fs.writeFileSync(resolve(repo, 'package.json'), pjChild) + npm.load({ + link: true, + prefix: pkg, + loglevel: 'silent' + }, function () { + git = require('../../lib/utils/git.js') + + function startDaemon (cb) { + // start git server + var d = git.spawn( + [ + 'daemon', + '--verbose', + '--listen=localhost', + '--export-all', + '--base-path=.', + '--port=1234' + ], + { + cwd: pkg, + env: process.env, + stdio: ['pipe', 'pipe', 'pipe'] + } + ) + d.stderr.on('data', childFinder) + + function childFinder (c) { + var cpid = c.toString().match(/^\[(\d+)\]/) + if (cpid[1]) { + this.removeListener('data', childFinder) + cb(null, [d, cpid[1]]) + } + } + } + + var opts = { + cwd: repo, + env: process.env + } + + chain( + [ + git.chainableExec(['init'], opts), + git.chainableExec(['config', 'user.name', 'PhantomFaker'], opts), + git.chainableExec(['config', 'user.email', 'nope@not.real'], opts), + git.chainableExec(['add', 'package.json'], opts), + git.chainableExec(['commit', '-m', 'stub package'], opts), + git.chainableExec( + ['clone', '--bare', repo, 'child.git'], + { cwd: pkg, env: process.env } + ), + startDaemon + ], + cb + ) + }) +} + +function cleanup () { + process.chdir(osenv.tmpdir()) + rimraf.sync(repo) + rimraf.sync(pkg) +} |