diff options
author | Rebecca Turner <me@re-becca.org> | 2016-07-16 00:19:37 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2016-07-16 01:15:52 +0300 |
commit | d3bc78039db26c7188577a60c4294f3328db0448 (patch) | |
tree | 1a7ce30aa22856f4751a2ef842347374fafd8e11 /test/network | |
parent | 6e74c4f51f9dbcb17999e8cd9b70ff52da975702 (diff) |
test: separate the remaining network tests
PR-URL: https://github.com/npm/npm/pull/13397
Credit: @iarna
Reviewed-By: @othiym23
Diffstat (limited to 'test/network')
-rw-r--r-- | test/network/bearer-token-check.js | 118 | ||||
-rw-r--r-- | test/network/git-cache-locking.js | 45 | ||||
-rw-r--r-- | test/network/git-cache-no-hooks.js | 50 | ||||
-rw-r--r-- | test/network/it.js | 77 | ||||
-rw-r--r-- | test/network/legacy-bundled-git.js | 99 | ||||
-rw-r--r-- | test/network/legacy-optional-deps.js | 79 | ||||
-rw-r--r-- | test/network/legacy-shrinkwrap.js | 132 | ||||
-rw-r--r-- | test/network/legacy-url-dep.js | 59 | ||||
-rw-r--r-- | test/network/outdated-symlink.js | 103 | ||||
-rw-r--r-- | test/network/registry.js | 74 |
10 files changed, 836 insertions, 0 deletions
diff --git a/test/network/bearer-token-check.js b/test/network/bearer-token-check.js new file mode 100644 index 000000000..8ddbec29a --- /dev/null +++ b/test/network/bearer-token-check.js @@ -0,0 +1,118 @@ +var resolve = require('path').resolve +var writeFileSync = require('graceful-fs').writeFileSync + +var mkdirp = require('mkdirp') +var mr = require('npm-registry-mock') +var osenv = require('osenv') +var rimraf = require('rimraf') +var test = require('tap').test + +var common = require('../common-tap.js') +var toNerfDart = require('../../lib/config/nerf-dart.js') + +var pkg = resolve(__dirname, 'install-bearer-check') +var outfile = resolve(pkg, '_npmrc') +var modules = resolve(pkg, 'node_modules') +var tarballPath = '/scoped-underscore/-/scoped-underscore-1.3.1.tgz' +// needs to be a different hostname to verify tokens (not) being sent correctly +var tarballURL = 'http://lvh.me:' + common.port + tarballPath +var tarball = resolve(__dirname, '../fixtures/scoped-underscore-1.3.1.tgz') + +var server + +var EXEC_OPTS = { cwd: pkg } + +function mocks (server) { + var auth = 'Bearer 0xabad1dea' + server.get(tarballPath, { authorization: auth }).reply(403, { + error: 'token leakage', + reason: 'This token should not be sent.' + }) + server.get(tarballPath).replyWithFile(200, tarball) +} + +test('setup', function (t) { + mr({ port: common.port, plugin: mocks }, function (er, s) { + server = s + t.ok(s, 'set up mock registry') + setup() + t.end() + }) +}) + +test('authed npm install with tarball not on registry', function (t) { + common.npm( + [ + 'install', + '--loglevel', 'silent', + '--json', + '--fetch-retries', 0, + '--userconfig', outfile + ], + EXEC_OPTS, + function (err, code, stdout, stderr) { + t.ifError(err, 'test runner executed without error') + t.equal(code, 0, 'npm install exited OK') + t.notOk(stderr, 'no output on stderr') + try { + var results = JSON.parse(stdout) + } catch (ex) { + console.error('#', ex) + t.ifError(ex, 'stdout was valid JSON') + } + + if (results) { + var installedversion = { + 'version': '1.3.1', + 'from': '>=1.3.1 <2', + 'resolved': 'http://lvh.me:1337/scoped-underscore/-/scoped-underscore-1.3.1.tgz' + } + t.isDeeply(results.dependencies['@scoped/underscore'], installedversion, '@scoped/underscore installed') + } + + t.end() + } + ) +}) + +test('cleanup', function (t) { + server.close() + cleanup() + t.end() +}) + +var contents = '@scoped:registry=' + common.registry + '\n' + + toNerfDart(common.registry) + ':_authToken=0xabad1dea\n' + +var json = { + name: 'test-package-install', + version: '1.0.0' +} + +var shrinkwrap = { + name: 'test-package-install', + version: '1.0.0', + dependencies: { + '@scoped/underscore': { + resolved: tarballURL, + from: '>=1.3.1 <2', + version: '1.3.1' + } + } +} + +function setup () { + cleanup() + mkdirp.sync(modules) + writeFileSync(resolve(pkg, 'package.json'), JSON.stringify(json, null, 2) + '\n') + writeFileSync(outfile, contents) + writeFileSync( + resolve(pkg, 'npm-shrinkwrap.json'), + JSON.stringify(shrinkwrap, null, 2) + '\n' + ) +} + +function cleanup () { + process.chdir(osenv.tmpdir()) + rimraf.sync(pkg) +} diff --git a/test/network/git-cache-locking.js b/test/network/git-cache-locking.js new file mode 100644 index 000000000..29ab5709b --- /dev/null +++ b/test/network/git-cache-locking.js @@ -0,0 +1,45 @@ +var test = require('tap').test +var common = require('../common-tap') +var path = require('path') +var rimraf = require('rimraf') +var mkdirp = require('mkdirp') +var pkg = path.resolve(__dirname, 'git-cache-locking') +var tmp = path.join(pkg, 'tmp') +var cache = path.join(pkg, 'cache') +var shallowClone = Object.assign || require('util')._extend + +test('setup', function (t) { + rimraf.sync(pkg) + mkdirp.sync(path.resolve(pkg, 'node_modules')) + t.end() +}) + +test('git-cache-locking: install a git dependency', function (t) { + // disable git integration tests on Travis. + if (process.env.TRAVIS) return t.end() + + var gitEnv = shallowClone({}, process.env) + gitEnv.npm_config_cache = cache + gitEnv.npm_config_tmp = tmp + gitEnv.npm_config_prefix = pkg + gitEnv.npm_config_global = 'false' + + // package c depends on a.git#master and b.git#master + // package b depends on a.git#master + common.npm([ + 'install', + 'git://github.com/nigelzor/npm-4503-c.git' + ], { + cwd: pkg, + env: gitEnv + }, function (err, code, stdout, stderr) { + if (err) throw err + t.equal(0, code, 'npm install should succeed') + t.end() + }) +}) + +test('cleanup', function (t) { + rimraf.sync(pkg) + t.end() +}) diff --git a/test/network/git-cache-no-hooks.js b/test/network/git-cache-no-hooks.js new file mode 100644 index 000000000..0021064ce --- /dev/null +++ b/test/network/git-cache-no-hooks.js @@ -0,0 +1,50 @@ +var test = require('tap').test +var fs = require('fs') +var path = require('path') +var common = require('../common-tap.js') +var rimraf = require('rimraf') +var mkdirp = require('mkdirp') +var pkg = path.resolve(__dirname, 'git-cache-no-hooks') +var osenv = require('osenv') +var tmp = path.join(pkg, 'tmp') +var cache = path.join(pkg, 'cache') + +test('setup', function (t) { + rimraf.sync(pkg) + mkdirp.sync(pkg) + mkdirp.sync(cache) + mkdirp.sync(tmp) + mkdirp.sync(path.resolve(pkg, 'node_modules')) + t.end() +}) + +test('git-cache-no-hooks: install a git dependency', function (t) { + // disable git integration tests on Travis. + if (process.env.TRAVIS) return t.end() + + common.npm([ + 'install', 'git://github.com/nigelzor/npm-4503-a.git', + '--cache', cache, + '--tmp', tmp + ], { + cwd: pkg + }, function (err, code, stdout, stderr) { + t.ifErr(err, 'npm completed') + t.equal(stderr, '', 'no error output') + t.equal(code, 0, 'npm install should succeed') + + // verify permissions on git hooks + var repoDir = 'git-github-com-nigelzor-npm-4503-a-git-40c5cb24' + var hooksPath = path.join(cache, '_git-remotes', repoDir, 'hooks') + fs.readdir(hooksPath, function (err) { + t.equal(err && err.code, 'ENOENT', 'hooks are not brought along with repo') + t.end() + }) + }) +}) + +test('cleanup', function (t) { + process.chdir(osenv.tmpdir()) + rimraf.sync(pkg) + t.end() +}) diff --git a/test/network/it.js b/test/network/it.js new file mode 100644 index 000000000..6fc2a6fd4 --- /dev/null +++ b/test/network/it.js @@ -0,0 +1,77 @@ +var join = require('path').join +var statSync = require('graceful-fs').statSync +var writeFileSync = require('graceful-fs').writeFileSync + +var mkdirp = require('mkdirp') +var mr = require('npm-registry-mock') +var osenv = require('osenv') +var rimraf = require('rimraf') +var test = require('tap').test + +var common = require('../common-tap') + +var pkg = join(__dirname, 'run-script') +var installed = join(pkg, 'node_modules', 'underscore', 'package.json') + +var json = { + name: 'npm-it-test', + dependencies: { + underscore: '1.5.1' + }, + scripts: { + test: 'echo hax' + } +} + +var server + +test('run up the mock registry', function (t) { + mr({ port: common.port }, function (err, s) { + if (err) throw err + server = s + t.end() + }) +}) + +test('npm install-test', function (t) { + setup() + common.npm('install-test', { cwd: pkg }, function (err, code, stdout, stderr) { + if (err) throw err + t.equal(code, 0, 'command ran without error') + t.ok(statSync(installed), 'package was installed') + t.equal(require(installed).version, '1.5.1', 'underscore got installed as expected') + t.match(stdout, /hax/, 'found expected test output') + t.notOk(stderr, 'stderr should be empty') + t.end() + }) +}) + +test('npm it (the form most people will use)', function (t) { + setup() + common.npm('it', { cwd: pkg }, function (err, code, stdout, stderr) { + if (err) throw err + t.equal(code, 0, 'command ran without error') + t.ok(statSync(installed), 'package was installed') + t.equal(require(installed).version, '1.5.1', 'underscore got installed as expected') + t.match(stdout, /hax/, 'found expected test output') + t.notOk(stderr, 'stderr should be empty') + t.end() + }) +}) + +test('cleanup', function (t) { + process.chdir(osenv.tmpdir()) + server.close() + cleanup() + t.end() +}) + +function cleanup () { + rimraf.sync(pkg) +} + +function setup () { + cleanup() + mkdirp.sync(pkg) + writeFileSync(join(pkg, 'package.json'), JSON.stringify(json, null, 2)) +} diff --git a/test/network/legacy-bundled-git.js b/test/network/legacy-bundled-git.js new file mode 100644 index 000000000..15fbac84e --- /dev/null +++ b/test/network/legacy-bundled-git.js @@ -0,0 +1,99 @@ +'use strict' +var test = require('tap').test +var common = require('../common-tap.js') +var path = require('path') +var rimraf = require('rimraf') +var mkdirp = require('mkdirp') +var basepath = path.resolve(__dirname, path.basename(__filename, '.js')) +var fixturepath = path.resolve(basepath, 'npm-test-bundled-git') +var modulepath = path.resolve(basepath, 'node_modules') +var installedpath = path.resolve(modulepath, 'npm-test-bundled-git') +var Tacks = require('tacks') +var File = Tacks.File +var Dir = Tacks.Dir + +var minimatchExpected = { + name: 'minimatch', + description: 'a glob matcher in javascript', + version: '0.2.1', + repository: { + type: 'git', + url: 'git://github.com/isaacs/minimatch.git' + }, + main: 'minimatch.js', + scripts: { + test: 'tap test' + }, + engines: { + node: '*' + }, + dependencies: { + 'lru-cache': '~1.0.5' + }, + devDependencies: { + tap: '~0.1.3' + }, + licenses: [ + { + type: 'MIT', + url: 'http://github.com/isaacs/minimatch/raw/master/LICENSE' + } + ] +} + +var fixture = new Tacks( + Dir({ + README: File( + 'just an npm test\n' + ), + 'package.json': File({ + name: 'npm-test-bundled-git', + scripts: { + test: 'node test.js' + }, + version: '1.2.5', + dependencies: { + glob: 'git://github.com/isaacs/node-glob.git#npm-test' + }, + bundledDependencies: [ + 'glob' + ] + }) + }) +) +test('setup', function (t) { + setup() + t.done() +}) +test('bundled-git', function (t) { + common.npm(['install', '--global-style', fixturepath], {cwd: basepath}, installCheckAndTest) + function installCheckAndTest (err, code, stdout, stderr) { + if (err) throw err + t.is(code, 0, 'install went ok') + + var actual = require(path.resolve(installedpath, 'node_modules/glob/node_modules/minimatch/package.json')) + Object.keys(minimatchExpected).forEach(function (key) { + t.isDeeply(actual[key], minimatchExpected[key], key + ' set to the right value') + }) + + common.npm(['rm', fixturepath], {cwd: basepath}, removeCheckAndDone) + } + function removeCheckAndDone (err, code, stdout, stderr) { + if (err) throw err + t.is(code, 0, 'remove went ok') + t.done() + } +}) +test('cleanup', function (t) { + cleanup() + t.done() +}) +function setup () { + cleanup() + fixture.create(fixturepath) + mkdirp.sync(modulepath) +} +function cleanup () { + fixture.remove(fixturepath) + rimraf.sync(basepath) +} diff --git a/test/network/legacy-optional-deps.js b/test/network/legacy-optional-deps.js new file mode 100644 index 000000000..80ad7cc47 --- /dev/null +++ b/test/network/legacy-optional-deps.js @@ -0,0 +1,79 @@ +'use strict' +var path = require('path') +var fs = require('fs') +var test = require('tap').test +var common = require('../common-tap.js') +var rimraf = require('rimraf') +var mkdirp = require('mkdirp') +var mr = require('npm-registry-mock') +var basepath = path.resolve(__dirname, path.basename(__filename, '.js')) +var fixturepath = path.resolve(basepath, 'npm-test-optional-deps') +var modulepath = path.resolve(basepath, 'node_modules') +var Tacks = require('tacks') +var File = Tacks.File +var Dir = Tacks.Dir + +var fixture = new Tacks( + Dir({ + README: File( + 'just an npm test\n' + ), + 'package.json': File({ + name: 'npm-test-optional-deps', + version: '1.2.5', + optionalDependencies: { + 'npm-test-foobarzaaakakaka': 'http://example.com/', + async: '10.999.14234', + mkdirp: '0.3.5', + optimist: 'some invalid version 99 #! $$ x y z', + 'npm-test-failer': '*' + } + }) + }) +) + +var server + +test('setup', function (t) { + setup() + mr({port: common.port}, function (err, s) { + if (err) throw err + server = s + t.done() + }) +}) + +test('optional-deps', function (t) { + server.get('/npm-test-failer').reply(404, {error: 'nope'}) + + var opts = ['--registry=' + common.registry, '--timeout=100'] + common.npm(opts.concat(['install', fixturepath]), {cwd: basepath}, installCheckAndTest) + + function installCheckAndTest (err, code, stdout, stderr) { + if (err) throw err + if (stderr) console.error(stderr) + server.done() + t.is(code, 0, 'install went ok') + var dir = fs.readdirSync(modulepath).sort() + t.isDeeply(dir, ['mkdirp', 'npm-test-optional-deps'], 'only one optional dep should be there') + t.is(require(path.resolve(modulepath, 'mkdirp', 'package.json')).version, '0.3.5', 'mkdirp version right') + t.done() + } +}) + +test('cleanup', function (t) { + cleanup() + server.close() + t.done() +}) + +function setup () { + cleanup() + fixture.create(fixturepath) + mkdirp.sync(modulepath) +} + +function cleanup () { + fixture.remove(fixturepath) + rimraf.sync(basepath) +} diff --git a/test/network/legacy-shrinkwrap.js b/test/network/legacy-shrinkwrap.js new file mode 100644 index 000000000..6f5303037 --- /dev/null +++ b/test/network/legacy-shrinkwrap.js @@ -0,0 +1,132 @@ +'use strict' +var test = require('tap').test +var common = require('../common-tap.js') +var path = require('path') +var basepath = path.resolve(__dirname, path.basename(__filename, '.js')) +var Tacks = require('tacks') +var File = Tacks.File +var Dir = Tacks.Dir + +var fixture = new Tacks( + Dir({ + README: File( + 'just an npm test\n' + ), + 'npm-shrinkwrap.json': File({ + name: 'npm-test-shrinkwrap', + version: '0.0.0', + dependencies: { + glob: { + version: '3.1.5', + from: 'git://github.com/isaacs/node-glob.git#npm-test', + resolved: 'git://github.com/isaacs/node-glob.git#67bda227fd7a559cca5620307c7d30a6732a792f', + dependencies: { + 'graceful-fs': { + version: '1.1.5', + resolved: 'https://registry.npmjs.org/graceful-fs/-/graceful-fs-1.1.5.tgz', + dependencies: { + 'fast-list': { + version: '1.0.2', + resolved: 'https://registry.npmjs.org/fast-list/-/fast-list-1.0.2.tgz' + } + } + }, + inherits: { + version: '1.0.0', + resolved: 'https://registry.npmjs.org/inherits/-/inherits-1.0.0.tgz' + }, + minimatch: { + version: '0.2.1', + dependencies: { + 'lru-cache': { + version: '1.0.5' + } + } + } + } + }, + minimatch: { + version: '0.1.5', + resolved: 'https://registry.npmjs.org/minimatch/-/minimatch-0.1.5.tgz', + dependencies: { + 'lru-cache': { + version: '1.0.5', + resolved: 'https://registry.npmjs.org/lru-cache/-/lru-cache-1.0.5.tgz' + } + } + }, + 'npm-test-single-file': { + version: '1.2.3', + resolved: 'https://gist.github.com/isaacs/1837112/raw/9ef57a59fc22aeb1d1ca346b68826dcb638b8416/index.js' + } + } + }), + 'package.json': File({ + author: 'Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)', + name: 'npm-test-shrinkwrap', + version: '0.0.0', + dependencies: { + 'npm-test-single-file': 'https://gist.github.com/isaacs/1837112/raw/9ef57a59fc22aeb1d1ca346b68826dcb638b8416/index.js', + glob: 'git://github.com/isaacs/node-glob.git#npm-test', + minimatch: '~0.1.0' + }, + scripts: { + test: 'node test.js' + } + }) + }) +) + +test('setup', function (t) { + setup() + t.done() +}) + +test('shrinkwrap', function (t) { + common.npm(['install'], {cwd: basepath}, installCheckAndTest) + + function installCheckAndTest (err, code, stdout, stderr) { + if (err) throw err + console.error(stderr) + t.is(code, 0, 'install went ok') + + common.npm(['ls', '--json'], {cwd: basepath}, verifyLsMatchesShrinkwrap) + } + + function verifyLsMatchesShrinkwrap (err, code, stdout, stderr) { + if (err) throw err + console.error(stderr) + t.is(code, 0, 'ls went ok') + var actual = JSON.parse(stdout) + var expected = require(path.resolve(basepath, 'npm-shrinkwrap.json')) + // from is expected to vary + t.isDeeply(rmFrom(actual), rmFrom(expected)) + t.done() + } + + function rmFrom (obj) { + for (var i in obj) { + if (i === 'from') { + delete obj[i] + } else if (i === 'dependencies') { + for (var j in obj[i]) { + rmFrom(obj[i][j]) + } + } + } + } +}) + +test('cleanup', function (t) { + cleanup() + t.done() +}) + +function setup () { + cleanup() + fixture.create(basepath) +} + +function cleanup () { + fixture.remove(basepath) +} diff --git a/test/network/legacy-url-dep.js b/test/network/legacy-url-dep.js new file mode 100644 index 000000000..46378cd3e --- /dev/null +++ b/test/network/legacy-url-dep.js @@ -0,0 +1,59 @@ +'use strict' +var test = require('tap').test +var common = require('../common-tap.js') +var path = require('path') +var rimraf = require('rimraf') +var mkdirp = require('mkdirp') +var basepath = path.resolve(__dirname, path.basename(__filename, '.js')) +var fixturepath = path.resolve(basepath, 'npm-test-url-dep') +var modulepath = path.resolve(basepath, 'node_modules') +var Tacks = require('tacks') +var File = Tacks.File +var Dir = Tacks.Dir + +var fixture = new Tacks( + Dir({ + README: File( + 'just an npm test\n' + ), + 'package.json': File({ + name: 'npm-test-url-dep', + version: '1.2.3', + dependencies: { + jsonify: 'https://github.com/substack/jsonify/tarball/master', + sax: 'isaacs/sax-js', + 'canonical-host': 'git://github.com/isaacs/canonical-host' + } + }) + }) +) + +test('setup', function (t) { + setup() + t.done() +}) + +test('url-dep', function (t) { + common.npm(['install', fixturepath], {cwd: basepath}, installCheckAndTest) + function installCheckAndTest (err, code, stdout, stderr) { + if (err) throw err + t.is(code, 0, 'install went ok') + t.done() + } +}) + +test('cleanup', function (t) { + cleanup() + t.done() +}) + +function setup () { + cleanup() + fixture.create(fixturepath) + mkdirp.sync(modulepath) +} + +function cleanup () { + fixture.remove(fixturepath) + rimraf.sync(basepath) +} diff --git a/test/network/outdated-symlink.js b/test/network/outdated-symlink.js new file mode 100644 index 000000000..809cfec2e --- /dev/null +++ b/test/network/outdated-symlink.js @@ -0,0 +1,103 @@ +var fs = require('graceful-fs') +var path = require('path') +var osenv = require('osenv') +var mkdirp = require('mkdirp') +var mr = require('npm-registry-mock') +var rimraf = require('rimraf') +var test = require('tap').test + +var common = require('../common-tap.js') + +var pkg = path.resolve(__dirname, 'outdated-symlink') +var cache = path.resolve(pkg, 'cache') +var extend = Object.assign || require('util')._extend + +var fakeRoot = path.join(pkg, 'fakeRoot') +var OPTS = { + env: extend(extend({}, process.env), { + 'npm_config_prefix': fakeRoot + }) +} + +var json = { + name: 'my-local-package', + description: 'fixture', + version: '1.0.0' +} + +test('setup', function (t) { + cleanup() + mkdirp.sync(cache) + fs.writeFileSync( + path.join(pkg, 'package.json'), + JSON.stringify(json, null, 2) + ) + process.chdir(pkg) + common.npm(['install', '-g', 'async@0.2.9', 'underscore@1.3.1'], OPTS, function (err, code, stdout, stderr) { + if (err) throw err + t.comment(stdout) + t.comment(stderr) + common.npm(['link'], OPTS, function (err, code, stdout, stderr) { + if (err) throw err + t.comment(stdout) + t.comment(stderr) + t.is(code, 0) + common.npm(['ls', '-g'], OPTS, function (err, code, stdout, stderr) { + if (err) throw err + t.is(code, 0) + t.is(stderr, '', 'got expected stderr') + t.match(stdout, /my-local-package@1.0.0/, 'creates global link ok') + t.end() + }) + }) + }) +}) + +test('when outdated is called linked packages should be displayed as such', function (t) { + var regOutLinked = /my-local-package\s*1.0.0\s*linked\s*linked\n/ + var regOutInstallOne = /async\s*0.2.9\s*0.2.9\s*0.2.10\n/ + var regOutInstallTwo = /underscore\s*1.3.1\s*1.3.1\s*1.5.1\n/ + + mr({ port: common.port }, function (er, s) { + common.npm( + [ + '--registry', common.registry, + 'outdated', '-g' + ], + OPTS, + function (err, c, out, stderr) { + if (err) throw err + t.is(stderr, '') + t.match(out, regOutLinked, 'Global Link format as expected') + t.match(out, regOutInstallOne, 'Global Install format as expected') + t.match(out, regOutInstallTwo, 'Global Install format as expected') + s.close() + t.end() + } + ) + }) +}) + +test('cleanup', function (t) { + process.chdir(osenv.tmpdir()) + common.npm(['rm', 'outdated'], OPTS, function (err, code, stdout, stderr) { + if (err) throw err + t.comment(stdout) + t.comment(stderr) + t.is(code, 0, 'cleanup outdated in local ok') + common.npm(['rm', '-g', 'outdated', 'async', 'underscore'], OPTS, function (err, code) { + if (err) throw err + t.comment(stdout) + t.comment(stderr) + t.is(code, 0, 'cleanup outdated in global ok') + + cleanup() + t.end() + }) + }) +}) + +function cleanup () { + rimraf.sync(pkg) + rimraf.sync(fakeRoot) +} diff --git a/test/network/registry.js b/test/network/registry.js new file mode 100644 index 000000000..d8ec4a204 --- /dev/null +++ b/test/network/registry.js @@ -0,0 +1,74 @@ +// Run all the tests in the `npm-registry-couchapp` suite +// This verifies that the server-side stuff still works. + +var common = require('../common-tap') +var test = require('tap').test + +var npmExec = require.resolve('../../bin/npm-cli.js') +var path = require('path') +var ca = path.resolve(__dirname, '../../node_modules/npm-registry-couchapp') + +var which = require('which') + +var v = process.versions.node.split('.').map(function (n) { return parseInt(n, 10) }) +if (v[0] === 0 && v[1] < 10) { + console.error( + 'WARNING: need a recent Node for npm-registry-couchapp tests to run, have', + process.versions.node + ) +} else { + which('couchdb', function (er) { + if (er) { + console.error('WARNING: need couch to run test: ' + er.message) + } else { + runTests() + } + }) +} + +var extend = Object.assign || require('util')._extend + +function runTests () { + var env = extend({ TAP: 1 }, process.env) + env.npm = npmExec + // TODO: fix tap and / or nyc to handle nested invocations properly + env.COVERALLS_REPO_TOKEN = '' + + var opts = { + cwd: ca, + stdio: 'inherit' + } + common.npm(['install'], opts, function (err, code) { + if (err) { throw err } + if (code) { + return test('need install to work', function (t) { + t.fail('install failed with: ' + code) + t.end() + }) + } else { + opts = { + cwd: ca, + env: env, + stdio: 'inherit' + } + common.npm(['test', '--', '-Rtap', '--no-coverage'], opts, function (err, code) { + if (err) { throw err } + if (code) { + return test('need test to work', function (t) { + t.fail('test failed with: ' + code) + t.end() + }) + } + opts = { + cwd: ca, + env: env, + stdio: 'inherit' + } + common.npm(['prune', '--production'], opts, function (err, code) { + if (err) { throw err } + process.exit(code || 0) + }) + }) + } + }) +} |