diff --git a/lib/doctor.js b/lib/doctor.js index 95ede1bc87242..96094e6346d05 100644 --- a/lib/doctor.js +++ b/lib/doctor.js @@ -87,7 +87,7 @@ function makePretty (p) { const cacheStatus = p[8] ? `verified ${p[8].verifiedContent} tarballs` : 'notOk' const npmV = npm.version const nodeV = process.version.replace('v', '') - const registry = npm.config.get('registry') + const registry = npm.config.get('registry') || '' const list = [ ['npm ping', ping], ['npm -v', 'v' + npmV], diff --git a/lib/install/inflate-shrinkwrap.js b/lib/install/inflate-shrinkwrap.js index 395cc11191309..5da9418bbdb7a 100644 --- a/lib/install/inflate-shrinkwrap.js +++ b/lib/install/inflate-shrinkwrap.js @@ -74,7 +74,7 @@ function quotemeta (str) { } function tarballToVersion (name, tb) { - const registry = quotemeta(npm.config.get('registry')) + const registry = quotemeta(npm.config.get('registry') || '') .replace(/https?:/, 'https?:') .replace(/([^/])$/, '$1/') let matchRegTarball diff --git a/test/tap/doctor.js b/test/tap/doctor.js index 7b07e0f39b7d8..9285518c2e10e 100644 --- a/test/tap/doctor.js +++ b/test/tap/doctor.js @@ -5,9 +5,8 @@ const http = require('http') const mr = require('npm-registry-mock') const npm = require('../../lib/npm.js') const path = require('path') -const rimraf = require('rimraf') const Tacks = require('tacks') -const test = require('tap').test +const t = require('tap') const which = require('which') const Dir = Tacks.Dir @@ -44,12 +43,23 @@ const npmResponse = { } } -test('setup', (t) => { +let nodeServer + +t.teardown(() => { + if (server) { + server.close() + } + if (nodeServer) { + nodeServer.close() + } +}) + +t.test('setup', (t) => { const port = common.port + 1 - http.createServer(function (q, s) { + nodeServer = http.createServer(function (q, s) { s.end(JSON.stringify([{lts: true, version: '0.0.0'}])) - this.close() - }).listen(port, () => { + }) + nodeServer.listen(port, () => { node_url = 'http://localhost:' + port mr({port: common.port}, (err, s) => { t.ifError(err, 'registry mocked successfully') @@ -78,7 +88,7 @@ test('setup', (t) => { }) }) -test('npm doctor', function (t) { +t.test('npm doctor', function (t) { npm.commands.doctor({'node-url': node_url}, true, function (e, list) { t.ifError(e, 'npm loaded successfully') t.same(list.length, 9, 'list should have 9 prop') @@ -93,13 +103,29 @@ test('npm doctor', function (t) { which('git', function (e, resolvedPath) { t.ifError(e, 'git command is installed') t.same(list[4][1], resolvedPath, 'which git') - server.close() t.done() }) }) }) -test('cleanup', (t) => { - rimraf.sync(ROOT) - t.done() +t.test('npm doctor works without registry', function (t) { + npm.config.set('registry', false) + npm.commands.doctor({'node-url': node_url}, true, function (e, list) { + t.ifError(e, 'npm loaded successfully') + t.same(list.length, 9, 'list should have 9 prop') + t.same(list[0][1], 'OK', 'npm ping') + t.same(list[1][1], 'v' + npm.version, 'npm -v') + t.same(list[2][1], process.version, 'node -v') + t.same(list[3][1], '', 'no registry, but no crash') + t.same(list[5][1], 'ok', 'Perms check on cached files') + t.same(list[6][1], 'ok', 'Perms check on global node_modules') + t.same(list[7][1], 'ok', 'Perms check on local node_modules') + t.match(list[8][1], /^verified \d+ tarballs?$/, 'Cache verified') + which('git', function (e, resolvedPath) { + t.ifError(e, 'git command is installed') + t.same(list[4][1], resolvedPath, 'which git') + server.close() + t.done() + }) + }) }) diff --git a/test/tap/install-without-registry-config.js b/test/tap/install-without-registry-config.js new file mode 100644 index 0000000000000..852bd777ced5a --- /dev/null +++ b/test/tap/install-without-registry-config.js @@ -0,0 +1,35 @@ +const t = require('tap') +const { pkg, npm } = require('../common-tap.js') +const { writeFileSync, statSync, readFileSync } = require('fs') +const mkdirp = require('mkdirp') +const proj = pkg + '/project' +const dep = pkg + '/dep' +mkdirp.sync(proj) +mkdirp.sync(dep) +writeFileSync(dep + '/package.json', JSON.stringify({ + name: 'dependency', + version: '1.2.3' +})) +writeFileSync(proj + '/package.json', JSON.stringify({ + name: 'project', + version: '4.2.0' +})) + +const runTest = t => npm([ + 'install', + '../dep', + '--no-registry' +], { cwd: proj }).then(([code, out, err]) => { + t.equal(code, 0) + t.match(out, /^\+ dependency@1\.2\.3\n.* 1 package in [0-9.]+m?s\n$/) + t.equal(err, '') + const data = readFileSync(proj + '/node_modules/dependency/package.json', 'utf8') + t.same(JSON.parse(data), { + name: 'dependency', + version: '1.2.3' + }, 'dep got installed') + t.ok(statSync(proj + '/package-lock.json').isFile(), 'package-lock exists') +}) + +t.test('install without a registry, no package lock', t => runTest(t)) +t.test('install without a registry, with package lock', t => runTest(t))