diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2015-03-05 03:38:15 +0300 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2015-03-05 09:55:00 +0300 |
commit | 6823807bba6c00228a724e1205ae90d67df0adad (patch) | |
tree | 76bfe9bf0e72c2e50c1167da0d84ee3eaad100c8 /test | |
parent | 1b8ba7426393cbae2c76ad2c35953782d4401871 (diff) |
restore order to caching git remotes
Also, update code coments to be accurate, and extirpate single-letter
variable names. And introduce a params object because those argument
lists were completely ridiculous.
Diffstat (limited to 'test')
-rw-r--r-- | test/tap/add-remote-git-fake-windows.js | 4 | ||||
-rw-r--r-- | test/tap/add-remote-git-shrinkwrap.js | 171 |
2 files changed, 173 insertions, 2 deletions
diff --git a/test/tap/add-remote-git-fake-windows.js b/test/tap/add-remote-git-fake-windows.js index 305247792..b665f752a 100644 --- a/test/tap/add-remote-git-fake-windows.js +++ b/test/tap/add-remote-git-fake-windows.js @@ -58,7 +58,7 @@ var pjParent = JSON.stringify({ name : "parent", version : "1.2.3", dependencies : { - "child" : "git://localhost:1234/child.git" + "child" : "git://localhost:1233/child.git" } }, null, 2) + "\n" @@ -93,7 +93,7 @@ function setup (cb) { "--listen=localhost", "--export-all", "--base-path=.", - "--port=1234" + "--port=1233" ], { cwd : pkg, diff --git a/test/tap/add-remote-git-shrinkwrap.js b/test/tap/add-remote-git-shrinkwrap.js new file mode 100644 index 000000000..555dca213 --- /dev/null +++ b/test/tap/add-remote-git-shrinkwrap.js @@ -0,0 +1,171 @@ +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 npm = require('../../lib/npm.js') +var common = require('../common-tap.js') + +var pkg = resolve(__dirname, 'add-remote-git-shrinkwrap') +var repo = resolve(__dirname, 'add-remote-git-shrinkwrap-repo') + +var daemon +var daemonPID +var git + +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] + } + + t.end() + }) +}) + +test('install from repo', function (t) { + process.chdir(pkg) + npm.commands.install('.', [], function (er) { + t.ifError(er, 'npm installed via git') + + t.end() + }) +}) + +test('shrinkwrap gets correct _from and _resolved (#7121)', function (t) { + common.npm( + [ + 'shrinkwrap', + '--loglevel', 'silent' + ], + { cwd: pkg }, + function (er, code, stdout, stderr) { + t.ifError(er, 'npm shrinkwrapped without errors') + t.notOk(code, '`npm shrinkwrap` exited with 0') + t.equal(stdout.trim(), 'wrote npm-shrinkwrap.json') + t.notOk(stderr, 'no error output on successful shrinkwrap') + + var shrinkwrap = require(resolve(pkg, 'npm-shrinkwrap.json')) + t.equal( + shrinkwrap.dependencies.child.from, + 'git://localhost:1235/child.git#master', + 'npm shrinkwrapped from correctly' + ) + + git.whichAndExec( + ['rev-list', '-n1', 'master'], + { cwd: repo, env: process.env }, + function (er, stdout, stderr) { + t.ifErr(er, 'git rev-list ran without error') + t.notOk(stderr, 'no error output') + var treeish = stdout.trim() + + t.equal( + shrinkwrap.dependencies.child.resolved, + 'git://localhost:1235/child.git#' + treeish, + 'npm shrinkwrapped resolved correctly' + ) + + t.end() + } + ) + } + ) +}) + +test('clean', function (t) { + daemon.on('close', function () { + cleanup() + t.end() + }) + process.kill(daemonPID) +}) + +var pjParent = JSON.stringify({ + name: 'parent', + version: '1.2.3', + dependencies: { + 'child': 'git://localhost:1235/child.git#master' + } +}, null, 2) + '\n' + +var pjChild = JSON.stringify({ + name: 'child', + version: '1.0.3' +}, null, 2) + '\n' + +function bootstrap () { + mkdirp.sync(pkg) + fs.writeFileSync(resolve(pkg, 'package.json'), pjParent) +} + +function setup (cb) { + mkdirp.sync(repo) + fs.writeFileSync(resolve(repo, 'package.json'), pjChild) + npm.load({ prefix: pkg, registry: common.registry, 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=1235' + ], + { + 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) +} |