aboutsummaryrefslogtreecommitdiff
path: root/deps/npm/test/tap
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/test/tap')
-rw-r--r--deps/npm/test/tap/cache-eacces-error-message.js38
-rw-r--r--deps/npm/test/tap/cache-shasum-fork.js19
-rw-r--r--deps/npm/test/tap/doctor.js48
-rw-r--r--deps/npm/test/tap/false-name.js2
-rw-r--r--deps/npm/test/tap/install-without-registry-config.js35
5 files changed, 113 insertions, 29 deletions
diff --git a/deps/npm/test/tap/cache-eacces-error-message.js b/deps/npm/test/tap/cache-eacces-error-message.js
new file mode 100644
index 0000000000..aa112eba43
--- /dev/null
+++ b/deps/npm/test/tap/cache-eacces-error-message.js
@@ -0,0 +1,38 @@
+const npm = require('../../lib/npm.js')
+const t = require('tap')
+
+if (process.platform === 'win32') {
+ t.plan(0, 'this is a unix-only thing')
+ process.exit(0)
+}
+
+const errorMessage = require('../../lib/utils/error-message.js')
+
+const common = require('../common-tap.js')
+
+t.plan(1)
+
+npm.load({ cache: common.cache }, () => {
+ npm.config.set('cache', common.cache)
+ const er = new Error('access is e, i am afraid')
+ er.code = 'EACCES'
+ er.errno = -13
+ er.path = common.cache + '/src'
+ er.dest = common.cache + '/to'
+
+ t.match(errorMessage(er), {
+ summary: [
+ [
+ '',
+ new RegExp('\n' +
+ 'Your cache folder contains root-owned files, due to a bug in\n' +
+ 'previous versions of npm which has since been addressed.\n' +
+ '\n' +
+ 'To permanently fix this problem, please run:\n' +
+ ' sudo chown -R [0-9]+:[0-9]+ ".*npm_cache_cache-eacces-error-message"'
+ )
+ ]
+ ],
+ detail: []
+ }, 'get the helpful error message')
+})
diff --git a/deps/npm/test/tap/cache-shasum-fork.js b/deps/npm/test/tap/cache-shasum-fork.js
index e035c78111..fade5ffb64 100644
--- a/deps/npm/test/tap/cache-shasum-fork.js
+++ b/deps/npm/test/tap/cache-shasum-fork.js
@@ -3,8 +3,6 @@ var path = require('path')
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')
@@ -19,7 +17,8 @@ var cache = common.cache
var server
test('setup', function (t) {
- setup()
+ mkdirp.sync(path.join(pkg, 'node_modules'))
+ process.chdir(pkg)
t.comment('test for https://github.com/npm/npm/issues/3265')
mr({ port: common.port }, function (er, s) {
server = s
@@ -28,7 +27,6 @@ test('setup', function (t) {
})
test('npm cache - install from fork', function (t) {
- setup()
common.npm(
[
'--loglevel', 'silent',
@@ -60,7 +58,6 @@ test('npm cache - install from fork', function (t) {
// Now install the real 1.5.1.
test('npm cache - install from origin', function (t) {
- setup()
common.npm(
[
'--loglevel', 'silent',
@@ -91,17 +88,5 @@ test('npm cache - install from origin', function (t) {
test('cleanup', function (t) {
server.close()
- cleanup()
t.end()
})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
-
-function setup () {
- mkdirp.sync(cache)
- mkdirp.sync(path.join(pkg, 'node_modules'))
- process.chdir(pkg)
-}
diff --git a/deps/npm/test/tap/doctor.js b/deps/npm/test/tap/doctor.js
index 7b07e0f39b..9285518c2e 100644
--- a/deps/npm/test/tap/doctor.js
+++ b/deps/npm/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/deps/npm/test/tap/false-name.js b/deps/npm/test/tap/false-name.js
index 541bacc7ed..57d2a2ad2f 100644
--- a/deps/npm/test/tap/false-name.js
+++ b/deps/npm/test/tap/false-name.js
@@ -58,7 +58,7 @@ test('not every pkg.name can be required', function (t) {
)
t.ok(
existsSync(path.join(pkg, 'node_modules', 'test-package')),
- 'test-pacakge subdep installed OK'
+ 'test-package subdep installed OK'
)
t.end()
}
diff --git a/deps/npm/test/tap/install-without-registry-config.js b/deps/npm/test/tap/install-without-registry-config.js
new file mode 100644
index 0000000000..852bd777ce
--- /dev/null
+++ b/deps/npm/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))