summaryrefslogtreecommitdiff
path: root/deps/npm/test/tap
diff options
context:
space:
mode:
authorRuy Adorno <ruyadorno@hotmail.com>2019-11-05 14:55:08 -0500
committerRich Trott <rtrott@gmail.com>2019-11-09 20:13:43 -0800
commit4b97c3addb246274cd7e8432edd537e0bdf60b63 (patch)
tree9f859239c3b38b04ddc58ee736bf6b2caf6008a5 /deps/npm/test/tap
parent5f9794ea9aaaf5597974a65460e1f3069f68475f (diff)
downloadandroid-node-v8-4b97c3addb246274cd7e8432edd537e0bdf60b63.tar.gz
android-node-v8-4b97c3addb246274cd7e8432edd537e0bdf60b63.tar.bz2
android-node-v8-4b97c3addb246274cd7e8432edd537e0bdf60b63.zip
deps: update npm to 6.13.0
PR-URL: https://github.com/nodejs/node/pull/30271 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'deps/npm/test/tap')
-rw-r--r--deps/npm/test/tap/404-parent.js18
-rw-r--r--deps/npm/test/tap/access.js10
-rw-r--r--deps/npm/test/tap/add-remote-git-file.js24
-rw-r--r--deps/npm/test/tap/add-remote-git-shrinkwrap.js26
-rw-r--r--deps/npm/test/tap/add-remote-git-submodule.js15
-rw-r--r--deps/npm/test/tap/add-remote-git.js27
-rw-r--r--deps/npm/test/tap/all-package-metadata.js20
-rw-r--r--deps/npm/test/tap/bearer-token-check.js89
-rw-r--r--deps/npm/test/tap/bitbucket-https-url-with-creds-package.js15
-rw-r--r--deps/npm/test/tap/bitbucket-https-url-with-creds.js13
-rw-r--r--deps/npm/test/tap/bitbucket-shortcut-package.js13
-rw-r--r--deps/npm/test/tap/bitbucket-shortcut.js13
-rw-r--r--deps/npm/test/tap/build-already-built.js21
-rw-r--r--deps/npm/test/tap/cache-eacces-error-message.js9
-rw-r--r--deps/npm/test/tap/check-cpu-reqs.js13
-rw-r--r--deps/npm/test/tap/check-engine-reqs.js13
-rw-r--r--deps/npm/test/tap/check-install-self.js13
-rw-r--r--deps/npm/test/tap/check-os-reqs.js13
-rw-r--r--deps/npm/test/tap/circular-dep.js9
-rw-r--r--deps/npm/test/tap/config-meta.js10
-rw-r--r--deps/npm/test/tap/config-new-cafile.js25
-rw-r--r--deps/npm/test/tap/correct-mkdir.js6
-rw-r--r--deps/npm/test/tap/do-not-remove-other-bins.js14
-rw-r--r--deps/npm/test/tap/fund.js298
-rw-r--r--deps/npm/test/tap/gist-short-shortcut-package.js13
-rw-r--r--deps/npm/test/tap/gist-short-shortcut.js13
-rw-r--r--deps/npm/test/tap/gist-shortcut-package.js21
-rw-r--r--deps/npm/test/tap/gist-shortcut.js33
-rw-r--r--deps/npm/test/tap/git-dependency-install-link.js41
-rw-r--r--deps/npm/test/tap/git-prepare.js18
-rw-r--r--deps/npm/test/tap/github-shortcut-package.js33
-rw-r--r--deps/npm/test/tap/github-shortcut.js33
-rw-r--r--deps/npm/test/tap/gitlab-shortcut-package.js33
-rw-r--r--deps/npm/test/tap/gitlab-shortcut.js33
-rw-r--r--deps/npm/test/tap/graceful-restart.js25
-rw-r--r--deps/npm/test/tap/ignore-install-link.js5
-rw-r--r--deps/npm/test/tap/init-interrupt.js22
-rw-r--r--deps/npm/test/tap/install-at-locally.js19
-rw-r--r--deps/npm/test/tap/install-at-sub-path-locally.js36
-rw-r--r--deps/npm/test/tap/install-bad-dep-format.js39
-rw-r--r--deps/npm/test/tap/install-bad-man.js42
-rw-r--r--deps/npm/test/tap/install-bin-null.js54
-rw-r--r--deps/npm/test/tap/install-cli-only-development.js68
-rw-r--r--deps/npm/test/tap/install-cli-only-production.js9
-rw-r--r--deps/npm/test/tap/install-cli-only-shrinkwrap.js67
-rw-r--r--deps/npm/test/tap/install-cli-production-nosave.js39
-rw-r--r--deps/npm/test/tap/install-cli-production.js9
-rw-r--r--deps/npm/test/tap/install-cli-unicode.js16
-rw-r--r--deps/npm/test/tap/install-duplicate-deps-warning.js24
-rw-r--r--deps/npm/test/tap/install-from-local-multipath.js9
-rw-r--r--deps/npm/test/tap/install-from-local.js9
-rw-r--r--deps/npm/test/tap/install-link-scripts.js67
-rw-r--r--deps/npm/test/tap/install-man.js40
-rw-r--r--deps/npm/test/tap/install-mention-funding.js127
-rw-r--r--deps/npm/test/tap/install-noargs-dev.js33
-rw-r--r--deps/npm/test/tap/install-package-json-order.js43
-rw-r--r--deps/npm/test/tap/install-property-conflicts.js33
-rw-r--r--deps/npm/test/tap/install-save-consistent-newlines.js134
-rw-r--r--deps/npm/test/tap/install-save-exact.js84
-rw-r--r--deps/npm/test/tap/install-save-local.js246
-rw-r--r--deps/npm/test/tap/install-save-prefix.js210
-rw-r--r--deps/npm/test/tap/install-scoped-already-installed.js10
-rw-r--r--deps/npm/test/tap/install-scoped-link.js19
-rw-r--r--deps/npm/test/tap/install-scoped-with-peer-dependency.js33
-rw-r--r--deps/npm/test/tap/install-shrinkwrapped-git.js63
-rw-r--r--deps/npm/test/tap/install-test-cli-without-package-lock.js53
-rw-r--r--deps/npm/test/tap/install-with-dev-dep-duplicate.js27
-rw-r--r--deps/npm/test/tap/install.fund.js100
-rw-r--r--deps/npm/test/tap/it.js66
-rw-r--r--deps/npm/test/tap/lifecycle-INIT_CWD.js38
-rw-r--r--deps/npm/test/tap/lifecycle-order.js30
-rw-r--r--deps/npm/test/tap/link.js63
-rw-r--r--deps/npm/test/tap/locker.js13
-rw-r--r--deps/npm/test/tap/ls-depth-cli.js15
-rw-r--r--deps/npm/test/tap/ls-depth-unmet.js15
-rw-r--r--deps/npm/test/tap/ls-env.js15
-rw-r--r--deps/npm/test/tap/ls-l-depth-0.js35
-rw-r--r--deps/npm/test/tap/ls-production-and-dev.js15
-rw-r--r--deps/npm/test/tap/no-global-warns.js31
-rw-r--r--deps/npm/test/tap/no-scan-full-global-dir.js3
-rw-r--r--deps/npm/test/tap/optional-metadep-rollback-collision.js80
-rw-r--r--deps/npm/test/tap/outdated-depth.js15
-rw-r--r--deps/npm/test/tap/peer-deps.js37
-rw-r--r--deps/npm/test/tap/publish-config.js3
-rw-r--r--deps/npm/test/tap/publish-invalid-semver-tag.js51
-rw-r--r--deps/npm/test/tap/repo.js35
-rw-r--r--deps/npm/test/tap/scripts-whitespace-windows.js13
-rw-r--r--deps/npm/test/tap/semver-doc.js2
-rw-r--r--deps/npm/test/tap/shrinkwrap-_auth.js91
-rw-r--r--deps/npm/test/tap/shrinkwrap-dev-dependency.js29
-rw-r--r--deps/npm/test/tap/shrinkwrap-empty-deps.js16
-rw-r--r--deps/npm/test/tap/shrinkwrap-extra-metadata.js18
-rw-r--r--deps/npm/test/tap/shrinkwrap-global-auth.js84
-rw-r--r--deps/npm/test/tap/shrinkwrap-lifecycle.js19
-rw-r--r--deps/npm/test/tap/shrinkwrap-optional-dependency.js34
-rw-r--r--deps/npm/test/tap/shrinkwrap-optional-property.js33
-rw-r--r--deps/npm/test/tap/shrinkwrap-prod-dependency-also.js85
-rw-r--r--deps/npm/test/tap/shrinkwrap-prod-dependency.js64
-rw-r--r--deps/npm/test/tap/shrinkwrap-save-dev-with-existing-deps.js15
-rw-r--r--deps/npm/test/tap/shrinkwrap-save-with-existing-dev-deps.js33
-rw-r--r--deps/npm/test/tap/shrinkwrap-scoped-auth.js84
-rw-r--r--deps/npm/test/tap/startstop.js13
-rw-r--r--deps/npm/test/tap/symlink-cycle.js29
-rw-r--r--deps/npm/test/tap/uninstall-package.js17
-rw-r--r--deps/npm/test/tap/uninstall-save.js32
-rw-r--r--deps/npm/test/tap/unpack-foreign-tarball.js73
-rw-r--r--deps/npm/test/tap/unpublish-config.js13
-rw-r--r--deps/npm/test/tap/update-examples.js47
-rw-r--r--deps/npm/test/tap/url-dependencies.js108
-rw-r--r--deps/npm/test/tap/utils.funding.js480
-rw-r--r--deps/npm/test/tap/version-allow-same-version.js83
-rw-r--r--deps/npm/test/tap/version-commit-hooks.js16
-rw-r--r--deps/npm/test/tap/version-consistent-newlines.js11
-rw-r--r--deps/npm/test/tap/version-sub-directory.js25
-rw-r--r--deps/npm/test/tap/view.js35
115 files changed, 2158 insertions, 2816 deletions
diff --git a/deps/npm/test/tap/404-parent.js b/deps/npm/test/tap/404-parent.js
index 306a4bc4bf..ee9623c545 100644
--- a/deps/npm/test/tap/404-parent.js
+++ b/deps/npm/test/tap/404-parent.js
@@ -1,7 +1,6 @@
var common = require('../common-tap.js')
var test = require('tap').test
var npm = require('../../')
-var osenv = require('osenv')
var path = require('path')
var fs = require('fs')
var rimraf = require('rimraf')
@@ -10,20 +9,15 @@ var mr = require('npm-registry-mock')
test('404-parent: if parent exists, specify parent in error message', function (t) {
setup()
- rimraf.sync(path.resolve(pkg, 'node_modules'))
- performInstall(function (err) {
- t.ok(err instanceof Error, 'error was returned')
- t.equal(err.parent, '404-parent', "error's parent set")
- t.end()
+ rimraf(path.resolve(pkg, 'node_modules'), () => {
+ performInstall(function (err) {
+ t.ok(err instanceof Error, 'error was returned')
+ t.equal(err.parent, '404-parent', "error's parent set")
+ t.end()
+ })
})
})
-test('cleanup', function (t) {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
- t.end()
-})
-
function setup () {
fs.writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify({
author: 'Evan Lucas',
diff --git a/deps/npm/test/tap/access.js b/deps/npm/test/tap/access.js
index 2998bbf63b..4183c46b53 100644
--- a/deps/npm/test/tap/access.js
+++ b/deps/npm/test/tap/access.js
@@ -73,8 +73,7 @@ test('npm access public when no package passed and no package.json', function (t
function (er, code, stdout, stderr) {
t.ifError(er, 'npm access')
t.match(stderr, /no package name passed to command and no package.json found/)
- rimraf.sync(missing)
- t.end()
+ rimraf(missing, t.end)
})
})
@@ -95,8 +94,7 @@ test('npm access public when no package passed and invalid package.json', functi
function (er, code, stdout, stderr) {
t.ifError(er, 'npm access')
t.match(stderr, /Failed to parse json/)
- rimraf.sync(invalid)
- t.end()
+ rimraf(invalid, t.end)
})
})
@@ -405,8 +403,7 @@ test('npm access ls-packages with no package specified or package.json', functio
function (er, code, stdout, stderr) {
t.ifError(er, 'npm access ls-packages')
t.same(JSON.parse(stdout), clientPackages)
- rimraf.sync(missing)
- t.end()
+ rimraf(missing, t.end)
}
)
})
@@ -557,7 +554,6 @@ test('npm access blerg', function (t) {
test('cleanup', function (t) {
t.pass('cleaned up')
- rimraf.sync(pkg)
server.done()
server.close()
t.end()
diff --git a/deps/npm/test/tap/add-remote-git-file.js b/deps/npm/test/tap/add-remote-git-file.js
index 7d64609072..483c6368c6 100644
--- a/deps/npm/test/tap/add-remote-git-file.js
+++ b/deps/npm/test/tap/add-remote-git-file.js
@@ -4,17 +4,16 @@ var fs = require('fs')
var resolve = require('path').resolve
var url = require('url')
-var osenv = require('osenv')
var mkdirp = require('mkdirp')
-var rimraf = require('rimraf')
var test = require('tap').test
var npm = require('../../lib/npm.js')
var fetchPackageMetadata = require('../../lib/fetch-package-metadata.js')
var common = require('../common-tap.js')
-var pkg = common.pkg
-var repo = common.pkg + '-repo'
+var pkg = resolve(common.pkg, 'package')
+var repo = resolve(common.pkg, 'repo')
+mkdirp.sync(pkg)
var git
var cloneURL = 'git+file://' + resolve(pkg, 'child.git')
@@ -25,7 +24,6 @@ var pjChild = JSON.stringify({
}, null, 2) + '\n'
test('setup', function (t) {
- bootstrap()
setup(function (er, r) {
t.ifError(er, 'git started up successfully')
@@ -70,16 +68,6 @@ test('save install', function (t) {
})
})
-test('clean', function (t) {
- cleanup()
- t.end()
-})
-
-function bootstrap () {
- cleanup()
- mkdirp.sync(pkg)
-}
-
function setup (cb) {
mkdirp.sync(repo)
fs.writeFileSync(resolve(repo, 'package.json'), pjChild)
@@ -95,9 +83,3 @@ function setup (cb) {
}, cb)
})
}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(repo)
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/add-remote-git-shrinkwrap.js b/deps/npm/test/tap/add-remote-git-shrinkwrap.js
index 0daf2922e7..01a033e894 100644
--- a/deps/npm/test/tap/add-remote-git-shrinkwrap.js
+++ b/deps/npm/test/tap/add-remote-git-shrinkwrap.js
@@ -1,16 +1,14 @@
var fs = require('fs')
var resolve = require('path').resolve
-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 = common.pkg
-var repo = pkg + '-repo'
+var pkg = resolve(common.pkg, 'package')
+var repo = resolve(common.pkg, 'repo')
var daemon
var daemonPID
@@ -30,7 +28,8 @@ var pjChild = JSON.stringify({
}, null, 2) + '\n'
test('setup', function (t) {
- bootstrap()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(resolve(pkg, 'package.json'), pjParent)
setup(function (er, r) {
t.ifError(er, 'git started up successfully')
@@ -85,19 +84,10 @@ test('shrinkwrap gets correct _from and _resolved (#7121)', function (t) {
})
test('clean', function (t) {
- daemon.on('close', function () {
- cleanup()
- t.end()
- })
+ daemon.on('close', t.end)
process.kill(daemonPID)
})
-function bootstrap () {
- cleanup()
- mkdirp.sync(pkg)
- fs.writeFileSync(resolve(pkg, 'package.json'), pjParent)
-}
-
function setup (cb) {
mkdirp.sync(repo)
fs.writeFileSync(resolve(repo, 'package.json'), pjChild)
@@ -145,9 +135,3 @@ function setup (cb) {
}, cb)
})
}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(repo)
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/add-remote-git-submodule.js b/deps/npm/test/tap/add-remote-git-submodule.js
index 43b30f7a65..54f2819fb3 100644
--- a/deps/npm/test/tap/add-remote-git-submodule.js
+++ b/deps/npm/test/tap/add-remote-git-submodule.js
@@ -1,7 +1,7 @@
var fs = require('fs')
var resolve = require('path').resolve
-var osenv = require('osenv')
+var cwd = process.cwd()
var mkdirp = require('mkdirp')
var rimraf = require('rimraf')
var test = require('tap').test
@@ -9,8 +9,8 @@ var test = require('tap').test
var npm = require('../../lib/npm.js')
var common = require('../common-tap.js')
-var pkg = common.pkg
-var repos = pkg + '-repos'
+var pkg = resolve(common.pkg, 'package')
+var repos = resolve(common.pkg, 'repos')
var subwt = resolve(repos, 'subwt')
var topwt = resolve(repos, 'topwt')
var suburl = 'git://localhost:' + common.gitPort + '/sub.git'
@@ -62,14 +62,13 @@ test('has file in submodule', function (t) {
test('clean', function (t) {
daemon.on('close', function () {
- cleanup()
t.end()
})
process.kill(daemonPID)
})
function bootstrap (t) {
- process.chdir(osenv.tmpdir())
+ process.chdir(cwd)
rimraf.sync(pkg)
mkdirp.sync(pkg)
process.chdir(pkg)
@@ -141,9 +140,3 @@ function setup (cb) {
}, cb)
})
}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(repos)
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/add-remote-git.js b/deps/npm/test/tap/add-remote-git.js
index 44294924f1..2a61963439 100644
--- a/deps/npm/test/tap/add-remote-git.js
+++ b/deps/npm/test/tap/add-remote-git.js
@@ -1,16 +1,14 @@
var fs = require('fs')
var resolve = require('path').resolve
-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 = common.pkg
-var repo = pkg + '-repo'
+var pkg = resolve(common.pkg, 'package')
+var repo = resolve(pkg, 'repo')
var daemon
var daemonPID
@@ -30,7 +28,8 @@ var pjChild = JSON.stringify({
}, null, 2) + '\n'
test('setup', function (t) {
- bootstrap()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(resolve(pkg, 'package.json'), pjParent)
setup(function (er, r) {
t.ifError(er, 'git started up successfully')
@@ -47,25 +46,15 @@ test('install from repo', function (t) {
process.chdir(pkg)
npm.commands.install('.', [], function (er) {
t.ifError(er, 'npm installed via git')
-
t.end()
})
})
test('clean', function (t) {
- daemon.on('close', function () {
- cleanup()
- t.end()
- })
+ daemon.on('close', t.end)
process.kill(daemonPID)
})
-function bootstrap () {
- cleanup()
- mkdirp.sync(pkg)
- fs.writeFileSync(resolve(pkg, 'package.json'), pjParent)
-}
-
function setup (cb) {
mkdirp.sync(repo)
fs.writeFileSync(resolve(repo, 'package.json'), pjChild)
@@ -113,9 +102,3 @@ function setup (cb) {
}, cb)
})
}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(repo)
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/all-package-metadata.js b/deps/npm/test/tap/all-package-metadata.js
index 153878500a..75afa9bad2 100644
--- a/deps/npm/test/tap/all-package-metadata.js
+++ b/deps/npm/test/tap/all-package-metadata.js
@@ -26,8 +26,8 @@ function setup () {
mkdirp.sync(cacheBase)
}
-function cleanup () {
- rimraf.sync(PKG_DIR)
+function cleanup (cb) {
+ rimraf(PKG_DIR, cb)
}
test('setup', function (t) {
@@ -88,8 +88,7 @@ test('allPackageMetadata full request', function (t) {
}
}, 'cache contents based on what was written')
server.done()
- cleanup()
- t.end()
+ cleanup(t.end)
})
})
@@ -126,8 +125,7 @@ test('allPackageMetadata cache only', function (t) {
t.ok(fileData, 'cache contents written to the right file')
t.deepEquals(fileData, cacheContents, 'cacheContents written directly')
server.done()
- cleanup()
- t.end()
+ cleanup(t.end)
})
})
@@ -188,8 +186,7 @@ test('createEntryStream merged stream', function (t) {
t.ok(fileData, 'cache contents written to the right file')
t.deepEquals(fileData, cacheContents, 'cache updated correctly')
server.done()
- cleanup()
- t.end()
+ cleanup(t.end)
})
})
@@ -205,14 +202,11 @@ test('allPackageMetadata no sources', function (t) {
t.ok(err, 'no sources, got an error')
t.match(err.message, /No search sources available/, 'useful error message')
server.done()
- cleanup()
- t.end()
+ cleanup(t.end)
})
})
test('cleanup', function (t) {
- cleanup()
server.close()
- t.pass('all done')
- t.done()
+ cleanup(t.end)
})
diff --git a/deps/npm/test/tap/bearer-token-check.js b/deps/npm/test/tap/bearer-token-check.js
index 21c6b0beb2..86602b303c 100644
--- a/deps/npm/test/tap/bearer-token-check.js
+++ b/deps/npm/test/tap/bearer-token-check.js
@@ -4,9 +4,7 @@ var writeFileSync = require('graceful-fs').writeFileSync
var fs = require('fs')
var mkdirp = require('mkdirp')
var http = require('http')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
-var test = require('tap').test
+const t = require('tap')
var common = require('../common-tap.js')
var toNerfDart = require('../../lib/config/nerf-dart.js')
@@ -38,14 +36,42 @@ server.on('request', (req, res) => {
}
})
-test('setup', function (t) {
- server.listen(common.port, () => {
- setup()
- t.done()
- })
+var contents = '@scoped:registry=' + common.registry + '\n' +
+ toNerfDart(common.registry) + ':_authToken=0xabad1dea\n'
+
+var json = {
+ name: 'test-package-install',
+ version: '1.0.0',
+ dependencies: {
+ '@scoped/underscore': '1.3.1'
+ }
+}
+
+var shrinkwrap = {
+ name: 'test-package-install',
+ version: '1.0.0',
+ dependencies: {
+ '@scoped/underscore': {
+ resolved: tarballURL,
+ version: '1.3.1'
+ }
+ }
+}
+
+t.teardown(() => server.close())
+
+t.test('setup', function (t) {
+ 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'
+ )
+ server.listen(common.port, t.end)
})
-test('authed npm install with tarball not on registry', function (t) {
+t.test('authed npm install with tarball not on registry', function (t) {
common.npm(
[
'install',
@@ -81,48 +107,3 @@ test('authed npm install with tarball not on registry', function (t) {
}
)
})
-
-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',
- dependencies: {
- '@scoped/underscore': '1.3.1'
- }
-}
-
-var shrinkwrap = {
- name: 'test-package-install',
- version: '1.0.0',
- dependencies: {
- '@scoped/underscore': {
- resolved: tarballURL,
- 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/deps/npm/test/tap/bitbucket-https-url-with-creds-package.js b/deps/npm/test/tap/bitbucket-https-url-with-creds-package.js
index 4891b9886b..f0f14dcb34 100644
--- a/deps/npm/test/tap/bitbucket-https-url-with-creds-package.js
+++ b/deps/npm/test/tap/bitbucket-https-url-with-creds-package.js
@@ -5,10 +5,7 @@ const BB = require('bluebird')
var fs = require('graceful-fs')
var path = require('path')
-var mkdirp = require('mkdirp')
-var osenv = require('osenv')
var requireInject = require('require-inject')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
@@ -64,22 +61,10 @@ test('bitbucket-https-url-with-creds-package', function (t) {
})
})
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
function setup () {
- cleanup()
- mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
JSON.stringify(json, null, 2)
)
process.chdir(pkg)
}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/bitbucket-https-url-with-creds.js b/deps/npm/test/tap/bitbucket-https-url-with-creds.js
index 7f7e7eee48..703d0d9a6a 100644
--- a/deps/npm/test/tap/bitbucket-https-url-with-creds.js
+++ b/deps/npm/test/tap/bitbucket-https-url-with-creds.js
@@ -6,9 +6,7 @@ var fs = require('graceful-fs')
var path = require('path')
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
var requireInject = require('require-inject')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
@@ -61,13 +59,7 @@ test('bitbucket-https-url-with-creds', function (t) {
})
})
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
function setup () {
- cleanup()
mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
@@ -75,8 +67,3 @@ function setup () {
)
process.chdir(pkg)
}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/bitbucket-shortcut-package.js b/deps/npm/test/tap/bitbucket-shortcut-package.js
index ef606f4aa3..a148c598c6 100644
--- a/deps/npm/test/tap/bitbucket-shortcut-package.js
+++ b/deps/npm/test/tap/bitbucket-shortcut-package.js
@@ -6,9 +6,7 @@ var fs = require('graceful-fs')
var path = require('path')
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
var requireInject = require('require-inject')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
@@ -65,13 +63,7 @@ test('bitbucket-shortcut', function (t) {
})
})
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
function setup () {
- cleanup()
mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
@@ -79,8 +71,3 @@ function setup () {
)
process.chdir(pkg)
}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/bitbucket-shortcut.js b/deps/npm/test/tap/bitbucket-shortcut.js
index fe1c417975..6d750f869a 100644
--- a/deps/npm/test/tap/bitbucket-shortcut.js
+++ b/deps/npm/test/tap/bitbucket-shortcut.js
@@ -6,9 +6,7 @@ var fs = require('graceful-fs')
var path = require('path')
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
var requireInject = require('require-inject')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
@@ -62,13 +60,7 @@ test('bitbucket-shortcut', function (t) {
})
})
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
function setup () {
- cleanup()
mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
@@ -76,8 +68,3 @@ function setup () {
)
process.chdir(pkg)
}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/build-already-built.js b/deps/npm/test/tap/build-already-built.js
index 1e7359a558..3410432ab2 100644
--- a/deps/npm/test/tap/build-already-built.js
+++ b/deps/npm/test/tap/build-already-built.js
@@ -2,8 +2,6 @@
// message "already built" should not be error
var test = require('tap').test
var path = require('path')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var npmlog = require('npmlog')
var mkdirp = require('mkdirp')
var requireInject = require('require-inject')
@@ -12,13 +10,7 @@ var npm = require('../../lib/npm.js')
const common = require('../common-tap.js')
var PKG_DIR = common.pkg
-var fakePkg = 'foo'
-
-test('setup', function (t) {
- cleanup()
-
- t.end()
-})
+var fakePkg = path.resolve(PKG_DIR, 'foo')
test("issue #6735 build 'already built' message", function (t) {
npm.load({ loglevel: 'warn' }, function () {
@@ -66,14 +58,3 @@ test("issue #6735 build 'already built' message", function (t) {
t.end()
})
})
-
-test('cleanup', function (t) {
- cleanup()
-
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(PKG_DIR)
-}
diff --git a/deps/npm/test/tap/cache-eacces-error-message.js b/deps/npm/test/tap/cache-eacces-error-message.js
index aa112eba43..fe76875c3e 100644
--- a/deps/npm/test/tap/cache-eacces-error-message.js
+++ b/deps/npm/test/tap/cache-eacces-error-message.js
@@ -1,14 +1,11 @@
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 common = require('../common-tap.js')
-const errorMessage = require('../../lib/utils/error-message.js')
+common.skipIfWindows('this is a unix-only thing')
-const common = require('../common-tap.js')
+const errorMessage = require('../../lib/utils/error-message.js')
t.plan(1)
diff --git a/deps/npm/test/tap/check-cpu-reqs.js b/deps/npm/test/tap/check-cpu-reqs.js
index 0a36492430..d70660b058 100644
--- a/deps/npm/test/tap/check-cpu-reqs.js
+++ b/deps/npm/test/tap/check-cpu-reqs.js
@@ -2,9 +2,7 @@
var path = require('path')
var fs = require('fs')
var test = require('tap').test
-var osenv = require('osenv')
var mkdirp = require('mkdirp')
-var rimraf = require('rimraf')
var common = require('../common-tap.js')
var base = common.pkg
@@ -41,18 +39,7 @@ test('force install bad cpu', function (t) {
})
})
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(base)
-}
-
function setup () {
- cleanup()
mkdirp.sync(path.resolve(installFrom, 'node_modules'))
fs.writeFileSync(
path.join(installFrom, 'package.json'),
diff --git a/deps/npm/test/tap/check-engine-reqs.js b/deps/npm/test/tap/check-engine-reqs.js
index fa25e28dd6..eec0756288 100644
--- a/deps/npm/test/tap/check-engine-reqs.js
+++ b/deps/npm/test/tap/check-engine-reqs.js
@@ -2,9 +2,7 @@
var path = require('path')
var fs = require('fs')
var test = require('tap').test
-var osenv = require('osenv')
var mkdirp = require('mkdirp')
-var rimraf = require('rimraf')
var common = require('../common-tap.js')
var base = common.pkg
@@ -54,18 +52,7 @@ test('warns on bad engine not strict', function (t) {
})
})
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(base)
-}
-
function setup () {
- cleanup()
mkdirp.sync(path.resolve(installFrom, 'node_modules'))
fs.writeFileSync(
path.join(installFrom, 'package.json'),
diff --git a/deps/npm/test/tap/check-install-self.js b/deps/npm/test/tap/check-install-self.js
index e7591b55e0..63901a12df 100644
--- a/deps/npm/test/tap/check-install-self.js
+++ b/deps/npm/test/tap/check-install-self.js
@@ -2,9 +2,7 @@
var path = require('path')
var fs = require('fs')
var test = require('tap').test
-var osenv = require('osenv')
var mkdirp = require('mkdirp')
-var rimraf = require('rimraf')
var common = require('../common-tap.js')
var base = common.pkg
@@ -43,18 +41,7 @@ test('force install self', function (t) {
})
})
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(base)
-}
-
function setup () {
- cleanup()
mkdirp.sync(path.resolve(installFrom, 'node_modules'))
fs.writeFileSync(
path.join(installFrom, 'package.json'),
diff --git a/deps/npm/test/tap/check-os-reqs.js b/deps/npm/test/tap/check-os-reqs.js
index 6c43fa61aa..66dcbd5328 100644
--- a/deps/npm/test/tap/check-os-reqs.js
+++ b/deps/npm/test/tap/check-os-reqs.js
@@ -2,9 +2,7 @@
var path = require('path')
var fs = require('fs')
var test = require('tap').test
-var osenv = require('osenv')
var mkdirp = require('mkdirp')
-var rimraf = require('rimraf')
var common = require('../common-tap.js')
var base = common.pkg
@@ -41,18 +39,7 @@ test('force install bad os', function (t) {
})
})
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(base)
-}
-
function setup () {
- cleanup()
mkdirp.sync(path.resolve(installFrom, 'node_modules'))
fs.writeFileSync(
path.join(installFrom, 'package.json'),
diff --git a/deps/npm/test/tap/circular-dep.js b/deps/npm/test/tap/circular-dep.js
index 624ea3800a..f7e018d023 100644
--- a/deps/npm/test/tap/circular-dep.js
+++ b/deps/npm/test/tap/circular-dep.js
@@ -4,8 +4,6 @@ var existsSync = fs.existsSync || path.existsSync
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')
@@ -75,13 +73,11 @@ test('installing a package that depends on the current package', function (t) {
})
test('cleanup', function (t) {
- cleanup()
server.close()
t.end()
})
function setup (cb) {
- cleanup()
mkdirp.sync(minimist)
fs.writeFileSync(
path.join(minimist, 'package.json'),
@@ -95,8 +91,3 @@ function setup (cb) {
cb()
})
}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/config-meta.js b/deps/npm/test/tap/config-meta.js
index 97918b8897..a98d5e6c4d 100644
--- a/deps/npm/test/tap/config-meta.js
+++ b/deps/npm/test/tap/config-meta.js
@@ -11,7 +11,7 @@ var root = path.resolve(__dirname, '..', '..')
var lib = path.resolve(root, 'lib')
var bin = path.resolve(root, 'bin')
var nm = path.resolve(root, 'node_modules')
-var doc = path.resolve(root, 'doc/misc/npm-config.md')
+var doc = path.resolve(root, 'docs/content/using-npm/config.md')
var FILES = []
var CONFS = {}
var DOC = {}
@@ -85,12 +85,12 @@ test('get lines', function (t) {
test('get docs', function (t) {
var d = fs.readFileSync(doc, 'utf8').split(/\r|\n/)
// walk down until the '## Config Settings' section
- for (var i = 0; i < d.length && d[i] !== '## Config Settings'; i++);
+ for (var i = 0; i < d.length && d[i] !== '### Config Settings'; i++);
i++
// now gather up all the ^###\s lines until the next ^##\s
- for (; i < d.length && !d[i].match(/^## /); i++) {
- if (d[i].match(/^### /)) {
- DOC[ d[i].replace(/^### /, '').trim() ] = true
+ for (; i < d.length && !d[i].match(/^### /); i++) {
+ if (d[i].match(/^#### /)) {
+ DOC[ d[i].replace(/^#### /, '').trim() ] = true
}
}
t.pass('read the docs')
diff --git a/deps/npm/test/tap/config-new-cafile.js b/deps/npm/test/tap/config-new-cafile.js
index bd5792f3e3..e4cc65ec74 100644
--- a/deps/npm/test/tap/config-new-cafile.js
+++ b/deps/npm/test/tap/config-new-cafile.js
@@ -3,22 +3,17 @@ const common = require('../common-tap.js')
var path = require('path')
var fs = require('graceful-fs')
var test = require('tap').test
-var mkdirp = require('mkdirp')
var rimraf = require('rimraf')
-var osenv = require('osenv')
var npmconf = require('../../lib/config/core.js')
var dir = common.pkg
var beep = path.resolve(dir, 'beep.pem')
var npmrc = path.resolve(dir, 'npmrc')
-test('setup', function (t) {
- bootstrap()
- t.end()
-})
-
test('can set new cafile when old is gone', function (t) {
t.plan(5)
+ fs.writeFileSync(npmrc, '')
+ fs.writeFileSync(beep, '')
npmconf.load({ userconfig: npmrc }, function (error, conf) {
npmconf.loaded = false
t.ifError(error)
@@ -40,19 +35,3 @@ test('can set new cafile when old is gone', function (t) {
})
})
})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function bootstrap () {
- mkdirp.sync(dir)
- fs.writeFileSync(npmrc, '')
- fs.writeFileSync(beep, '')
-}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(dir)
-}
diff --git a/deps/npm/test/tap/correct-mkdir.js b/deps/npm/test/tap/correct-mkdir.js
index 30907d725c..175fb34a00 100644
--- a/deps/npm/test/tap/correct-mkdir.js
+++ b/deps/npm/test/tap/correct-mkdir.js
@@ -5,11 +5,7 @@ var assert = require('assert')
var requireInject = require('require-inject')
const common = require('../common-tap.js')
var cache_dir = common.pkg
-
-if (process.platform === 'win32') {
- t.plan(0, 'windows does not use correct-mkdir behavior')
- process.exit(0)
-}
+common.skipIfWindows('windows does not use correct-mkdir behavior')
test('correct-mkdir: no race conditions', function (t) {
var mock_fs = {}
diff --git a/deps/npm/test/tap/do-not-remove-other-bins.js b/deps/npm/test/tap/do-not-remove-other-bins.js
index 4e6b0d27b2..a614043221 100644
--- a/deps/npm/test/tap/do-not-remove-other-bins.js
+++ b/deps/npm/test/tap/do-not-remove-other-bins.js
@@ -3,8 +3,6 @@ var fs = require('fs')
var path = require('path')
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap')
@@ -41,7 +39,6 @@ var EXEC_OPTS = {
}
test('setup', function (t) {
- cleanup()
mkdirp.sync(path.join(installPath, 'node_modules'))
mkdirp.sync(packageApath)
fs.writeFileSync(
@@ -118,14 +115,3 @@ test('verify postremoval bins', function (t) {
t.is(bin, path.join(installPath, 'node_modules', 'b'))
t.end()
})
-
-test('cleanup', function (t) {
- cleanup()
- t.pass('cleaned up')
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(base)
-}
diff --git a/deps/npm/test/tap/fund.js b/deps/npm/test/tap/fund.js
new file mode 100644
index 0000000000..cc66bea51a
--- /dev/null
+++ b/deps/npm/test/tap/fund.js
@@ -0,0 +1,298 @@
+'use strict'
+
+const fs = require('fs')
+const path = require('path')
+
+const test = require('tap').test
+const Tacks = require('tacks')
+const Dir = Tacks.Dir
+const File = Tacks.File
+const common = require('../common-tap.js')
+const isWindows = require('../../lib/utils/is-windows.js')
+
+const base = common.pkg
+const noFunding = path.join(base, 'no-funding-package')
+const maintainerOwnsAllDeps = path.join(base, 'maintainer-owns-all-deps')
+const nestedNoFundingPackages = path.join(base, 'nested-no-funding-packages')
+
+function getFixturePackage ({ name, version, dependencies, funding }, extras) {
+ const getDeps = () => Object
+ .keys(dependencies)
+ .reduce((res, dep) => (Object.assign({}, res, {
+ [dep]: '*'
+ })), {})
+
+ return Dir(Object.assign({
+ 'package.json': File({
+ name,
+ version: version || '1.0.0',
+ funding: (funding === undefined) ? {
+ type: 'individual',
+ url: 'http://example.com/donate'
+ } : funding,
+ dependencies: dependencies && getDeps(dependencies)
+ })
+ }, extras))
+}
+
+const fixture = new Tacks(Dir({
+ 'no-funding-package': Dir({
+ 'package.json': File({
+ name: 'no-funding-package',
+ version: '0.0.0'
+ })
+ }),
+ 'maintainer-owns-all-deps': getFixturePackage({
+ name: 'maintainer-owns-all-deps',
+ dependencies: {
+ 'dep-foo': '*',
+ 'dep-bar': '*'
+ }
+ }, {
+ node_modules: Dir({
+ 'dep-foo': getFixturePackage({
+ name: 'dep-foo',
+ dependencies: {
+ 'dep-sub-foo': '*'
+ }
+ }, {
+ node_modules: Dir({
+ 'dep-sub-foo': getFixturePackage({
+ name: 'dep-sub-foo'
+ })
+ })
+ }),
+ 'dep-bar': getFixturePackage({
+ name: 'dep-bar'
+ })
+ })
+ }),
+ 'nested-no-funding-packages': getFixturePackage({
+ name: 'nested-no-funding-packages',
+ funding: null,
+ dependencies: {
+ foo: '*'
+ },
+ devDependencies: {
+ lorem: '*'
+ }
+ }, {
+ node_modules: Dir({
+ foo: getFixturePackage({
+ name: 'foo',
+ dependencies: {
+ bar: '*'
+ },
+ funding: null
+ }, {
+ node_modules: Dir({
+ bar: getFixturePackage({
+ name: 'bar'
+ }, {
+ node_modules: Dir({
+ 'sub-bar': getFixturePackage({
+ name: 'sub-bar',
+ funding: {
+ url: 'https://example.com/sponsor'
+ }
+ })
+ })
+ })
+ })
+ }),
+ lorem: getFixturePackage({
+ name: 'lorem',
+ funding: {
+ url: 'https://example.com/lorem'
+ }
+ })
+ })
+ })
+}))
+
+function checkOutput (t, { code, stdout, stderr }) {
+ t.is(code, 0, `exited code 0`)
+ t.is(stderr, '', 'no warnings')
+}
+
+function jsonTest (t, { assertionMsg, expected, stdout }) {
+ let parsed = JSON.parse(stdout)
+ t.deepEqual(parsed, expected, assertionMsg)
+}
+
+function snapshotTest (t, { stdout, assertionMsg }) {
+ t.matchSnapshot(stdout, assertionMsg)
+}
+
+function testFundCmd ({ title, assertionMsg, args = [], opts = {}, output = checkOutput, assertion = snapshotTest, expected }) {
+ const validate = (t) => (err, code, stdout, stderr) => {
+ if (err) throw err
+
+ output(t, { code, stdout, stderr })
+ assertion(t, { assertionMsg, expected, stdout })
+ }
+
+ return test(title, (t) => {
+ t.plan(3)
+ common.npm(['fund', '--unicode=false'].concat(args), opts, validate(t))
+ })
+}
+
+test('setup', function (t) {
+ fixture.remove(base)
+ fixture.create(base)
+ t.end()
+})
+
+testFundCmd({
+ title: 'fund with no package containing funding',
+ assertionMsg: 'should print empty funding info',
+ opts: { cwd: noFunding }
+})
+
+testFundCmd({
+ title: 'fund in which same maintainer owns all its deps',
+ assertionMsg: 'should print stack packages together',
+ opts: { cwd: maintainerOwnsAllDeps }
+})
+
+testFundCmd({
+ title: 'fund in which same maintainer owns all its deps, using --json option',
+ assertionMsg: 'should print stack packages together',
+ args: ['--json'],
+ opts: { cwd: maintainerOwnsAllDeps },
+ assertion: jsonTest,
+ expected: {
+ length: 3,
+ name: 'maintainer-owns-all-deps',
+ version: '1.0.0',
+ funding: { type: 'individual', url: 'http://example.com/donate' },
+ dependencies: {
+ 'dep-bar': {
+ version: '1.0.0',
+ funding: { type: 'individual', url: 'http://example.com/donate' }
+ },
+ 'dep-foo': {
+ version: '1.0.0',
+ funding: { type: 'individual', url: 'http://example.com/donate' },
+ dependencies: {
+ 'dep-sub-foo': {
+ version: '1.0.0',
+ funding: { type: 'individual', url: 'http://example.com/donate' }
+ }
+ }
+ }
+ }
+ }
+})
+
+testFundCmd({
+ title: 'fund containing multi-level nested deps with no funding',
+ assertionMsg: 'should omit dependencies with no funding declared',
+ opts: { cwd: nestedNoFundingPackages }
+})
+
+testFundCmd({
+ title: 'fund containing multi-level nested deps with no funding, using --json option',
+ assertionMsg: 'should omit dependencies with no funding declared',
+ args: ['--json'],
+ opts: { cwd: nestedNoFundingPackages },
+ assertion: jsonTest,
+ expected: {
+ length: 3,
+ name: 'nested-no-funding-packages',
+ version: '1.0.0',
+ dependencies: {
+ lorem: { version: '1.0.0', funding: { url: 'https://example.com/lorem' } },
+ bar: {
+ version: '1.0.0',
+ funding: { type: 'individual', url: 'http://example.com/donate' },
+ dependencies: {
+ 'sub-bar': {
+ version: '1.0.0',
+ funding: { url: 'https://example.com/sponsor' }
+ }
+ }
+ }
+ }
+ }
+})
+
+testFundCmd({
+ title: 'fund does not support global',
+ assertionMsg: 'should throw EFUNDGLOBAL error',
+ args: ['--global'],
+ output: (t, { code, stdout, stderr }) => {
+ t.is(code, 1, `exited code 0`)
+ const [ errCode, errCmd ] = stderr.split('\n')
+ t.matchSnapshot(`${errCode}\n${errCmd}`, 'should write error msgs to stderr')
+ }
+})
+
+testFundCmd({
+ title: 'fund does not support global, using --json option',
+ assertionMsg: 'should throw EFUNDGLOBAL error',
+ args: ['--global', '--json'],
+ output: (t, { code, stdout, stderr }) => {
+ t.is(code, 1, `exited code 0`)
+ const [ errCode, errCmd ] = stderr.split('\n')
+ t.matchSnapshot(`${errCode}\n${errCmd}`, 'should write error msgs to stderr')
+ },
+ assertion: jsonTest,
+ expected: {
+ error: {
+ code: 'EFUNDGLOBAL',
+ summary: '`npm fund` does not support globals',
+ detail: ''
+ }
+ }
+})
+
+testFundCmd({
+ title: 'fund using package argument with no browser',
+ assertionMsg: 'should open funding url',
+ args: ['.', '--no-browser'],
+ opts: { cwd: maintainerOwnsAllDeps }
+})
+
+testFundCmd({
+ title: 'fund using package argument with no browser, using --json option',
+ assertionMsg: 'should open funding url',
+ args: ['.', '--json', '--no-browser'],
+ opts: { cwd: maintainerOwnsAllDeps },
+ assertion: jsonTest,
+ expected: {
+ title: 'individual funding available at the following URL',
+ url: 'http://example.com/donate'
+ }
+})
+
+if (!isWindows) {
+ test('fund using package argument', function (t) {
+ const fakeBrowser = path.join(common.pkg, '_script.sh')
+ const outFile = path.join(common.pkg, '_output')
+
+ const s = '#!/usr/bin/env bash\n' +
+ 'echo "$@" > ' + JSON.stringify(common.pkg) + '/_output\n'
+ fs.writeFileSync(fakeBrowser, s)
+ fs.chmodSync(fakeBrowser, '0755')
+
+ common.npm([
+ 'fund', '.',
+ '--loglevel=silent',
+ '--browser=' + fakeBrowser
+ ], { cwd: maintainerOwnsAllDeps }, function (err, code, stdout, stderr) {
+ t.ifError(err, 'repo command ran without error')
+ t.equal(code, 0, 'exit ok')
+ var res = fs.readFileSync(outFile, 'utf8')
+ t.equal(res, 'http://example.com/donate\n')
+ t.end()
+ })
+ })
+}
+
+test('cleanup', function (t) {
+ t.pass(base)
+ fixture.remove(base)
+ t.end()
+})
diff --git a/deps/npm/test/tap/gist-short-shortcut-package.js b/deps/npm/test/tap/gist-short-shortcut-package.js
index e5e67f21a0..601d53a827 100644
--- a/deps/npm/test/tap/gist-short-shortcut-package.js
+++ b/deps/npm/test/tap/gist-short-shortcut-package.js
@@ -3,9 +3,7 @@ var fs = require('graceful-fs')
var path = require('path')
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
var requireInject = require('require-inject')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
@@ -63,13 +61,7 @@ test('gist-short-shortcut-package', function (t) {
})
})
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
function setup () {
- cleanup()
mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
@@ -77,8 +69,3 @@ function setup () {
)
process.chdir(pkg)
}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/gist-short-shortcut.js b/deps/npm/test/tap/gist-short-shortcut.js
index 2fcf63d53e..82c9ae1750 100644
--- a/deps/npm/test/tap/gist-short-shortcut.js
+++ b/deps/npm/test/tap/gist-short-shortcut.js
@@ -3,9 +3,7 @@ var fs = require('graceful-fs')
var path = require('path')
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
var requireInject = require('require-inject')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
@@ -60,13 +58,7 @@ test('gist-shortcut', function (t) {
})
})
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
function setup () {
- cleanup()
mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
@@ -74,8 +66,3 @@ function setup () {
)
process.chdir(pkg)
}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/gist-shortcut-package.js b/deps/npm/test/tap/gist-shortcut-package.js
index 06b4383583..28e57357cc 100644
--- a/deps/npm/test/tap/gist-shortcut-package.js
+++ b/deps/npm/test/tap/gist-shortcut-package.js
@@ -2,10 +2,7 @@
var fs = require('graceful-fs')
var path = require('path')
-var mkdirp = require('mkdirp')
-var osenv = require('osenv')
var requireInject = require('require-inject')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
@@ -20,12 +17,8 @@ var json = {
}
}
-test('setup', function (t) {
- setup()
- t.end()
-})
-
test('gist-shortcut-package', function (t) {
+ setup()
var cloneUrls = [
['git://gist.github.com/deadbeef.git', 'GitHub gist shortcuts try git URLs first'],
['https://gist.github.com/deadbeef.git', 'GitHub gist shortcuts try HTTPS URLs second'],
@@ -63,22 +56,10 @@ test('gist-shortcut-package', function (t) {
})
})
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
function setup () {
- cleanup()
- mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
JSON.stringify(json, null, 2)
)
process.chdir(pkg)
}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/gist-shortcut.js b/deps/npm/test/tap/gist-shortcut.js
index e5f200f5fd..ca86d6bc55 100644
--- a/deps/npm/test/tap/gist-shortcut.js
+++ b/deps/npm/test/tap/gist-shortcut.js
@@ -2,10 +2,7 @@
var fs = require('graceful-fs')
var path = require('path')
-var mkdirp = require('mkdirp')
-var osenv = require('osenv')
var requireInject = require('require-inject')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
@@ -17,12 +14,12 @@ var json = {
version: '0.0.0'
}
-test('setup', function (t) {
- setup()
- t.end()
-})
-
test('gist-shortcut', function (t) {
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ process.chdir(pkg)
var cloneUrls = [
['git://gist.github.com/deadbeef.git', 'GitHub gist shortcuts try git URLs first'],
['https://gist.github.com/deadbeef.git', 'GitHub gist shortcuts try HTTPS URLs second'],
@@ -59,23 +56,3 @@ test('gist-shortcut', function (t) {
})
})
})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function setup () {
- cleanup()
- mkdirp.sync(pkg)
- fs.writeFileSync(
- path.join(pkg, 'package.json'),
- JSON.stringify(json, null, 2)
- )
- process.chdir(pkg)
-}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/git-dependency-install-link.js b/deps/npm/test/tap/git-dependency-install-link.js
index 44438e7f95..d80beab057 100644
--- a/deps/npm/test/tap/git-dependency-install-link.js
+++ b/deps/npm/test/tap/git-dependency-install-link.js
@@ -1,7 +1,6 @@
var fs = require('fs')
var resolve = require('path').resolve
-var osenv = require('osenv')
var mkdirp = require('mkdirp')
var rimraf = require('rimraf')
var test = require('tap').test
@@ -11,9 +10,9 @@ var mr = require('npm-registry-mock')
var npm = require('../../lib/npm.js')
var common = require('../common-tap.js')
-var pkg = common.pkg
-var repo = pkg + '-repo'
-var prefix = pkg + '-prefix'
+var pkg = resolve(common.pkg, 'package')
+var repo = resolve(common.pkg, 'repo')
+var prefix = resolve(common.pkg, 'prefix')
var cache = common.cache
var daemon
@@ -42,8 +41,8 @@ var pjChild = JSON.stringify({
}, null, 2) + '\n'
test('setup', function (t) {
- bootstrap()
- setup(function (er, r) {
+ t.test('bootstrap', t => bootstrap(t.end))
+ t.test('setup', t => setup(function (er, r) {
t.ifError(er, 'git started up successfully')
if (!er) {
@@ -59,7 +58,8 @@ test('setup', function (t) {
t.end()
})
- })
+ }))
+ t.end()
})
test('install from git repo [no --link]', function (t) {
@@ -103,20 +103,20 @@ test('install from git repo [with --link]', function (t) {
test('clean', function (t) {
mockRegistry.close()
- daemon.on('close', function () {
- cleanup()
- t.end()
- })
+ daemon.on('close', t.end)
process.kill(daemonPID)
})
-function bootstrap () {
- rimraf.sync(repo)
- rimraf.sync(pkg)
- mkdirp.sync(pkg)
- mkdirp.sync(cache)
+function bootstrap (cb) {
+ rimraf(repo, () => {
+ rimraf(pkg, () => {
+ mkdirp.sync(pkg)
+ mkdirp.sync(cache)
- fs.writeFileSync(resolve(pkg, 'package.json'), pjParent)
+ fs.writeFileSync(resolve(pkg, 'package.json'), pjParent)
+ cb()
+ })
+ })
}
function setup (cb) {
@@ -170,10 +170,3 @@ function setup (cb) {
}, cb)
})
}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(repo)
- rimraf.sync(prefix)
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/git-prepare.js b/deps/npm/test/tap/git-prepare.js
index 37534fbfc4..072f4dfc44 100644
--- a/deps/npm/test/tap/git-prepare.js
+++ b/deps/npm/test/tap/git-prepare.js
@@ -3,8 +3,6 @@
const fs = require('fs')
const path = require('path')
-const osenv = require('osenv')
-const rimraf = require('rimraf')
const test = require('tap').test
const mr = require('npm-registry-mock')
@@ -68,7 +66,7 @@ const fixture = new Tacks(Dir({
}))
test('setup', function (t) {
- bootstrap()
+ fixture.create(testdir)
setup(function (er, r) {
t.ifError(er, 'git started up successfully')
@@ -115,17 +113,10 @@ test('install from git repo with prepare script', function (t) {
test('clean', function (t) {
mockRegistry.close()
- daemon.on('close', function () {
- cleanup()
- t.end()
- })
+ daemon.on('close', t.end)
process.kill(daemonPID)
})
-function bootstrap () {
- fixture.create(testdir)
-}
-
function setup (cb) {
npm.load({
prefix: testdir,
@@ -173,8 +164,3 @@ function setup (cb) {
}, cb)
})
}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(testdir)
-}
diff --git a/deps/npm/test/tap/github-shortcut-package.js b/deps/npm/test/tap/github-shortcut-package.js
index db153ba352..444520308a 100644
--- a/deps/npm/test/tap/github-shortcut-package.js
+++ b/deps/npm/test/tap/github-shortcut-package.js
@@ -2,10 +2,7 @@
var fs = require('graceful-fs')
var path = require('path')
-var mkdirp = require('mkdirp')
-var osenv = require('osenv')
var requireInject = require('require-inject')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
@@ -20,12 +17,12 @@ var json = {
}
}
-test('setup', function (t) {
- setup()
- t.end()
-})
-
test('github-shortcut-package', function (t) {
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ process.chdir(pkg)
var cloneUrls = [
['git://github.com/foo/private.git', 'GitHub shortcuts try git URLs first'],
['https://github.com/foo/private.git', 'GitHub shortcuts try HTTPS URLs second'],
@@ -62,23 +59,3 @@ test('github-shortcut-package', function (t) {
})
})
})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function setup () {
- cleanup()
- mkdirp.sync(pkg)
- fs.writeFileSync(
- path.join(pkg, 'package.json'),
- JSON.stringify(json, null, 2)
- )
- process.chdir(pkg)
-}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/github-shortcut.js b/deps/npm/test/tap/github-shortcut.js
index 0c89d428fa..59c7e39ea9 100644
--- a/deps/npm/test/tap/github-shortcut.js
+++ b/deps/npm/test/tap/github-shortcut.js
@@ -5,10 +5,7 @@ const BB = require('bluebird')
const fs = require('graceful-fs')
const path = require('path')
-const mkdirp = require('mkdirp')
-const osenv = require('osenv')
const requireInject = require('require-inject')
-const rimraf = require('rimraf')
const test = require('tap').test
const common = require('../common-tap.js')
@@ -20,12 +17,12 @@ const json = {
version: '0.0.0'
}
-test('setup', function (t) {
- setup()
- t.end()
-})
-
test('github-shortcut', function (t) {
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ process.chdir(pkg)
const cloneUrls = [
['git://github.com/foo/private.git', 'GitHub shortcuts try git URLs first'],
['https://github.com/foo/private.git', 'GitHub shortcuts try HTTPS URLs second'],
@@ -62,23 +59,3 @@ test('github-shortcut', function (t) {
})
})
})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function setup () {
- cleanup()
- mkdirp.sync(pkg)
- fs.writeFileSync(
- path.join(pkg, 'package.json'),
- JSON.stringify(json, null, 2)
- )
- process.chdir(pkg)
-}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/gitlab-shortcut-package.js b/deps/npm/test/tap/gitlab-shortcut-package.js
index 4f5b43851d..9b431ff7b6 100644
--- a/deps/npm/test/tap/gitlab-shortcut-package.js
+++ b/deps/npm/test/tap/gitlab-shortcut-package.js
@@ -2,10 +2,7 @@
var fs = require('graceful-fs')
var path = require('path')
-var mkdirp = require('mkdirp')
-var osenv = require('osenv')
var requireInject = require('require-inject')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
@@ -20,12 +17,12 @@ var json = {
}
}
-test('setup', function (t) {
- setup()
- t.end()
-})
-
test('gitlab-shortcut-package', function (t) {
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ process.chdir(pkg)
var cloneUrls = [
['https://gitlab.com/foo/private.git', 'GitLab shortcuts try HTTPS URLs second'],
['ssh://git@gitlab.com/foo/private.git', 'GitLab shortcuts try SSH first']
@@ -61,23 +58,3 @@ test('gitlab-shortcut-package', function (t) {
})
})
})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function setup () {
- cleanup()
- mkdirp.sync(pkg)
- fs.writeFileSync(
- path.join(pkg, 'package.json'),
- JSON.stringify(json, null, 2)
- )
- process.chdir(pkg)
-}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/gitlab-shortcut.js b/deps/npm/test/tap/gitlab-shortcut.js
index e6bd54765a..344311b45f 100644
--- a/deps/npm/test/tap/gitlab-shortcut.js
+++ b/deps/npm/test/tap/gitlab-shortcut.js
@@ -2,10 +2,7 @@
var fs = require('graceful-fs')
var path = require('path')
-var mkdirp = require('mkdirp')
-var osenv = require('osenv')
var requireInject = require('require-inject')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
@@ -17,12 +14,12 @@ var json = {
version: '0.0.0'
}
-test('setup', function (t) {
- setup()
- t.end()
-})
-
test('gitlab-shortcut', function (t) {
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ process.chdir(pkg)
var cloneUrls = [
['https://gitlab.com/foo/private.git', 'GitLab shortcuts try HTTPS URLs second'],
['ssh://git@gitlab.com/foo/private.git', 'GitLab shortcuts try SSH first']
@@ -58,23 +55,3 @@ test('gitlab-shortcut', function (t) {
})
})
})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function setup () {
- cleanup()
- mkdirp.sync(pkg)
- fs.writeFileSync(
- path.join(pkg, 'package.json'),
- JSON.stringify(json, null, 2)
- )
- process.chdir(pkg)
-}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/graceful-restart.js b/deps/npm/test/tap/graceful-restart.js
index 740561bd79..787aa98894 100644
--- a/deps/npm/test/tap/graceful-restart.js
+++ b/deps/npm/test/tap/graceful-restart.js
@@ -1,13 +1,7 @@
var fs = require('fs')
var resolve = require('path').resolve
-
-var osenv = require('osenv')
-var mkdirp = require('mkdirp')
-var rimraf = require('rimraf')
var test = require('tap').test
-
var common = require('../common-tap.js')
-
var pkg = common.pkg
var outGraceless = [
@@ -60,11 +54,6 @@ var pjGraceful = JSON.stringify({
}
}, null, 2) + '\n'
-test('setup', function (t) {
- bootstrap()
- t.end()
-})
-
test('graceless restart', function (t) {
fs.writeFileSync(resolve(pkg, 'package.json'), pjGraceless)
createChild(['run-script', 'restart'], function (err, code, out) {
@@ -85,20 +74,6 @@ test('graceful restart', function (t) {
})
})
-test('clean', function (t) {
- cleanup()
- t.end()
-})
-
-function bootstrap () {
- mkdirp.sync(pkg)
-}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
-
function createChild (args, cb) {
var env = {
HOME: process.env.HOME,
diff --git a/deps/npm/test/tap/ignore-install-link.js b/deps/npm/test/tap/ignore-install-link.js
index a2caa23dfd..038b9448d7 100644
--- a/deps/npm/test/tap/ignore-install-link.js
+++ b/deps/npm/test/tap/ignore-install-link.js
@@ -1,8 +1,5 @@
-if (process.platform === 'win32') {
- require('tap').plan(0, 'symlinks are weird on windows, skip this test')
- process.exit(0)
-}
var common = require('../common-tap.js')
+common.skipIfWindows('symlinks are weird on windows')
var test = require('tap').test
var path = require('path')
var fs = require('fs')
diff --git a/deps/npm/test/tap/init-interrupt.js b/deps/npm/test/tap/init-interrupt.js
index 114bb2bacb..38c38053e5 100644
--- a/deps/npm/test/tap/init-interrupt.js
+++ b/deps/npm/test/tap/init-interrupt.js
@@ -2,21 +2,12 @@
// if 'npm init' is interrupted with ^C, don't report
// 'init written successfully'
var test = require('tap').test
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var npmlog = require('npmlog')
var requireInject = require('require-inject')
var npm = require('../../lib/npm.js')
-const common = require('../common-tap.js')
-var PKG_DIR = common.pkg
-
-test('setup', function (t) {
- cleanup()
-
- t.end()
-})
+require('../common-tap.js')
test('issue #6684 remove confusing message', function (t) {
var initJsonMock = function (dir, input, config, cb) {
@@ -45,14 +36,3 @@ test('issue #6684 remove confusing message', function (t) {
})
})
})
-
-test('cleanup', function (t) {
- cleanup()
-
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(PKG_DIR)
-}
diff --git a/deps/npm/test/tap/install-at-locally.js b/deps/npm/test/tap/install-at-locally.js
index 705c2df119..e4920d22d1 100644
--- a/deps/npm/test/tap/install-at-locally.js
+++ b/deps/npm/test/tap/install-at-locally.js
@@ -2,7 +2,6 @@ var fs = require('graceful-fs')
var path = require('path')
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
var rimraf = require('rimraf')
var test = require('tap').test
@@ -17,11 +16,6 @@ var json = {
version: '0.0.0'
}
-test('setup', function (t) {
- cleanup()
- t.end()
-})
-
test('\'npm install ./package@1.2.3\' should install local pkg', function (t) {
var target = './package@1.2.3'
setup(target)
@@ -46,18 +40,8 @@ test('\'npm install install/at/locally@./package@1.2.3\' should install local pk
})
})
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
-
function setup (target) {
- cleanup()
+ rimraf.sync(pkg)
var root = path.resolve(pkg, target)
mkdirp.sync(root)
fs.writeFileSync(
@@ -65,5 +49,4 @@ function setup (target) {
JSON.stringify(json, null, 2)
)
mkdirp.sync(path.resolve(pkg, 'node_modules'))
- process.chdir(pkg)
}
diff --git a/deps/npm/test/tap/install-at-sub-path-locally.js b/deps/npm/test/tap/install-at-sub-path-locally.js
index 08b64746af..931d29bbd2 100644
--- a/deps/npm/test/tap/install-at-sub-path-locally.js
+++ b/deps/npm/test/tap/install-at-sub-path-locally.js
@@ -2,13 +2,11 @@ var fs = require('graceful-fs')
var path = require('path')
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
-var pkg = common.pkg
+var pkg = path.resolve(common.pkg, 'package')
var EXEC_OPTS = { cwd: pkg, stdio: [0, 1, 2] }
@@ -20,12 +18,17 @@ var json = {
var target = '../package@1.2.3'
test('setup', function (t) {
- cleanup()
+ var root = path.resolve(pkg, target)
+ mkdirp.sync(root)
+ fs.writeFileSync(
+ path.join(root, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ mkdirp.sync(path.resolve(pkg, 'node_modules'))
t.end()
})
test('\'npm install ../package@1.2.3\' should install local pkg from sub path', function (t) {
- setup()
common.npm(['install', '--loglevel=silent', target], EXEC_OPTS, function (err, code) {
if (err) throw err
var p = path.resolve(pkg, 'node_modules/install-at-sub-path-locally-mock/package.json')
@@ -44,26 +47,3 @@ test('\'running npm install ../package@1.2.3\' should not break on sub path re-i
t.end()
})
})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
- rimraf.sync(path.resolve(pkg, target))
-}
-
-function setup () {
- cleanup()
- var root = path.resolve(pkg, target)
- mkdirp.sync(root)
- fs.writeFileSync(
- path.join(root, 'package.json'),
- JSON.stringify(json, null, 2)
- )
- mkdirp.sync(path.resolve(pkg, 'node_modules'))
- process.chdir(pkg)
-}
diff --git a/deps/npm/test/tap/install-bad-dep-format.js b/deps/npm/test/tap/install-bad-dep-format.js
index d01996f155..9d9a413835 100644
--- a/deps/npm/test/tap/install-bad-dep-format.js
+++ b/deps/npm/test/tap/install-bad-dep-format.js
@@ -2,8 +2,6 @@ var fs = require('graceful-fs')
var path = require('path')
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
@@ -18,8 +16,13 @@ var json = {
}
test('invalid url format returns appropriate error', function (t) {
- setup(json)
- common.npm(['install'], {}, function (err, code, stdout, stderr) {
+ var pkgPath = path.resolve(common.pkg, json.name)
+ mkdirp.sync(pkgPath)
+ fs.writeFileSync(
+ path.join(pkgPath, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ common.npm(['install'], {cwd: pkgPath}, function (err, code, stdout, stderr) {
t.ifError(err, 'install ran without error')
t.equals(code, 1, 'install exited with code 1')
t.match(stderr,
@@ -28,31 +31,3 @@ test('invalid url format returns appropriate error', function (t) {
t.end()
})
})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function setup (json) {
- cleanup()
- process.chdir(mkPkg(json))
-}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- var pkgs = [json]
- pkgs.forEach(function (json) {
- rimraf.sync(path.resolve(common.pkg, json.name))
- })
-}
-
-function mkPkg (json) {
- var pkgPath = path.resolve(common.pkg, json.name)
- mkdirp.sync(pkgPath)
- fs.writeFileSync(
- path.join(pkgPath, 'package.json'),
- JSON.stringify(json, null, 2)
- )
- return pkgPath
-}
diff --git a/deps/npm/test/tap/install-bad-man.js b/deps/npm/test/tap/install-bad-man.js
index 98c8e9a7e0..0aa83a21c5 100644
--- a/deps/npm/test/tap/install-bad-man.js
+++ b/deps/npm/test/tap/install-bad-man.js
@@ -1,15 +1,13 @@
var fs = require('fs')
var resolve = require('path').resolve
-var osenv = require('osenv')
var mkdirp = require('mkdirp')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
-var pkg = common.pkg
-var target = pkg + '-target'
+var pkg = resolve(common.pkg, 'package')
+var target = resolve(common.pkg, 'target')
var EXEC_OPTS = {
cwd: target
@@ -21,11 +19,17 @@ var json = {
man: [ './install-bad-man.1.lol' ]
}
-common.pendIfWindows('man pages do not get installed on Windows')
+common.skipIfWindows('man pages do not get installed on Windows')
test('setup', function (t) {
- setup()
- t.pass('setup ran')
+ mkdirp.sync(pkg)
+ // make sure it installs locally
+ mkdirp.sync(resolve(target, 'node_modules'))
+ fs.writeFileSync(
+ resolve(pkg, 'package.json'),
+ JSON.stringify(json, null, 2) + '\n'
+ )
+ fs.writeFileSync(resolve(pkg, 'install-bad-man.1.lol'), 'lol\n')
t.end()
})
@@ -55,27 +59,3 @@ test("install from repo on 'OS X'", function (t) {
}
)
})
-
-test('clean', function (t) {
- cleanup()
- t.pass('cleaned up')
- t.end()
-})
-
-function setup () {
- cleanup()
- mkdirp.sync(pkg)
- // make sure it installs locally
- mkdirp.sync(resolve(target, 'node_modules'))
- fs.writeFileSync(
- resolve(pkg, 'package.json'),
- JSON.stringify(json, null, 2) + '\n'
- )
- fs.writeFileSync(resolve(pkg, 'install-bad-man.1.lol'), 'lol\n')
-}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
- rimraf.sync(target)
-}
diff --git a/deps/npm/test/tap/install-bin-null.js b/deps/npm/test/tap/install-bin-null.js
index 7a87a2e0bb..2ad75eb599 100644
--- a/deps/npm/test/tap/install-bin-null.js
+++ b/deps/npm/test/tap/install-bin-null.js
@@ -2,8 +2,6 @@ var fs = require('graceful-fs')
var path = require('path')
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
@@ -43,49 +41,33 @@ var grandchildPkg = {
var pkgs = [childPkgA, childPkgB, grandchildPkg]
-test('the grandchild has bin:null', function (t) {
- setup()
- common.npm(['install'], EXEC_OPTS, function (err, code, stdout, stderr) {
- t.ifErr(err, 'npm link finished without error')
- t.equal(code, 0, 'exited ok')
- t.ok(stdout, 'output indicating success')
- t.notOk(stderr, 'no output stderr')
- t.end()
- })
-})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
-
-function setup () {
- cleanup()
+test('setup', t => {
mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
JSON.stringify(parentPkg, null, 2)
)
pkgs.forEach(function (json) {
- process.chdir(mkPkg(json))
+ var pkgPath = path.resolve(pkg, json.name)
+ mkdirp.sync(pkgPath)
+ fs.writeFileSync(
+ path.join(pkgPath, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
})
fs.writeFileSync(
path.join(pkg, childPkgA.name, 'index.js'),
''
)
-}
+ t.end()
+})
-function mkPkg (json) {
- var pkgPath = path.resolve(pkg, json.name)
- mkdirp.sync(pkgPath)
- fs.writeFileSync(
- path.join(pkgPath, 'package.json'),
- JSON.stringify(json, null, 2)
- )
- return pkgPath
-}
+test('the grandchild has bin:null', function (t) {
+ common.npm(['install'], EXEC_OPTS, function (err, code, stdout, stderr) {
+ t.ifErr(err, 'npm link finished without error')
+ t.equal(code, 0, 'exited ok')
+ t.ok(stdout, 'output indicating success')
+ t.notOk(stderr, 'no output stderr')
+ t.end()
+ })
+})
diff --git a/deps/npm/test/tap/install-cli-only-development.js b/deps/npm/test/tap/install-cli-only-development.js
index a68c0f8aac..6f03931d80 100644
--- a/deps/npm/test/tap/install-cli-only-development.js
+++ b/deps/npm/test/tap/install-cli-only-development.js
@@ -3,9 +3,8 @@ var path = require('path')
var existsSync = fs.existsSync || path.existsSync
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
var rimraf = require('rimraf')
-var test = require('tap').test
+const t = require('tap')
var common = require('../common-tap.js')
@@ -37,13 +36,29 @@ var devDependency = {
version: '0.0.0'
}
-test('setup', function (t) {
- setup()
- t.pass('setup ran')
+t.test('setup', t => {
+ mkdirp.sync(path.join(pkg, 'dependency'))
+ fs.writeFileSync(
+ path.join(pkg, 'dependency', 'package.json'),
+ JSON.stringify(dependency, null, 2)
+ )
+
+ mkdirp.sync(path.join(pkg, 'dev-dependency'))
+ fs.writeFileSync(
+ path.join(pkg, 'dev-dependency', 'package.json'),
+ JSON.stringify(devDependency, null, 2)
+ )
+
+ mkdirp.sync(path.join(pkg, 'node_modules'))
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+
t.end()
})
-test('\'npm install --only=development\' should only install devDependencies', function (t) {
+t.test('\'npm install --only=development\' should only install devDependencies', function (t) {
common.npm(['install', '--only=development'], EXEC_OPTS, function (err, code) {
t.ifError(err, 'install development successful')
t.equal(code, 0, 'npm install did not raise error code')
@@ -57,14 +72,11 @@ test('\'npm install --only=development\' should only install devDependencies', f
existsSync(path.resolve(pkg, 'node_modules/dependency/package.json')),
'dependency was NOT installed'
)
- t.end()
+ rimraf(path.join(pkg, 'node_modules'), t.end)
})
})
-test('\'npm install --only=development\' should only install devDependencies regardless of npm.config.get(\'production\')', function (t) {
- cleanup()
- setup()
-
+t.test('\'npm install --only=development\' should only install devDependencies regardless of npm.config.get(\'production\')', function (t) {
common.npm(['install', '--only=development', '--production'], EXEC_OPTS, function (err, code) {
t.ifError(err, 'install development successful')
t.equal(code, 0, 'npm install did not raise error code')
@@ -78,38 +90,6 @@ test('\'npm install --only=development\' should only install devDependencies reg
existsSync(path.resolve(pkg, 'node_modules/dependency/package.json')),
'dependency was NOT installed'
)
- t.end()
+ rimraf(path.join(pkg, 'node_modules'), t.end)
})
})
-
-test('cleanup', function (t) {
- cleanup()
- t.pass('cleaned up')
- t.end()
-})
-
-function setup () {
- mkdirp.sync(path.join(pkg, 'dependency'))
- fs.writeFileSync(
- path.join(pkg, 'dependency', 'package.json'),
- JSON.stringify(dependency, null, 2)
- )
-
- mkdirp.sync(path.join(pkg, 'dev-dependency'))
- fs.writeFileSync(
- path.join(pkg, 'dev-dependency', 'package.json'),
- JSON.stringify(devDependency, null, 2)
- )
-
- mkdirp.sync(path.join(pkg, 'node_modules'))
- fs.writeFileSync(
- path.join(pkg, 'package.json'),
- JSON.stringify(json, null, 2)
- )
- process.chdir(pkg)
-}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/install-cli-only-production.js b/deps/npm/test/tap/install-cli-only-production.js
index e43692d3d7..63863ff934 100644
--- a/deps/npm/test/tap/install-cli-only-production.js
+++ b/deps/npm/test/tap/install-cli-only-production.js
@@ -3,8 +3,6 @@ var path = require('path')
var existsSync = fs.existsSync || path.existsSync
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
@@ -59,7 +57,6 @@ test('setup', function (t) {
JSON.stringify(json, null, 2)
)
- process.chdir(pkg)
t.end()
})
@@ -82,9 +79,3 @@ test('\'npm install --only=production\' should only install dependencies', funct
t.end()
})
})
-
-test('cleanup', function (t) {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
- t.end()
-})
diff --git a/deps/npm/test/tap/install-cli-only-shrinkwrap.js b/deps/npm/test/tap/install-cli-only-shrinkwrap.js
index e3a4685d9c..004593d782 100644
--- a/deps/npm/test/tap/install-cli-only-shrinkwrap.js
+++ b/deps/npm/test/tap/install-cli-only-shrinkwrap.js
@@ -3,7 +3,6 @@ var path = require('path')
var existsSync = fs.existsSync || path.existsSync
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
var rimraf = require('rimraf')
var test = require('tap').test
@@ -55,9 +54,27 @@ var devDependency = {
}
test('setup', function (t) {
- cleanup()
- setup()
- t.pass('setup ran')
+ mkdirp.sync(path.join(pkg, 'dependency'))
+ fs.writeFileSync(
+ path.join(pkg, 'dependency', 'package.json'),
+ JSON.stringify(dependency, null, 2)
+ )
+
+ mkdirp.sync(path.join(pkg, 'dev-dependency'))
+ fs.writeFileSync(
+ path.join(pkg, 'dev-dependency', 'package.json'),
+ JSON.stringify(devDependency, null, 2)
+ )
+
+ mkdirp.sync(path.join(pkg, 'node_modules'))
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ fs.writeFileSync(
+ path.join(pkg, 'npm-shrinkwrap.json'),
+ JSON.stringify(shrinkwrap, null, 2)
+ )
t.end()
})
@@ -77,13 +94,11 @@ test('\'npm install --only=development\' should only install devDependencies', f
existsSync(path.resolve(pkg, 'node_modules/dependency/package.json')),
'dependency was NOT installed'
)
- t.end()
+ rimraf(path.join(pkg, 'node_modules'), t.end)
})
})
test('\'npm install --only=production\' should only install dependencies', function (t) {
- cleanup()
- setup()
common.npm(['install', '--only=production'], EXEC_OPTS, function (err, code, stdout, stderr) {
if (err) throw err
t.comment(stdout.trim())
@@ -99,42 +114,6 @@ test('\'npm install --only=production\' should only install dependencies', funct
existsSync(path.resolve(pkg, 'node_modules/dev-dependency/package.json')),
'devDependency was NOT installed'
)
- t.end()
+ rimraf(path.join(pkg, 'node_modules'), t.end)
})
})
-
-test('cleanup', function (t) {
- cleanup()
- t.pass('cleaned up')
- t.end()
-})
-
-function setup () {
- mkdirp.sync(path.join(pkg, 'dependency'))
- fs.writeFileSync(
- path.join(pkg, 'dependency', 'package.json'),
- JSON.stringify(dependency, null, 2)
- )
-
- mkdirp.sync(path.join(pkg, 'dev-dependency'))
- fs.writeFileSync(
- path.join(pkg, 'dev-dependency', 'package.json'),
- JSON.stringify(devDependency, null, 2)
- )
-
- mkdirp.sync(path.join(pkg, 'node_modules'))
- fs.writeFileSync(
- path.join(pkg, 'package.json'),
- JSON.stringify(json, null, 2)
- )
- fs.writeFileSync(
- path.join(pkg, 'npm-shrinkwrap.json'),
- JSON.stringify(shrinkwrap, null, 2)
- )
- process.chdir(pkg)
-}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/install-cli-production-nosave.js b/deps/npm/test/tap/install-cli-production-nosave.js
index 46b3460b72..23f5494996 100644
--- a/deps/npm/test/tap/install-cli-production-nosave.js
+++ b/deps/npm/test/tap/install-cli-production-nosave.js
@@ -3,12 +3,9 @@ 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 t = require('tap')
var common = require('../common-tap.js')
-var server
var pkg = common.pkg
@@ -21,16 +18,20 @@ var PACKAGE_JSON1 = {
}
}
-test('setup', function (t) {
- setup()
+t.test('setup', function (t) {
+ mkdirp.sync(path.resolve(pkg, 'node_modules'))
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(PACKAGE_JSON1, null, 2)
+ )
mr({ port: common.port }, function (er, s) {
t.ifError(er, 'started mock registry')
- server = s
+ t.parent.teardown(() => s.close())
t.end()
})
})
-test('install --production <module> without --save exits successfully', function (t) {
+t.test('install --production <module> without --save exits successfully', function (t) {
common.npm(
[
'--registry', common.registry,
@@ -45,25 +46,3 @@ test('install --production <module> without --save exits successfully', function
}
)
})
-
-test('cleanup', function (t) {
- server.close()
- cleanup()
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
-
-function setup () {
- cleanup()
- mkdirp.sync(path.resolve(pkg, 'node_modules'))
- fs.writeFileSync(
- path.join(pkg, 'package.json'),
- JSON.stringify(PACKAGE_JSON1, null, 2)
- )
-
- process.chdir(pkg)
-}
diff --git a/deps/npm/test/tap/install-cli-production.js b/deps/npm/test/tap/install-cli-production.js
index 4c88add92f..d083b42957 100644
--- a/deps/npm/test/tap/install-cli-production.js
+++ b/deps/npm/test/tap/install-cli-production.js
@@ -3,8 +3,6 @@ var path = require('path')
var existsSync = fs.existsSync || path.existsSync
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
@@ -59,7 +57,6 @@ test('setup', function (t) {
JSON.stringify(json, null, 2)
)
- process.chdir(pkg)
t.end()
})
@@ -80,9 +77,3 @@ test('\'npm install --production\' should only install dependencies', function (
t.end()
})
})
-
-test('cleanup', function (t) {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
- t.end()
-})
diff --git a/deps/npm/test/tap/install-cli-unicode.js b/deps/npm/test/tap/install-cli-unicode.js
index 2691db96d0..930066db5f 100644
--- a/deps/npm/test/tap/install-cli-unicode.js
+++ b/deps/npm/test/tap/install-cli-unicode.js
@@ -1,14 +1,10 @@
var fs = require('graceful-fs')
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')
-var server
var pkg = common.pkg
@@ -28,15 +24,13 @@ var json = {
}
test('setup', function (t) {
- rimraf.sync(pkg)
- mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
JSON.stringify(json, null, 2)
)
mr({ port: common.port }, function (er, s) {
- server = s
+ t.parent.teardown(() => s.close())
t.end()
})
})
@@ -61,11 +55,3 @@ test('does not use unicode with --unicode false', function (t) {
}
)
})
-
-test('cleanup', function (t) {
- server.close()
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-
- t.end()
-})
diff --git a/deps/npm/test/tap/install-duplicate-deps-warning.js b/deps/npm/test/tap/install-duplicate-deps-warning.js
index 05eccd8e43..869476ccd1 100644
--- a/deps/npm/test/tap/install-duplicate-deps-warning.js
+++ b/deps/npm/test/tap/install-duplicate-deps-warning.js
@@ -1,10 +1,7 @@
var fs = require('graceful-fs')
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')
@@ -21,21 +18,16 @@ var json = {
}
}
-test('setup', function (t) {
+test('npm install with duplicate dependencies, different versions', function (t) {
+ t.plan(1)
t.comment('test for https://github.com/npm/npm/issues/6725')
- cleanup()
- mkdirp.sync(pkg)
+
fs.writeFileSync(
path.join(pkg, 'package.json'),
JSON.stringify(json, null, 2)
)
process.chdir(pkg)
- console.dir(pkg)
- t.end()
-})
-test('npm install with duplicate dependencies, different versions', function (t) {
- t.plan(1)
mr({ port: common.port }, function (er, s) {
var opts = {
cache: common.cache,
@@ -57,13 +49,3 @@ test('npm install with duplicate dependencies, different versions', function (t)
})
})
})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/install-from-local-multipath.js b/deps/npm/test/tap/install-from-local-multipath.js
index 83dbdadde9..e35794dca9 100644
--- a/deps/npm/test/tap/install-from-local-multipath.js
+++ b/deps/npm/test/tap/install-from-local-multipath.js
@@ -2,8 +2,6 @@ var fs = require('graceful-fs')
var path = require('path')
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap')
@@ -115,7 +113,6 @@ var child2Lock = {
}
test('setup', function (t) {
- rimraf.sync(pkg)
mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
@@ -174,9 +171,3 @@ test('\'npm install\' should install local packages', function (t) {
}
)
})
-
-test('cleanup', function (t) {
- process.chdir(osenv.tmpdir())
- rimraf.sync(root)
- t.end()
-})
diff --git a/deps/npm/test/tap/install-from-local.js b/deps/npm/test/tap/install-from-local.js
index a3e63b359d..1ab94243ff 100644
--- a/deps/npm/test/tap/install-from-local.js
+++ b/deps/npm/test/tap/install-from-local.js
@@ -2,8 +2,6 @@ var fs = require('graceful-fs')
var path = require('path')
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap')
@@ -37,7 +35,6 @@ var localDevDependency = {
}
test('setup', function (t) {
- rimraf.sync(pkg)
mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
@@ -90,9 +87,3 @@ test('\'npm install\' should install local packages', function (t) {
}
)
})
-
-test('cleanup', function (t) {
- process.chdir(osenv.tmpdir())
- rimraf.sync(root)
- t.end()
-})
diff --git a/deps/npm/test/tap/install-link-scripts.js b/deps/npm/test/tap/install-link-scripts.js
index 3553e63773..52e50c6e9f 100644
--- a/deps/npm/test/tap/install-link-scripts.js
+++ b/deps/npm/test/tap/install-link-scripts.js
@@ -1,16 +1,12 @@
-if (process.platform === 'win32') {
- require('tap').plan(0, 'links are weird on windows, skip this')
- process.exit(0)
-}
var fs = require('graceful-fs')
var path = require('path')
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
var rimraf = require('rimraf')
-var test = require('tap').test
+const t = require('tap')
var common = require('../common-tap.js')
+common.skipIfWindows('links are weird on windows')
var pkg = common.pkg
var tmp = path.join(pkg, 'tmp')
@@ -40,9 +36,29 @@ console.log('hey sup')
process.env.npm_config_prefix = tmp
-test('plain install', function (t) {
- setup()
+t.beforeEach(cb => {
+ rimraf(pkg, er => {
+ if (er) {
+ return cb(er)
+ }
+ mkdirp.sync(tmp)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+
+ mkdirp.sync(path.join(dep, 'bin'))
+ fs.writeFileSync(
+ path.join(dep, 'package.json'),
+ JSON.stringify(dependency, null, 2)
+ )
+ fs.writeFileSync(path.join(dep, 'bin', 'foo'), foo)
+ fs.chmod(path.join(dep, 'bin', 'foo'), '0755')
+ cb()
+ })
+})
+t.test('plain install', function (t) {
common.npm(
[
'install', dep,
@@ -59,9 +75,7 @@ test('plain install', function (t) {
)
})
-test('link', function (t) {
- setup()
-
+t.test('link', function (t) {
common.npm(
[
'link',
@@ -78,9 +92,7 @@ test('link', function (t) {
)
})
-test('install --link', function (t) {
- setup()
-
+t.test('install --link', function (t) {
common.npm(
[
'link',
@@ -107,30 +119,3 @@ test('install --link', function (t) {
}
)
})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function setup () {
- cleanup()
- mkdirp.sync(tmp)
- fs.writeFileSync(
- path.join(pkg, 'package.json'),
- JSON.stringify(json, null, 2)
- )
-
- mkdirp.sync(path.join(dep, 'bin'))
- fs.writeFileSync(
- path.join(dep, 'package.json'),
- JSON.stringify(dependency, null, 2)
- )
- fs.writeFileSync(path.join(dep, 'bin', 'foo'), foo)
- fs.chmod(path.join(dep, 'bin', 'foo'), '0755')
-}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/install-man.js b/deps/npm/test/tap/install-man.js
index 720b4c217b..8c4b890151 100644
--- a/deps/npm/test/tap/install-man.js
+++ b/deps/npm/test/tap/install-man.js
@@ -1,15 +1,13 @@
var fs = require('fs')
var resolve = require('path').resolve
-var osenv = require('osenv')
var mkdirp = require('mkdirp')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
-var pkg = common.pkg
-var target = pkg + '-target'
+var pkg = resolve(common.pkg, 'package')
+var target = resolve(common.pkg, 'target')
common.pendIfWindows('man pages do not get installed on Windows')
@@ -24,8 +22,14 @@ var json = {
}
test('setup', function (t) {
- setup()
- t.pass('setup ran')
+ mkdirp.sync(pkg)
+ // make sure it installs locally
+ mkdirp.sync(resolve(target, 'node_modules'))
+ fs.writeFileSync(
+ resolve(pkg, 'package.json'),
+ JSON.stringify(json, null, 2) + '\n'
+ )
+ fs.writeFileSync(resolve(pkg, 'install-man.1'), 'THIS IS A MANPAGE\n')
t.end()
})
@@ -51,27 +55,3 @@ test('install man page', function (t) {
}
)
})
-
-test('clean', function (t) {
- cleanup()
- t.pass('cleaned up')
- t.end()
-})
-
-function setup () {
- cleanup()
- mkdirp.sync(pkg)
- // make sure it installs locally
- mkdirp.sync(resolve(target, 'node_modules'))
- fs.writeFileSync(
- resolve(pkg, 'package.json'),
- JSON.stringify(json, null, 2) + '\n'
- )
- fs.writeFileSync(resolve(pkg, 'install-man.1'), 'THIS IS A MANPAGE\n')
-}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
- rimraf.sync(target)
-}
diff --git a/deps/npm/test/tap/install-mention-funding.js b/deps/npm/test/tap/install-mention-funding.js
new file mode 100644
index 0000000000..ebd25a5732
--- /dev/null
+++ b/deps/npm/test/tap/install-mention-funding.js
@@ -0,0 +1,127 @@
+'use strict'
+const path = require('path')
+const test = require('tap').test
+const Tacks = require('tacks')
+const Dir = Tacks.Dir
+const File = Tacks.File
+const common = require('../common-tap.js')
+
+const base = common.pkg
+const singlePackage = path.join(base, 'single-funding-package')
+const multiplePackages = path.join(base, 'top-level-funding')
+
+function getFixturePackage ({ name, version, dependencies, funding }) {
+ return Dir({
+ 'package.json': File({
+ name,
+ version: version || '1.0.0',
+ funding: funding || {
+ type: 'individual',
+ url: 'http://example.com/donate'
+ },
+ dependencies: dependencies || {}
+ })
+ })
+}
+
+const fixture = new Tacks(Dir({
+ 'package.json': File({}),
+ 'single-funding-package': getFixturePackage({
+ name: 'single-funding-package'
+ }),
+ 'top-level-funding': getFixturePackage({
+ name: 'top-level-funding',
+ dependencies: {
+ 'dep-foo': 'file:../dep-foo',
+ 'dep-bar': 'file:../dep-bar'
+ }
+ }),
+ 'dep-foo': getFixturePackage({
+ name: 'dep-foo',
+ funding: {
+ type: 'corporate',
+ url: 'https://corp.example.com/sponsor'
+ },
+ dependencies: {
+ 'sub-dep-bar': 'file:../sub-dep-bar'
+ }
+ }),
+ 'dep-bar': getFixturePackage({
+ name: 'dep-bar',
+ version: '2.1.0',
+ dependencies: {
+ 'sub-dep-bar': 'file:../sub-dep-bar'
+ }
+ }),
+ 'sub-dep-bar': getFixturePackage({
+ name: 'sub-dep-bar',
+ funding: {
+ type: 'foo',
+ url: 'http://example.com/foo'
+ }
+ })
+}))
+
+test('mention npm fund upon installing single dependency', function (t) {
+ setup(t)
+ common.npm(['install', '--no-save', singlePackage], {cwd: base}, function (err, code, stdout, stderr) {
+ if (err) throw err
+ t.is(code, 0, 'installed successfully')
+ t.is(stderr, '', 'no warnings')
+ t.includes(stdout, '1 package is looking for funding.', 'should print amount of packages needing funding')
+ t.includes(stdout, 'Run "npm fund" to find out more.', 'should print npm fund mention')
+ t.end()
+ })
+})
+
+test('mention npm fund upon installing multiple dependencies', function (t) {
+ setup(t)
+ common.npm(['install', '--no-save', multiplePackages], {cwd: base}, function (err, code, stdout, stderr) {
+ if (err) throw err
+ t.is(code, 0, 'installed successfully')
+ t.is(stderr, '', 'no warnings')
+ t.includes(stdout, '4 packages are looking for funding.', 'should print amount of packages needing funding')
+ t.includes(stdout, 'Run "npm fund" to find out more.', 'should print npm fund mention')
+ t.end()
+ })
+})
+
+test('skips mention npm fund using --no-fund option', function (t) {
+ setup(t)
+ common.npm(['install', '--no-save', '--no-fund', multiplePackages], {cwd: base}, function (err, code, stdout, stderr) {
+ if (err) throw err
+ t.is(code, 0, 'installed successfully')
+ t.is(stderr, '', 'no warnings')
+ t.doesNotHave(stdout, '4 packages are looking for funding.', 'should print amount of packages needing funding')
+ t.doesNotHave(stdout, 'Run "npm fund" to find out more.', 'should print npm fund mention')
+ t.end()
+ })
+})
+
+test('mention packages looking for funding using --json', function (t) {
+ setup(t)
+ common.npm(['install', '--no-save', '--json', multiplePackages], {cwd: base}, function (err, code, stdout, stderr) {
+ if (err) throw err
+ t.is(code, 0, 'installed successfully')
+ t.is(stderr, '', 'no warnings')
+ const res = JSON.parse(stdout)
+ t.match(res.funding, '4 packages are looking for funding.', 'should print amount of packages needing funding')
+ t.end()
+ })
+})
+
+test('cleanup', function (t) {
+ cleanup()
+ t.end()
+})
+
+function setup (t) {
+ fixture.create(base)
+ t.teardown(() => {
+ cleanup()
+ })
+}
+
+function cleanup () {
+ fixture.remove(base)
+}
diff --git a/deps/npm/test/tap/install-noargs-dev.js b/deps/npm/test/tap/install-noargs-dev.js
index 4716dc2243..53422b9b5b 100644
--- a/deps/npm/test/tap/install-noargs-dev.js
+++ b/deps/npm/test/tap/install-noargs-dev.js
@@ -3,12 +3,9 @@ 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')
-var server
var pkg = common.pkg
@@ -31,10 +28,14 @@ var PACKAGE_JSON2 = {
}
test('setup', function (t) {
- setup()
+ mkdirp.sync(path.resolve(pkg, 'node_modules'))
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(PACKAGE_JSON1, null, 2)
+ )
mr({ port: common.port }, function (er, s) {
t.ifError(er, 'started mock registry')
- server = s
+ t.parent.teardown(() => s.close())
t.end()
})
})
@@ -87,25 +88,3 @@ test('install noargs installs updated devDependencies', function (t) {
}
)
})
-
-test('cleanup', function (t) {
- server.close()
- cleanup()
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
-
-function setup () {
- cleanup()
- mkdirp.sync(path.resolve(pkg, 'node_modules'))
- fs.writeFileSync(
- path.join(pkg, 'package.json'),
- JSON.stringify(PACKAGE_JSON1, null, 2)
- )
-
- process.chdir(pkg)
-}
diff --git a/deps/npm/test/tap/install-package-json-order.js b/deps/npm/test/tap/install-package-json-order.js
index 2e780def26..45ce882620 100644
--- a/deps/npm/test/tap/install-package-json-order.js
+++ b/deps/npm/test/tap/install-package-json-order.js
@@ -1,6 +1,5 @@
var test = require('tap').test
var path = require('path')
-var rimraf = require('rimraf')
var mkdirp = require('mkdirp')
var spawn = require('child_process').spawn
var npm = require.resolve('../../bin/npm-cli.js')
@@ -9,20 +8,26 @@ const common = require('../common-tap.js')
var pkg = common.pkg
var workdir = path.join(pkg, 'workdir')
var tmp = path.join(pkg, 'tmp')
-var cache = common.cache
var fs = require('fs')
-var osenv = require('osenv')
test('package.json sorting after install', function (t) {
var packageJson = path.resolve(pkg, 'package.json')
var installedPackage = path.resolve(workdir,
'node_modules/install-package-json-order/package.json')
- cleanup()
- mkdirp.sync(cache)
mkdirp.sync(tmp)
mkdirp.sync(workdir)
- setup()
+
+ fs.writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify({
+ 'name': 'install-package-json-order',
+ 'version': '0.0.0',
+ 'array': [ 'one', 'two', 'three' ]
+ }, null, 2), 'utf8')
+
+ fs.writeFileSync(path.resolve(workdir, 'package.json'), JSON.stringify({
+ 'name': 'install-package-json-order-work',
+ 'version': '0.0.0'
+ }, null, 2), 'utf8')
var before = JSON.parse(fs.readFileSync(packageJson).toString())
var child = spawn(node, [npm, 'install', pkg], { cwd: workdir })
@@ -35,29 +40,3 @@ test('package.json sorting after install', function (t) {
t.end()
})
})
-
-test('cleanup', function (t) {
- cleanup()
- t.pass('cleaned up')
- t.end()
-})
-
-function setup () {
- mkdirp.sync(pkg)
-
- fs.writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify({
- 'name': 'install-package-json-order',
- 'version': '0.0.0',
- 'array': [ 'one', 'two', 'three' ]
- }, null, 2), 'utf8')
- fs.writeFileSync(path.resolve(workdir, 'package.json'), JSON.stringify({
- 'name': 'install-package-json-order-work',
- 'version': '0.0.0'
- }, null, 2), 'utf8')
-}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(cache)
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/install-property-conflicts.js b/deps/npm/test/tap/install-property-conflicts.js
index c8f58e139f..a98f8570c6 100644
--- a/deps/npm/test/tap/install-property-conflicts.js
+++ b/deps/npm/test/tap/install-property-conflicts.js
@@ -1,9 +1,7 @@
var fs = require('fs')
var resolve = require('path').resolve
-var osenv = require('osenv')
var mkdirp = require('mkdirp')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
@@ -22,8 +20,12 @@ var json = {
}
test('setup', function (t) {
- setup()
- t.pass('setup ran')
+ // make sure it installs locally
+ mkdirp.sync(resolve(target, 'node_modules'))
+ fs.writeFileSync(
+ resolve(pkg, 'package.json'),
+ JSON.stringify(json, null, 2) + '\n'
+ )
t.end()
})
@@ -49,26 +51,3 @@ test('install package with a `type` property', function (t) {
}
)
})
-
-test('clean', function (t) {
- cleanup()
- t.pass('cleaned up')
- t.end()
-})
-
-function setup () {
- cleanup()
- mkdirp.sync(pkg)
- // make sure it installs locally
- mkdirp.sync(resolve(target, 'node_modules'))
- fs.writeFileSync(
- resolve(pkg, 'package.json'),
- JSON.stringify(json, null, 2) + '\n'
- )
-}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
- rimraf.sync(target)
-}
diff --git a/deps/npm/test/tap/install-save-consistent-newlines.js b/deps/npm/test/tap/install-save-consistent-newlines.js
index acea57c987..dfe41c649d 100644
--- a/deps/npm/test/tap/install-save-consistent-newlines.js
+++ b/deps/npm/test/tap/install-save-consistent-newlines.js
@@ -5,7 +5,6 @@ const path = require('path')
const mkdirp = require('mkdirp')
const mr = require('npm-registry-mock')
-const osenv = require('osenv')
const rimraf = require('rimraf')
const test = require('tap').test
@@ -21,102 +20,79 @@ const json = {
description: 'fixture'
}
-var server
-
-test('setup', function (t) {
- setup('\n')
+test('mock registry', function (t) {
mr({ port: common.port }, function (er, s) {
- server = s
+ t.parent.teardown(() => s.close())
t.end()
})
})
-test('\'npm install --save\' should keep the original package.json line endings (LF)', function (t) {
- common.npm(
- [
- '--loglevel', 'silent',
- '--registry', common.registry,
- '--save',
- 'install', 'underscore@1.3.1'
- ],
- EXEC_OPTS,
- function (err, code) {
- t.ifError(err, 'npm ran without issue')
- t.notOk(code, 'npm install exited without raising an error code')
-
- const pkgPath = path.resolve(pkg, 'package.json')
- const pkgStr = fs.readFileSync(pkgPath, 'utf8')
-
- t.match(pkgStr, '\n')
- t.notMatch(pkgStr, '\r')
+const runTest = (t, opts) => {
+ t.test('setup', setup(opts.ending))
+ t.test('check', check(opts))
+ t.end()
+}
- const pkgLockPath = path.resolve(pkg, 'package-lock.json')
- const pkgLockStr = fs.readFileSync(pkgLockPath, 'utf8')
+const setup = lineEnding => t => {
+ rimraf(pkg, er => {
+ if (er) {
+ throw er
+ }
+ mkdirp.sync(path.resolve(pkg, 'node_modules'))
- t.match(pkgLockStr, '\n')
- t.notMatch(pkgLockStr, '\r')
+ var jsonStr = JSON.stringify(json, null, 2)
- t.end()
+ if (lineEnding === '\r\n') {
+ jsonStr = jsonStr.replace(/\n/g, '\r\n')
}
- )
-})
-test('\'npm install --save\' should keep the original package.json line endings (CRLF)', function (t) {
- setup('\r\n')
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ jsonStr
+ )
- common.npm(
- [
- '--loglevel', 'silent',
- '--registry', common.registry,
- '--save',
- 'install', 'underscore@1.3.1'
- ],
- EXEC_OPTS,
- function (err, code) {
- t.ifError(err, 'npm ran without issue')
- t.notOk(code, 'npm install exited without raising an error code')
+ t.end()
+ })
+}
- const pkgPath = path.resolve(pkg, 'package.json')
- const pkgStr = fs.readFileSync(pkgPath, 'utf8')
+const check = opts => t => common.npm(
+ [
+ '--loglevel', 'silent',
+ '--registry', common.registry,
+ '--save',
+ 'install', 'underscore@1.3.1'
+ ],
+ EXEC_OPTS
+).then(([code, err, out]) => {
+ t.notOk(code, 'npm install exited without raising an error code')
- t.match(pkgStr, '\r\n')
- t.notMatch(pkgStr, /[^\r]\n/)
+ const pkgPath = path.resolve(pkg, 'package.json')
+ const pkgStr = fs.readFileSync(pkgPath, 'utf8')
- const pkgLockPath = path.resolve(pkg, 'package-lock.json')
- const pkgLockStr = fs.readFileSync(pkgLockPath, 'utf8')
+ t.match(pkgStr, opts.match)
+ t.notMatch(pkgStr, opts.notMatch)
- t.match(pkgLockStr, '\r\n')
- t.notMatch(pkgLockStr, /[^\r]\n/)
+ const pkgLockPath = path.resolve(pkg, 'package-lock.json')
+ const pkgLockStr = fs.readFileSync(pkgLockPath, 'utf8')
- t.end()
- }
- )
-})
+ t.match(pkgLockStr, opts.match)
+ t.notMatch(pkgLockStr, opts.notMatch)
-test('cleanup', function (t) {
- server.close()
- cleanup()
t.end()
})
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
-
-function setup (lineEnding) {
- cleanup()
- mkdirp.sync(path.resolve(pkg, 'node_modules'))
-
- var jsonStr = JSON.stringify(json, null, 2)
-
- if (lineEnding === '\r\n') {
- jsonStr = jsonStr.replace(/\n/g, '\r\n')
- }
+test('keep LF line endings', t => {
+ runTest(t, {
+ ending: '\n',
+ match: '\n',
+ notMatch: '\r'
+ })
+})
- fs.writeFileSync(
- path.join(pkg, 'package.json'),
- jsonStr
- )
- process.chdir(pkg)
-}
+test('keep CRLF line endings', t => {
+ runTest(t, {
+ ending: '\r\n',
+ match: '\r\n',
+ notMatch: /[^\r]\n/
+ })
+})
diff --git a/deps/npm/test/tap/install-save-exact.js b/deps/npm/test/tap/install-save-exact.js
index 3d57ead361..efa1e63613 100644
--- a/deps/npm/test/tap/install-save-exact.js
+++ b/deps/npm/test/tap/install-save-exact.js
@@ -3,12 +3,10 @@ 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')
-var server
var pkg = common.pkg
@@ -20,53 +18,32 @@ var json = {
description: 'fixture'
}
-test('setup', function (t) {
- setup()
+test('mock registry', function (t) {
mr({ port: common.port }, function (er, s) {
- server = s
+ t.parent.teardown(() => s.close())
t.end()
})
})
-test('\'npm install --save --save-exact\' should install local pkg', function (t) {
- common.npm(
- [
- '--loglevel', 'silent',
- '--registry', common.registry,
- '--save',
- '--save-exact',
- 'install', 'underscore@1.3.1'
- ],
- EXEC_OPTS,
- function (err, code) {
- t.ifError(err, 'npm ran without issue')
- t.notOk(code, 'npm install exited without raising an error code')
-
- var p = path.resolve(pkg, 'node_modules/underscore/package.json')
- t.ok(JSON.parse(fs.readFileSync(p)))
-
- p = path.resolve(pkg, 'package.json')
- var pkgJson = JSON.parse(fs.readFileSync(p, 'utf8'))
-
- t.same(
- pkgJson.dependencies,
- { 'underscore': '1.3.1' },
- 'underscore dependency should specify exactly 1.3.1'
- )
-
- t.end()
- }
- )
-})
-
-test('\'npm install --save-dev --save-exact\' should install local pkg', function (t) {
- setup()
+const setup = t => {
+ t.test('destroy', t => rimraf(pkg, t.end))
+ t.test('create', t => {
+ mkdirp.sync(path.resolve(pkg, 'node_modules'))
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ t.end()
+ })
+ t.end()
+}
+const check = (savearg, deptype) => t => {
common.npm(
[
'--loglevel', 'silent',
'--registry', common.registry,
- '--save-dev',
+ savearg,
'--save-exact',
'install', 'underscore@1.3.1'
],
@@ -82,7 +59,7 @@ test('\'npm install --save-dev --save-exact\' should install local pkg', functio
var pkgJson = JSON.parse(fs.readFileSync(p, 'utf8'))
t.same(
- pkgJson.devDependencies,
+ pkgJson[deptype],
{ 'underscore': '1.3.1' },
'underscore dependency should specify exactly 1.3.1'
)
@@ -90,25 +67,16 @@ test('\'npm install --save-dev --save-exact\' should install local pkg', functio
t.end()
}
)
-})
+}
-test('cleanup', function (t) {
- server.close()
- cleanup()
+test('\'npm install --save --save-exact\' should install local pkg', function (t) {
+ t.test('setup', setup)
+ t.test('check', check('--save', 'dependencies'))
t.end()
})
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
-
-function setup () {
- cleanup()
- mkdirp.sync(path.resolve(pkg, 'node_modules'))
- fs.writeFileSync(
- path.join(pkg, 'package.json'),
- JSON.stringify(json, null, 2)
- )
- process.chdir(pkg)
-}
+test('\'npm install --save-dev --save-exact\' should install local pkg', function (t) {
+ t.test('setup', setup)
+ t.test('check', check('--save-dev', 'devDependencies'))
+ t.end()
+})
diff --git a/deps/npm/test/tap/install-save-local.js b/deps/npm/test/tap/install-save-local.js
index 8f4f5ecb00..8b65979528 100644
--- a/deps/npm/test/tap/install-save-local.js
+++ b/deps/npm/test/tap/install-save-local.js
@@ -2,7 +2,6 @@ var fs = require('graceful-fs')
var path = require('path')
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
var rimraf = require('rimraf')
var test = require('tap').test
@@ -28,168 +27,155 @@ var localDevDependency = {
version: '0.0.0'
}
-test('setup', function (t) {
- setup()
+test('setup deps in root', t => {
+ mkdirp.sync(path.join(root, 'package-local-dependency'))
+ fs.writeFileSync(
+ path.join(root, 'package-local-dependency', 'package.json'),
+ JSON.stringify(localDependency, null, 2)
+ )
+
+ mkdirp.sync(path.join(root, 'package-local-dev-dependency'))
+ fs.writeFileSync(
+ path.join(root, 'package-local-dev-dependency', 'package.json'),
+ JSON.stringify(localDevDependency, null, 2)
+ )
+
t.end()
})
test('\'npm install --save ../local/path\' should save to package.json', function (t) {
- common.npm(
+ t.plan(2)
+ t.test('setup', setup)
+ t.test('run test', t => common.npm(
[
'--loglevel', 'silent',
'--save',
'install', '../package-local-dependency'
],
- EXEC_OPTS,
- function (err, code) {
- t.ifError(err, 'npm install ran without issue')
- t.notOk(code, 'npm install exited with code 0')
-
- var dependencyPackageJson = path.join(
- pkg, 'node_modules', 'package-local-dependency', 'package.json'
- )
- t.ok(JSON.parse(fs.readFileSync(dependencyPackageJson, 'utf8')))
-
- var pkgJson = JSON.parse(fs.readFileSync(pkg + '/package.json', 'utf8'))
- t.is(Object.keys(pkgJson.dependencies).length, 1, 'only one dep')
- t.ok(
- /file:.*?[/]package-local-dependency$/.test(pkgJson.dependencies['package-local-dependency']),
- 'local package saved correctly'
- )
- t.end()
- }
- )
+ EXEC_OPTS
+ ).then(([code]) => {
+ t.equal(code, 0, 'npm install exited with code 0')
+
+ var dependencyPackageJson = path.join(
+ pkg, 'node_modules', 'package-local-dependency', 'package.json'
+ )
+ t.ok(JSON.parse(fs.readFileSync(dependencyPackageJson, 'utf8')))
+
+ var pkgJson = JSON.parse(fs.readFileSync(pkg + '/package.json', 'utf8'))
+ t.is(Object.keys(pkgJson.dependencies).length, 1, 'only one dep')
+ t.ok(
+ /file:.*?[/]package-local-dependency$/.test(pkgJson.dependencies['package-local-dependency']),
+ 'local package saved correctly'
+ )
+ }))
})
test('\'npm install --save local/path\' should save to package.json', function (t) {
- setup()
- common.npm(
+ t.plan(2)
+ t.test('setup', setup)
+ t.test('run test', t => common.npm(
[
'--loglevel', 'silent',
'--save',
'install', 'package-local-dependency/'
],
- EXEC_OPTS,
- function (err, code) {
- t.ifError(err, 'npm install ran without issue')
- t.notOk(code, 'npm install exited with code 0')
-
- var dependencyPackageJson = path.join(
- pkg, 'node_modules', 'package-local-dependency', 'package.json'
- )
- t.ok(JSON.parse(fs.readFileSync(dependencyPackageJson, 'utf8')))
-
- var pkgJson = JSON.parse(fs.readFileSync(pkg + '/package.json', 'utf8'))
- t.is(Object.keys(pkgJson.dependencies).length, 1, 'only one dep')
- t.ok(
- /file:package-local-dependency$/.test(pkgJson.dependencies['package-local-dependency']),
- 'local package saved correctly'
- )
- t.end()
- }
- )
+ EXEC_OPTS
+ ).then(([code, out, err]) => {
+ t.equal(code, 0, 'npm install exited with code 0')
+
+ var dependencyPackageJson = path.join(
+ pkg, 'node_modules', 'package-local-dependency', 'package.json'
+ )
+ t.ok(JSON.parse(fs.readFileSync(dependencyPackageJson, 'utf8')))
+
+ var pkgJson = JSON.parse(fs.readFileSync(pkg + '/package.json', 'utf8'))
+ t.is(Object.keys(pkgJson.dependencies).length, 1, 'only one dep')
+ t.ok(
+ /file:package-local-dependency$/.test(pkgJson.dependencies['package-local-dependency']),
+ 'local package saved correctly'
+ )
+ }))
})
test('\'npm install --save-dev ../local/path\' should save to package.json', function (t) {
- setup()
- common.npm(
+ t.plan(2)
+ t.test('setup', setup)
+ t.test('run test', t => common.npm(
[
'--loglevel', 'silent',
'--save-dev',
'install', '../package-local-dev-dependency'
],
- EXEC_OPTS,
- function (err, code) {
- t.ifError(err, 'npm install ran without issue')
- t.notOk(code, 'npm install exited with code 0')
-
- var dependencyPackageJson = path.resolve(
- pkg, 'node_modules', 'package-local-dev-dependency', 'package.json'
- )
- t.ok(JSON.parse(fs.readFileSync(dependencyPackageJson, 'utf8')))
-
- var pkgJson = JSON.parse(fs.readFileSync(pkg + '/package.json', 'utf8'))
- t.is(Object.keys(pkgJson.devDependencies).length, 1, 'only one dep')
- t.ok(
- /file:.*?[/\\]package-local-dev-dependency$/.test(pkgJson.devDependencies['package-local-dev-dependency']),
- 'local package saved correctly'
- )
-
- t.end()
- }
- )
+ EXEC_OPTS
+ ).then(([code]) => {
+ t.equal(code, 0, 'npm install exited with code 0')
+
+ var dependencyPackageJson = path.resolve(
+ pkg, 'node_modules', 'package-local-dev-dependency', 'package.json'
+ )
+ t.ok(JSON.parse(fs.readFileSync(dependencyPackageJson, 'utf8')))
+
+ var pkgJson = JSON.parse(fs.readFileSync(pkg + '/package.json', 'utf8'))
+ t.is(Object.keys(pkgJson.devDependencies).length, 1, 'only one dep')
+ t.ok(
+ /file:.*?[/\\]package-local-dev-dependency$/.test(pkgJson.devDependencies['package-local-dev-dependency']),
+ 'local package saved correctly'
+ )
+
+ t.end()
+ }))
})
+
test('\'npm install --save-dev local/path\' should save to package.json', function (t) {
- setup()
- common.npm(
+ t.plan(2)
+ t.test('setup', setup)
+ t.test('run test', t => common.npm(
[
'--loglevel', 'silent',
'--save-dev',
'install', 'package-local-dev-dependency/'
],
- EXEC_OPTS,
- function (err, code) {
- t.ifError(err, 'npm install ran without issue')
- t.notOk(code, 'npm install exited with code 0')
-
- var dependencyPackageJson = path.resolve(
- pkg, 'node_modules', 'package-local-dev-dependency', 'package.json'
- )
- t.ok(JSON.parse(fs.readFileSync(dependencyPackageJson, 'utf8')))
-
- var pkgJson = JSON.parse(fs.readFileSync(pkg + '/package.json', 'utf8'))
- t.is(Object.keys(pkgJson.devDependencies).length, 1, 'only one dep')
- t.ok(
- /file:package-local-dev-dependency$/.test(pkgJson.devDependencies['package-local-dev-dependency']),
- 'local package saved correctly'
- )
-
- t.end()
- }
- )
+ EXEC_OPTS
+ ).then(([code]) => {
+ t.equal(code, 0, 'npm install exited with code 0')
+
+ var dependencyPackageJson = path.resolve(
+ pkg, 'node_modules', 'package-local-dev-dependency', 'package.json'
+ )
+ t.ok(JSON.parse(fs.readFileSync(dependencyPackageJson, 'utf8')))
+
+ var pkgJson = JSON.parse(fs.readFileSync(pkg + '/package.json', 'utf8'))
+ t.is(Object.keys(pkgJson.devDependencies).length, 1, 'only one dep')
+ t.ok(
+ /file:package-local-dev-dependency$/.test(pkgJson.devDependencies['package-local-dev-dependency']),
+ 'local package saved correctly'
+ )
+
+ t.end()
+ }))
})
-test('cleanup', function (t) {
- cleanup()
+function setup (t) {
+ t.test('destroy', t => rimraf(pkg, t.end))
+ t.test('create', t => {
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+
+ mkdirp.sync(path.join(pkg, 'package-local-dependency'))
+ fs.writeFileSync(
+ path.join(pkg, 'package-local-dependency', 'package.json'),
+ JSON.stringify(localDependency, null, 2)
+ )
+
+ mkdirp.sync(path.join(pkg, 'package-local-dev-dependency'))
+ fs.writeFileSync(
+ path.join(pkg, 'package-local-dev-dependency', 'package.json'),
+ JSON.stringify(localDevDependency, null, 2)
+ )
+ t.end()
+ })
t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- process.chdir(__dirname)
- rimraf.sync(root)
-}
-
-function setup () {
- cleanup()
- mkdirp.sync(pkg)
- fs.writeFileSync(
- path.join(pkg, 'package.json'),
- JSON.stringify(json, null, 2)
- )
-
- mkdirp.sync(path.join(root, 'package-local-dependency'))
- fs.writeFileSync(
- path.join(root, 'package-local-dependency', 'package.json'),
- JSON.stringify(localDependency, null, 2)
- )
-
- mkdirp.sync(path.join(root, 'package-local-dev-dependency'))
- fs.writeFileSync(
- path.join(root, 'package-local-dev-dependency', 'package.json'),
- JSON.stringify(localDevDependency, null, 2)
- )
-
- mkdirp.sync(path.join(pkg, 'package-local-dependency'))
- fs.writeFileSync(
- path.join(pkg, 'package-local-dependency', 'package.json'),
- JSON.stringify(localDependency, null, 2)
- )
-
- mkdirp.sync(path.join(pkg, 'package-local-dev-dependency'))
- fs.writeFileSync(
- path.join(pkg, 'package-local-dev-dependency', 'package.json'),
- JSON.stringify(localDevDependency, null, 2)
- )
- process.chdir(pkg)
}
diff --git a/deps/npm/test/tap/install-save-prefix.js b/deps/npm/test/tap/install-save-prefix.js
index 001e24d873..d61608e1cf 100644
--- a/deps/npm/test/tap/install-save-prefix.js
+++ b/deps/npm/test/tap/install-save-prefix.js
@@ -1,14 +1,11 @@
var fs = require('fs')
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')
-var server
var pkg = common.pkg
@@ -19,17 +16,18 @@ var json = {
version: '0.0.1'
}
-test('setup', function (t) {
- setup()
+test('start mock reg', function (t) {
mr({ port: common.port }, function (er, s) {
t.ifError(er, 'started mock registry')
- server = s
+ t.parent.teardown(() => s.close())
t.end()
})
})
test('install --save with \'^\' save prefix should accept minor updates', function (t) {
- common.npm(
+ t.plan(2)
+ t.test('setup', setup)
+ t.test('run test', t => common.npm(
[
'--registry', common.registry,
'--loglevel', 'silent',
@@ -37,31 +35,30 @@ test('install --save with \'^\' save prefix should accept minor updates', functi
'--save',
'install', 'underscore@latest'
],
- EXEC_OPTS,
- function (err, code) {
- t.ifError(err, 'npm install ran without issue')
- t.notOk(code, 'npm install exited with code 0')
-
- var p = path.join(pkg, 'node_modules', 'underscore', 'package.json')
- t.ok(JSON.parse(fs.readFileSync(p)))
-
- var pkgJson = JSON.parse(fs.readFileSync(
- path.join(pkg, 'package.json'),
- 'utf8'
- ))
- t.deepEqual(
- pkgJson.dependencies,
- { 'underscore': '^1.5.1' },
- 'got expected save prefix and version of 1.5.1'
- )
- t.end()
- }
- )
+ EXEC_OPTS
+ ).then(([code]) => {
+ console.error('back from install!', code)
+ t.equal(code, 0, 'npm install exited with code 0')
+
+ var p = path.join(pkg, 'node_modules', 'underscore', 'package.json')
+ t.ok(JSON.parse(fs.readFileSync(p)))
+
+ var pkgJson = JSON.parse(fs.readFileSync(
+ path.join(pkg, 'package.json'),
+ 'utf8'
+ ))
+ t.deepEqual(
+ pkgJson.dependencies,
+ { 'underscore': '^1.5.1' },
+ 'got expected save prefix and version of 1.5.1'
+ )
+ }))
})
test('install --save-dev with \'^\' save prefix should accept minor dev updates', function (t) {
- setup()
- common.npm(
+ t.plan(2)
+ t.test('setup', setup)
+ t.test('run test', t => common.npm(
[
'--registry', common.registry,
'--loglevel', 'silent',
@@ -69,31 +66,30 @@ test('install --save-dev with \'^\' save prefix should accept minor dev updates'
'--save-dev',
'install', 'underscore@1.3.1'
],
- EXEC_OPTS,
- function (err, code) {
- t.ifError(err, 'npm install ran without issue')
- t.notOk(code, 'npm install exited with code 0')
-
- var p = path.join(pkg, 'node_modules', 'underscore', 'package.json')
- t.ok(JSON.parse(fs.readFileSync(p)))
-
- var pkgJson = JSON.parse(fs.readFileSync(
- path.join(pkg, 'package.json'),
- 'utf8'
- ))
- t.deepEqual(
- pkgJson.devDependencies,
- { 'underscore': '^1.3.1' },
- 'got expected save prefix and version of 1.3.1'
- )
- t.end()
- }
- )
+ EXEC_OPTS
+ ).then(([code]) => {
+ t.equal(code, 0, 'npm install exited with code 0')
+
+ var p = path.join(pkg, 'node_modules', 'underscore', 'package.json')
+ t.ok(JSON.parse(fs.readFileSync(p)))
+
+ var pkgJson = JSON.parse(fs.readFileSync(
+ path.join(pkg, 'package.json'),
+ 'utf8'
+ ))
+ t.deepEqual(
+ pkgJson.devDependencies,
+ { 'underscore': '^1.3.1' },
+ 'got expected save prefix and version of 1.3.1'
+ )
+ t.end()
+ }))
})
test('install --save with \'~\' save prefix should accept patch updates', function (t) {
- setup()
- common.npm(
+ t.plan(2)
+ t.test('setup', setup)
+ t.test('run test', t => common.npm(
[
'--registry', common.registry,
'--loglevel', 'silent',
@@ -101,31 +97,29 @@ test('install --save with \'~\' save prefix should accept patch updates', functi
'--save',
'install', 'underscore@1.3.1'
],
- EXEC_OPTS,
- function (err, code) {
- t.ifError(err, 'npm install ran without issue')
- t.notOk(code, 'npm install exited with code 0')
-
- var p = path.join(pkg, 'node_modules', 'underscore', 'package.json')
- t.ok(JSON.parse(fs.readFileSync(p)))
-
- var pkgJson = JSON.parse(fs.readFileSync(
- path.join(pkg, 'package.json'),
- 'utf8'
- ))
- t.deepEqual(
- pkgJson.dependencies,
- { 'underscore': '~1.3.1' },
- 'got expected save prefix and version of 1.3.1'
- )
- t.end()
- }
- )
+ EXEC_OPTS
+ ).then(([code]) => {
+ t.equal(code, 0, 'npm install exited with code 0')
+
+ var p = path.join(pkg, 'node_modules', 'underscore', 'package.json')
+ t.ok(JSON.parse(fs.readFileSync(p)))
+
+ var pkgJson = JSON.parse(fs.readFileSync(
+ path.join(pkg, 'package.json'),
+ 'utf8'
+ ))
+ t.deepEqual(
+ pkgJson.dependencies,
+ { 'underscore': '~1.3.1' },
+ 'got expected save prefix and version of 1.3.1'
+ )
+ }))
})
test('install --save-dev with \'~\' save prefix should accept patch updates', function (t) {
- setup()
- common.npm(
+ t.plan(2)
+ t.test('setup', setup)
+ t.test('run test', t => common.npm(
[
'--registry', common.registry,
'--loglevel', 'silent',
@@ -133,46 +127,38 @@ test('install --save-dev with \'~\' save prefix should accept patch updates', fu
'--save-dev',
'install', 'underscore@1.3.1'
],
- EXEC_OPTS,
- function (err, code) {
- t.ifError(err, 'npm install ran without issue')
- t.notOk(code, 'npm install exited with code 0')
-
- var p = path.join(pkg, 'node_modules', 'underscore', 'package.json')
- t.ok(JSON.parse(fs.readFileSync(p)))
-
- var pkgJson = JSON.parse(fs.readFileSync(
- path.join(pkg, 'package.json'),
- 'utf8'
- ))
- t.deepEqual(
- pkgJson.devDependencies,
- { 'underscore': '~1.3.1' },
- 'got expected save prefix and version of 1.3.1'
- )
- t.end()
- }
- )
+ EXEC_OPTS
+ ).then(([code]) => {
+ t.notOk(code, 'npm install exited with code 0')
+
+ var p = path.join(pkg, 'node_modules', 'underscore', 'package.json')
+ t.ok(JSON.parse(fs.readFileSync(p)))
+
+ var pkgJson = JSON.parse(fs.readFileSync(
+ path.join(pkg, 'package.json'),
+ 'utf8'
+ ))
+ t.deepEqual(
+ pkgJson.devDependencies,
+ { 'underscore': '~1.3.1' },
+ 'got expected save prefix and version of 1.3.1'
+ )
+ }))
})
-test('cleanup', function (t) {
- server.close()
- cleanup()
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
-
-function setup () {
- cleanup()
- mkdirp.sync(path.resolve(pkg, 'node_modules'))
- fs.writeFileSync(
- path.join(pkg, 'package.json'),
- JSON.stringify(json, null, 2)
- )
+function setup (t) {
+ t.test('destroy', t => {
+ t.plan(2)
+ rimraf(path.resolve(pkg, 'node_modules'), () => t.pass('node_modules'))
+ rimraf(path.resolve(pkg, 'pacakage-lock.json'), () => t.pass('lock file'))
+ })
+ t.test('create', t => {
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ t.end()
+ })
- process.chdir(pkg)
+ t.end()
}
diff --git a/deps/npm/test/tap/install-scoped-already-installed.js b/deps/npm/test/tap/install-scoped-already-installed.js
index 707d82a443..d4655f4a9a 100644
--- a/deps/npm/test/tap/install-scoped-already-installed.js
+++ b/deps/npm/test/tap/install-scoped-already-installed.js
@@ -3,8 +3,6 @@ var path = require('path')
var existsSync = fs.existsSync || path.existsSync
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap')
@@ -37,7 +35,6 @@ var scopedDependency = {
}
test('setup', function (t) {
- rimraf.sync(root)
mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
@@ -56,7 +53,6 @@ test('setup', function (t) {
JSON.stringify(scopedDependency, null, 2)
)
- process.chdir(pkg)
t.end()
})
@@ -118,12 +114,6 @@ test('installing already installed local scoped package', function (t) {
)
})
-test('cleanup', function (t) {
- process.chdir(osenv.tmpdir())
- rimraf.sync(root)
- t.end()
-})
-
function contains (list, element) {
var matcher = new RegExp(element.replace(/\//g, '[\\\\/]') + '$')
for (var i = 0; i < list.length; ++i) {
diff --git a/deps/npm/test/tap/install-scoped-link.js b/deps/npm/test/tap/install-scoped-link.js
index 920e7e3d45..a0c9c61a98 100644
--- a/deps/npm/test/tap/install-scoped-link.js
+++ b/deps/npm/test/tap/install-scoped-link.js
@@ -4,16 +4,15 @@ var path = require('path')
var existsSync = fs.existsSync || path.existsSync
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var test = require('tap').test
var escapeExecPath = require('../../lib/utils/escape-exec-path')
var common = require('../common-tap.js')
-var pkg = common.pkg
-var work = pkg + '-TEST'
+var resolve = require('path').resolve
+var pkg = resolve(common.pkg, 'package')
+var work = resolve(common.pkg, 'TEST')
var modules = path.join(work, 'node_modules')
var EXEC_OPTS = { cwd: work }
@@ -29,7 +28,6 @@ var json = {
}
test('setup', function (t) {
- cleanup()
mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
@@ -73,14 +71,3 @@ test('installing package with links', function (t) {
}
)
})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(work)
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/install-scoped-with-peer-dependency.js b/deps/npm/test/tap/install-scoped-with-peer-dependency.js
index 477a04a105..016f5f0453 100644
--- a/deps/npm/test/tap/install-scoped-with-peer-dependency.js
+++ b/deps/npm/test/tap/install-scoped-with-peer-dependency.js
@@ -2,15 +2,13 @@ var fs = require('fs')
var path = require('path')
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
var pkg = common.pkg
var local = path.join(pkg, 'package')
-var EXEC_OPTS = { }
+var EXEC_OPTS = { cwd: pkg }
var json = {
name: '@scope/package',
@@ -21,8 +19,12 @@ var json = {
}
test('setup', function (t) {
- setup()
-
+ mkdirp.sync(local)
+ mkdirp.sync(path.resolve(pkg, 'node_modules'))
+ fs.writeFileSync(
+ path.join(local, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
t.end()
})
@@ -36,24 +38,3 @@ test('it should install peerDependencies in same tree level as the parent packag
t.end()
})
})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function setup () {
- cleanup()
- mkdirp.sync(local)
- mkdirp.sync(path.resolve(pkg, 'node_modules'))
- fs.writeFileSync(
- path.join(local, 'package.json'),
- JSON.stringify(json, null, 2)
- )
- process.chdir(pkg)
-}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/install-shrinkwrapped-git.js b/deps/npm/test/tap/install-shrinkwrapped-git.js
index f74e185bfb..3cdc2b9129 100644
--- a/deps/npm/test/tap/install-shrinkwrapped-git.js
+++ b/deps/npm/test/tap/install-shrinkwrapped-git.js
@@ -3,7 +3,6 @@
var fs = require('fs')
var path = require('path')
var resolve = path.resolve
-var osenv = require('osenv')
var mkdirp = require('mkdirp')
var rimraf = require('rimraf')
var test = require('tap').test
@@ -32,16 +31,31 @@ var childPackageJSON = JSON.stringify({
})
test('setup', function (t) {
- cleanup()
- setup(function (err, result) {
- t.ifError(err, 'git started up successfully')
+ mkdirp.sync(parentPath)
+ fs.writeFileSync(resolve(parentPath, 'package.json'), parentPackageJSON)
+ process.chdir(parentPath)
- if (!err) {
- gitDaemon = result[result.length - 2]
- gitDaemonPID = result[result.length - 1]
- }
+ // Setup child
+ mkdirp.sync(childPath)
+ fs.writeFileSync(resolve(childPath, 'package.json'), childPackageJSON)
+
+ // Setup npm and then git
+ npm.load({
+ registry: common.registry,
+ loglevel: 'silent',
+ save: true // Always install packages with --save
+ }, function () {
+ // It's important to initialize git after npm because it uses config
+ initializeGit(function (err, result) {
+ t.ifError(err, 'git started up successfully')
- t.end()
+ if (!err) {
+ gitDaemon = result[result.length - 2]
+ gitDaemonPID = result[result.length - 1]
+ }
+
+ t.end()
+ })
})
})
@@ -85,39 +99,10 @@ test('shrinkwrapped git dependency got updated', function (t) {
})
test('clean', function (t) {
- gitDaemon.on('close', function () {
- cleanup()
- t.end()
- })
+ gitDaemon.on('close', t.end)
process.kill(gitDaemonPID)
})
-function setup (cb) {
- // Setup parent package
- mkdirp.sync(parentPath)
- fs.writeFileSync(resolve(parentPath, 'package.json'), parentPackageJSON)
- process.chdir(parentPath)
-
- // Setup child
- mkdirp.sync(childPath)
- fs.writeFileSync(resolve(childPath, 'package.json'), childPackageJSON)
-
- // Setup npm and then git
- npm.load({
- registry: common.registry,
- loglevel: 'silent',
- save: true // Always install packages with --save
- }, function () {
- // It's important to initialize git after npm because it uses config
- initializeGit(cb)
- })
-}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(mockPath)
-}
-
function prepareChildAndGetRefs (cb) {
var opts = { cwd: childPath, env: { PATH: process.env.PATH } }
chain([
diff --git a/deps/npm/test/tap/install-test-cli-without-package-lock.js b/deps/npm/test/tap/install-test-cli-without-package-lock.js
index 468277d74d..603043af8f 100644
--- a/deps/npm/test/tap/install-test-cli-without-package-lock.js
+++ b/deps/npm/test/tap/install-test-cli-without-package-lock.js
@@ -2,8 +2,6 @@ var fs = require('graceful-fs')
var path = require('path')
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
@@ -28,8 +26,23 @@ var dependency = {
}
test('setup', function (t) {
- setup()
- t.pass('setup ran')
+ mkdirp.sync(path.join(pkg, 'dependency'))
+ fs.writeFileSync(
+ path.join(pkg, 'dependency', 'package.json'),
+ JSON.stringify(dependency, null, 2)
+ )
+
+ mkdirp.sync(path.join(pkg, 'node_modules'))
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+
+ // Disable package-lock
+ fs.writeFileSync(
+ path.join(pkg, '.npmrc'),
+ 'package-lock=false\n'
+ )
t.end()
})
@@ -49,35 +62,3 @@ test('\'npm install-test\' should not generate package-lock.json.*', function (t
t.end()
})
})
-
-test('cleanup', function (t) {
- cleanup()
- t.pass('cleaned up')
- t.end()
-})
-
-function setup () {
- mkdirp.sync(path.join(pkg, 'dependency'))
- fs.writeFileSync(
- path.join(pkg, 'dependency', 'package.json'),
- JSON.stringify(dependency, null, 2)
- )
-
- mkdirp.sync(path.join(pkg, 'node_modules'))
- fs.writeFileSync(
- path.join(pkg, 'package.json'),
- JSON.stringify(json, null, 2)
- )
-
- // Disable package-lock
- fs.writeFileSync(
- path.join(pkg, '.npmrc'),
- 'package-lock=false\n'
- )
- process.chdir(pkg)
-}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/install-with-dev-dep-duplicate.js b/deps/npm/test/tap/install-with-dev-dep-duplicate.js
index 01ba38a112..7d8586f47d 100644
--- a/deps/npm/test/tap/install-with-dev-dep-duplicate.js
+++ b/deps/npm/test/tap/install-with-dev-dep-duplicate.js
@@ -1,10 +1,7 @@
var fs = require('graceful-fs')
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')
@@ -42,13 +39,19 @@ test('prefers version from dependencies over devDependencies', function (t) {
mr({ port: common.port }, function (er, s) {
setup(function (err) {
- if (err) return t.fail(err)
+ if (err) {
+ throw err
+ }
npm.install('.', function (err) {
- if (err) return t.fail(err)
+ if (err) {
+ throw err
+ }
npm.commands.ls([], true, function (err, _, results) {
- if (err) return t.fail(err)
+ if (err) {
+ throw err
+ }
// these contain full paths so we can't do an exact match
// with them
@@ -63,14 +66,7 @@ test('prefers version from dependencies over devDependencies', function (t) {
})
})
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
function setup (cb) {
- cleanup()
- mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
JSON.stringify(json, null, 2)
@@ -83,8 +79,3 @@ function setup (cb) {
}
npm.load(opts, cb)
}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/install.fund.js b/deps/npm/test/tap/install.fund.js
new file mode 100644
index 0000000000..37a61e4289
--- /dev/null
+++ b/deps/npm/test/tap/install.fund.js
@@ -0,0 +1,100 @@
+'use strict'
+
+const { EOL } = require('os')
+const { test } = require('tap')
+const { getPrintFundingReport } = require('../../lib/install/fund')
+
+test('message when there are no funding found', (t) => {
+ t.deepEqual(
+ getPrintFundingReport({}),
+ '',
+ 'should not print any message if missing info'
+ )
+ t.deepEqual(
+ getPrintFundingReport({
+ name: 'foo',
+ version: '1.0.0',
+ dependencies: {}
+ }),
+ '',
+ 'should not print any message if package has no dependencies'
+ )
+ t.deepEqual(
+ getPrintFundingReport({
+ fund: true,
+ idealTree: {
+ name: 'foo',
+ version: '1.0.0',
+ dependencies: {
+ bar: {},
+ lorem: {}
+ }
+ }
+ }),
+ '',
+ 'should not print any message if no package has funding info'
+ )
+ t.end()
+})
+
+test('print appropriate message for a single package', (t) => {
+ t.deepEqual(
+ getPrintFundingReport({
+ fund: true,
+ idealTree: {
+ name: 'foo',
+ version: '1.0.0',
+ children: [
+ {
+ package: {
+ name: 'bar',
+ version: '1.0.0',
+ funding: { type: 'foo', url: 'http://example.com' }
+ }
+ }
+ ]
+ }
+ }),
+ `${EOL}1 package is looking for funding.${EOL}Run "npm fund" to find out more.`,
+ 'should print single package message'
+ )
+ t.end()
+})
+
+test('print appropriate message for many packages', (t) => {
+ t.deepEqual(
+ getPrintFundingReport({
+ fund: true,
+ idealTree: {
+ name: 'foo',
+ version: '1.0.0',
+ children: [
+ {
+ package: {
+ name: 'bar',
+ version: '1.0.0',
+ funding: { type: 'foo', url: 'http://example.com' }
+ }
+ },
+ {
+ package: {
+ name: 'lorem',
+ version: '1.0.0',
+ funding: { type: 'foo', url: 'http://example.com' }
+ }
+ },
+ {
+ package: {
+ name: 'ipsum',
+ version: '1.0.0',
+ funding: { type: 'foo', url: 'http://example.com' }
+ }
+ }
+ ]
+ }
+ }),
+ `${EOL}3 packages are looking for funding.${EOL}Run "npm fund" to find out more.`,
+ 'should print many package message'
+ )
+ t.end()
+})
diff --git a/deps/npm/test/tap/it.js b/deps/npm/test/tap/it.js
index 9b716139a3..bb59bc6f5e 100644
--- a/deps/npm/test/tap/it.js
+++ b/deps/npm/test/tap/it.js
@@ -2,9 +2,7 @@ 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
@@ -23,55 +21,45 @@ var json = {
}
}
-var server
-
test('run up the mock registry', function (t) {
mr({ port: common.port }, function (err, s) {
if (err) throw err
- server = s
+ t.parent.teardown(() => s.close())
t.end()
})
})
+const check = args => t =>
+ common.npm(args.concat('--registry=' + common.registry), { cwd: pkg })
+ .then(([code, stdout, stderr]) => {
+ 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')
+ })
+
test('npm install-test', function (t) {
- setup()
- common.npm(['install-test', '--no-shrinkwrap', '--registry=' + common.registry], { 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()
- })
+ t.plan(2)
+ t.test('setup', setup)
+ t.test('check', check(['install-test', '--no-shrinkwrap']))
})
test('npm it (the form most people will use)', function (t) {
- setup()
- common.npm(['it', '--registry=' + common.registry], { 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()
- })
+ t.plan(2)
+ t.test('setup', setup)
+ t.test('check', check(['it']))
})
-test('cleanup', function (t) {
- process.chdir(osenv.tmpdir())
- server.close()
- cleanup()
+function setup (t) {
+ t.test('destroy', t => {
+ t.plan(2)
+ rimraf(join(pkg, 'node_modules'), () => t.pass('node_modules'))
+ rimraf(join(pkg, 'package-lock.json'), () => t.pass('lock file'))
+ })
+ t.test('create', t => {
+ writeFileSync(join(pkg, 'package.json'), JSON.stringify(json, null, 2))
+ t.end()
+ })
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/deps/npm/test/tap/lifecycle-INIT_CWD.js b/deps/npm/test/tap/lifecycle-INIT_CWD.js
index 3e9c1c8257..fbedd3849c 100644
--- a/deps/npm/test/tap/lifecycle-INIT_CWD.js
+++ b/deps/npm/test/tap/lifecycle-INIT_CWD.js
@@ -2,8 +2,6 @@ var fs = require('fs')
var path = require('path')
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
@@ -20,39 +18,19 @@ var json = {
}
test('setup', function (t) {
- cleanup()
- mkdirp.sync(pkg)
mkdirp.sync(subdir)
fs.writeFileSync(
path.join(pkg, 'package.json'),
JSON.stringify(json, null, 2)
)
-
- process.chdir(subdir)
- t.end()
-})
-
-test('make sure the env.INIT_CWD is correct', function (t) {
- common.npm(['run-script', 'initcwd'], {
- cwd: subdir
- }, function (er, code, stdout) {
- if (er) throw er
- t.equal(code, 0, 'exit code')
- stdout = stdout.trim().split(/\r|\n/).pop()
- var actual = stdout
-
- t.equal(actual, subdir)
- t.end()
- })
-})
-
-test('cleanup', function (t) {
- cleanup()
t.end()
})
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(subdir)
- rimraf.sync(pkg)
-}
+test('make sure the env.INIT_CWD is correct', t =>
+ common.npm(['run-script', 'initcwd'], { cwd: subdir })
+ .then(([code, stdout, stderr]) => {
+ t.equal(code, 0, 'exit code')
+ stdout = stdout.trim().split(/\r|\n/).pop()
+ var actual = stdout
+ t.equal(actual, subdir)
+ }))
diff --git a/deps/npm/test/tap/lifecycle-order.js b/deps/npm/test/tap/lifecycle-order.js
index 8f2b2ba4a7..ac6c07925c 100644
--- a/deps/npm/test/tap/lifecycle-order.js
+++ b/deps/npm/test/tap/lifecycle-order.js
@@ -1,13 +1,7 @@
var fs = require('graceful-fs')
var path = require('path')
-
-var mkdirp = require('mkdirp')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var test = require('tap').test
-
var common = require('../common-tap.js')
-
var pkg = common.pkg
var json = {
@@ -21,37 +15,19 @@ var json = {
}
test('setup', function (t) {
- cleanup()
- mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
JSON.stringify(json, null, 2)
)
-
- process.chdir(pkg)
t.end()
})
-test('lifecycle scripts execute in the proper order', function (t) {
- common.npm('install', {cwd: pkg}, function (err, code, stdout, stderr) {
- if (err) throw err
+test('lifecycle scripts execute in the proper order', t =>
+ common.npm('install', {cwd: pkg}).then(([code, stdout, stderr]) => {
t.is(code, 0, 'no error')
// All three files should exist
t.ok(fs.existsSync(path.join(pkg, 'preinstall-step')), 'preinstall ok')
t.ok(fs.existsSync(path.join(pkg, 'install-step')), 'install ok')
t.ok(fs.existsSync(path.join(pkg, 'postinstall-step')), 'postinstall ok')
-
- t.end()
- })
-})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
+ }))
diff --git a/deps/npm/test/tap/link.js b/deps/npm/test/tap/link.js
index f0339194a2..2d2d63de21 100644
--- a/deps/npm/test/tap/link.js
+++ b/deps/npm/test/tap/link.js
@@ -1,7 +1,5 @@
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
var path = require('path')
-var rimraf = require('rimraf')
var test = require('tap').test
var lstatSync = require('fs').lstatSync
var writeFileSync = require('fs').writeFileSync
@@ -72,7 +70,28 @@ var insideInstallJSON = {
}
test('setup', function (t) {
- setup()
+ mkdirp.sync(linkRoot)
+ mkdirp.sync(link)
+ writeFileSync(
+ path.join(link, 'package.json'),
+ JSON.stringify(readJSON, null, 2)
+ )
+ mkdirp.sync(linkScoped)
+ writeFileSync(
+ path.join(linkScoped, 'package.json'),
+ JSON.stringify(readScopedJSON, null, 2)
+ )
+ mkdirp.sync(linkInstall)
+ writeFileSync(
+ path.join(linkInstall, 'package.json'),
+ JSON.stringify(installJSON, null, 2)
+ )
+ mkdirp.sync(linkInside)
+ writeFileSync(
+ path.join(linkInside, 'package.json'),
+ JSON.stringify(insideInstallJSON, null, 2)
+ )
+ writeFileSync(configPath, config)
common.npm(['ls', '-g', '--depth=0'], OPTS, function (err, c, out) {
t.ifError(err)
t.equal(c, 0, 'set up ok')
@@ -173,50 +192,14 @@ test('ls the linked packages', function (t) {
})
test('cleanup', function (t) {
- process.chdir(osenv.tmpdir())
+ process.chdir(common.pkg)
common.npm(['rm', 'foo'], OPTS, function (err, code) {
t.ifError(err, 'npm removed the linked package without error')
t.equal(code, 0, 'cleanup foo in local ok')
common.npm(['rm', '-g', 'foo'], OPTS, function (err, code) {
t.ifError(err, 'npm removed the global package without error')
t.equal(code, 0, 'cleanup foo in global ok')
-
- cleanup()
t.end()
})
})
})
-
-function cleanup () {
- rimraf.sync(linkRoot)
- rimraf.sync(link)
- rimraf.sync(linkScoped)
- rimraf.sync(linkInstall)
- rimraf.sync(linkInside)
-}
-
-function setup () {
- cleanup()
- mkdirp.sync(linkRoot)
- mkdirp.sync(link)
- writeFileSync(
- path.join(link, 'package.json'),
- JSON.stringify(readJSON, null, 2)
- )
- mkdirp.sync(linkScoped)
- writeFileSync(
- path.join(linkScoped, 'package.json'),
- JSON.stringify(readScopedJSON, null, 2)
- )
- mkdirp.sync(linkInstall)
- writeFileSync(
- path.join(linkInstall, 'package.json'),
- JSON.stringify(installJSON, null, 2)
- )
- mkdirp.sync(linkInside)
- writeFileSync(
- path.join(linkInside, 'package.json'),
- JSON.stringify(insideInstallJSON, null, 2)
- )
- writeFileSync(configPath, config)
-}
diff --git a/deps/npm/test/tap/locker.js b/deps/npm/test/tap/locker.js
index 5ee64196fe..1df6fda710 100644
--- a/deps/npm/test/tap/locker.js
+++ b/deps/npm/test/tap/locker.js
@@ -2,8 +2,6 @@ var test = require('tap').test
var path = require('path')
var fs = require('graceful-fs')
var crypto = require('crypto')
-var rimraf = require('rimraf')
-var osenv = require('osenv')
var mkdirp = require('mkdirp')
var npm = require('../../')
var locker = require('../../lib/utils/locker.js')
@@ -16,13 +14,7 @@ var cache = path.join(pkg, '/cache')
var tmp = path.join(pkg, '/tmp')
var nm = path.join(pkg, '/node_modules')
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
-
test('setup', function (t) {
- cleanup()
mkdirp.sync(cache)
mkdirp.sync(tmp)
t.end()
@@ -83,8 +75,3 @@ test('unlocking out of order errors out', function (t) {
})
})
})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
diff --git a/deps/npm/test/tap/ls-depth-cli.js b/deps/npm/test/tap/ls-depth-cli.js
index 6bb2f3cd12..55142b3ad1 100644
--- a/deps/npm/test/tap/ls-depth-cli.js
+++ b/deps/npm/test/tap/ls-depth-cli.js
@@ -1,11 +1,8 @@
var fs = require('graceful-fs')
var path = require('path')
-var mkdirp = require('mkdirp')
var Bluebird = require('bluebird')
var mr = Bluebird.promisify(require('npm-registry-mock'))
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap')
@@ -29,8 +26,6 @@ var json = {
}
test('setup', function (t) {
- cleanup()
- mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
JSON.stringify(json, null, 2)
@@ -199,13 +194,3 @@ test('npm ls --depth=1 --parseable --long', function (t) {
}
)
})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/ls-depth-unmet.js b/deps/npm/test/tap/ls-depth-unmet.js
index 7a2ed4dacc..bf032efe9c 100644
--- a/deps/npm/test/tap/ls-depth-unmet.js
+++ b/deps/npm/test/tap/ls-depth-unmet.js
@@ -1,10 +1,7 @@
var fs = require('graceful-fs')
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')
@@ -25,8 +22,6 @@ var json = {
}
test('setup', function (t) {
- cleanup()
- mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
JSON.stringify(json, null, 2)
@@ -160,13 +155,3 @@ test('npm ls --depth=Infinity', function (t) {
}
)
})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/ls-env.js b/deps/npm/test/tap/ls-env.js
index e3fbece3b0..5d9d7cd06b 100644
--- a/deps/npm/test/tap/ls-env.js
+++ b/deps/npm/test/tap/ls-env.js
@@ -1,10 +1,7 @@
var fs = require('graceful-fs')
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')
@@ -22,8 +19,6 @@ var json = {
}
test('setup', function (t) {
- cleanup()
- mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
JSON.stringify(json, null, 2)
@@ -123,13 +118,3 @@ test('npm ls --only=prod', function (t) {
t.end()
})
})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/ls-l-depth-0.js b/deps/npm/test/tap/ls-l-depth-0.js
index b2516c9fa2..8e707a1d39 100644
--- a/deps/npm/test/tap/ls-l-depth-0.js
+++ b/deps/npm/test/tap/ls-l-depth-0.js
@@ -1,13 +1,10 @@
-var cat = require('graceful-fs').writeFileSync
+var writeFileSync = require('graceful-fs').writeFileSync
var resolve = require('path').resolve
var mkdirp = require('mkdirp')
var Bluebird = require('bluebird')
var mr = Bluebird.promisify(require('npm-registry-mock'))
-var rimraf = require('rimraf')
var test = require('tap').test
-var tmpdir = require('osenv').tmpdir
-
var common = require('../common-tap.js')
var pkg = common.pkg
@@ -25,8 +22,6 @@ var expected =
' file:glock-1.8.7.tgz\n' +
'\n'
-var server
-
var EXEC_OPTS = { cwd: pkg }
var fixture = {
@@ -44,9 +39,12 @@ var fixture = {
var deppack
test('setup', function (t) {
- setup()
+ mkdirp.sync(modules)
+ mkdirp.sync(dep)
+
+ writeFileSync(resolve(dep, 'package.json'), JSON.stringify(fixture))
return mr({ port: common.port }).then((s) => {
- server = s
+ t.parent.teardown(() => s.close())
return common.npm(['pack', dep], EXEC_OPTS)
}).spread((code, stdout) => {
t.is(code, 0, 'pack')
@@ -100,24 +98,3 @@ test('#6311: npm ll --depth=0 duplicates listing', function (t) {
}
)
})
-
-test('cleanup', function (t) {
- cleanup()
- server.close()
-
- t.end()
-})
-
-function cleanup () {
- process.chdir(tmpdir())
- rimraf.sync(pkg)
-}
-
-function setup () {
- cleanup()
-
- mkdirp.sync(modules)
- mkdirp.sync(dep)
-
- cat(resolve(dep, 'package.json'), JSON.stringify(fixture))
-}
diff --git a/deps/npm/test/tap/ls-production-and-dev.js b/deps/npm/test/tap/ls-production-and-dev.js
index a39e643786..5836c8fc13 100644
--- a/deps/npm/test/tap/ls-production-and-dev.js
+++ b/deps/npm/test/tap/ls-production-and-dev.js
@@ -1,10 +1,7 @@
var fs = require('graceful-fs')
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')
@@ -27,8 +24,6 @@ var json = {
}
test('setup', function (t) {
- cleanup()
- mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
JSON.stringify(json, null, 2)
@@ -160,13 +155,3 @@ test('npm ls --only=prod', function (t) {
t.end()
})
})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/no-global-warns.js b/deps/npm/test/tap/no-global-warns.js
index 538ab8b359..1c39fd7954 100644
--- a/deps/npm/test/tap/no-global-warns.js
+++ b/deps/npm/test/tap/no-global-warns.js
@@ -2,8 +2,6 @@
var path = require('path')
var test = require('tap').test
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var writeFileSync = require('fs').writeFileSync
var common = require('../common-tap.js')
@@ -38,7 +36,13 @@ var installJSON = {
}
test('setup', function (t) {
- setup()
+ mkdirp.sync(mockGlobal)
+ mkdirp.sync(toInstall)
+ writeFileSync(
+ path.join(toInstall, 'package.json'),
+ JSON.stringify(installJSON, null, 2)
+ )
+ writeFileSync(configPath, config)
t.end()
})
@@ -59,24 +63,3 @@ test('no-global-warns', function (t) {
t.end()
})
})
-
-test('cleanup', function (t) {
- process.chdir(osenv.tmpdir())
- cleanup()
- t.end()
-})
-
-function cleanup () {
- rimraf.sync(base)
-}
-
-function setup () {
- cleanup()
- mkdirp.sync(mockGlobal)
- mkdirp.sync(toInstall)
- writeFileSync(
- path.join(toInstall, 'package.json'),
- JSON.stringify(installJSON, null, 2)
- )
- writeFileSync(configPath, config)
-}
diff --git a/deps/npm/test/tap/no-scan-full-global-dir.js b/deps/npm/test/tap/no-scan-full-global-dir.js
index 7856ff33f4..7501b881c9 100644
--- a/deps/npm/test/tap/no-scan-full-global-dir.js
+++ b/deps/npm/test/tap/no-scan-full-global-dir.js
@@ -3,7 +3,6 @@ var fs = require('fs')
var path = require('path')
var test = require('tap').test
var requireInject = require('require-inject')
-var osenv = require('osenv')
var npm = require('../../lib/npm.js')
// XXX update this when rpt's realpath.js is extracted out
@@ -25,8 +24,6 @@ Object.keys(packages).forEach(function (name) {
files[path.join(packages[name].path, 'package.json')] = packages[name].package
})
-process.chdir(osenv.tmpdir())
-
var mockReaddir = function (name, cb) {
if (dirs[name]) return cb(null, dirs[name])
var er = new Error('No such mock: ' + name)
diff --git a/deps/npm/test/tap/optional-metadep-rollback-collision.js b/deps/npm/test/tap/optional-metadep-rollback-collision.js
index d665a123bf..b62d63d7f7 100644
--- a/deps/npm/test/tap/optional-metadep-rollback-collision.js
+++ b/deps/npm/test/tap/optional-metadep-rollback-collision.js
@@ -4,8 +4,6 @@ var fs = require('graceful-fs')
var path = require('path')
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
@@ -64,7 +62,7 @@ var opdep_json = {
}
}
-var blart = function () { /*
+var blart = `
var rando = require('crypto').randomBytes
var resolve = require('path').resolve
@@ -116,18 +114,15 @@ mkdirp(BASEDIR, function go () {
keepItGoingLouder = {}
}, 3 * 1000)
})
-*/ }.toString().split('\n').slice(1, -1).join('\n')
+`
-let badServer
-let mockServer
test('setup', function (t) {
- cleanup()
- badServer = createServer(function (req, res) {
+ const badServer = createServer(function (req, res) {
setTimeout(function () {
res.writeHead(404)
res.end()
}, 1000)
- }).listen(serverPort)
+ }).listen(serverPort, () => t.parent.teardown(() => badServer.close()))
mkdirp.sync(pkg)
fs.writeFileSync(
@@ -154,36 +149,36 @@ test('setup', function (t) {
JSON.stringify(opdep_json, null, 2)
)
mr({ port: common.port }, function (er, server) {
- mockServer = server
+ t.parent.teardown(() => server.close())
t.end()
})
})
-test('go go test racer', function (t) {
- return common.npm(
- [
- '--prefix', pkg,
- '--fetch-retries', '0',
- '--loglevel', 'error',
- '--no-progress',
- '--registry', common.registry,
- '--parseable',
- '--cache', cache,
- 'install'
- ],
- {
- cwd: pkg,
- env: {
- PATH: process.env.PATH,
- Path: process.env.Path
- },
- stdio: 'pipe'
- }).spread((code, stdout, stderr) => {
- t.comment(stdout.trim())
- t.comment(stderr.trim())
- t.is(code, 0, 'npm install exited with code 0')
- t.notOk(/not ok/.test(stdout), 'should not contain the string \'not ok\'')
- })
-})
+
+test('go go test racer', t => common.npm(
+ [
+ '--prefix', pkg,
+ '--fetch-retries', '0',
+ '--loglevel', 'error',
+ '--no-progress',
+ '--registry', common.registry,
+ '--parseable',
+ '--cache', cache,
+ 'install'
+ ],
+ {
+ cwd: pkg,
+ env: {
+ PATH: process.env.PATH,
+ Path: process.env.Path
+ },
+ stdio: 'pipe'
+ }
+).spread((code, stdout, stderr) => {
+ t.comment(stdout.trim())
+ t.comment(stderr.trim())
+ t.is(code, 0, 'npm install exited with code 0')
+ t.notOk(/not ok/.test(stdout), 'should not contain the string \'not ok\'')
+}))
test('verify results', function (t) {
t.throws(function () {
@@ -191,16 +186,3 @@ test('verify results', function (t) {
})
t.end()
})
-
-test('cleanup', function (t) {
- mockServer.close()
- badServer.close()
- cleanup()
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
-
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/outdated-depth.js b/deps/npm/test/tap/outdated-depth.js
index 8e272e6002..368d32230a 100644
--- a/deps/npm/test/tap/outdated-depth.js
+++ b/deps/npm/test/tap/outdated-depth.js
@@ -1,10 +1,7 @@
var fs = require('graceful-fs')
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 npm = require('../../')
@@ -22,8 +19,6 @@ var json = {
}
test('setup', function (t) {
- cleanup()
- mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
JSON.stringify(json, null, 2)
@@ -79,13 +74,3 @@ test('outdated depth zero', function (t) {
)
})
})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/peer-deps.js b/deps/npm/test/tap/peer-deps.js
index 463a5ec479..558fe9c4e6 100644
--- a/deps/npm/test/tap/peer-deps.js
+++ b/deps/npm/test/tap/peer-deps.js
@@ -1,10 +1,7 @@
var fs = require('graceful-fs')
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')
@@ -23,6 +20,17 @@ var json = {
}
}
+function setup (cb) {
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ process.chdir(pkg)
+
+ var opts = { cache: common.cache, registry: common.registry }
+ npm.load(opts, cb)
+}
+
test('installs the peer dependency directory structure', function (t) {
mr({ port: common.port }, function (er, s) {
setup(function (err) {
@@ -42,26 +50,3 @@ test('installs the peer dependency directory structure', function (t) {
})
})
})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function setup (cb) {
- cleanup()
- mkdirp.sync(pkg)
- fs.writeFileSync(
- path.join(pkg, 'package.json'),
- JSON.stringify(json, null, 2)
- )
- process.chdir(pkg)
-
- var opts = { cache: common.cache, registry: common.registry }
- npm.load(opts, cb)
-}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/publish-config.js b/deps/npm/test/tap/publish-config.js
index 7d617df2c4..0d6406316b 100644
--- a/deps/npm/test/tap/publish-config.js
+++ b/deps/npm/test/tap/publish-config.js
@@ -3,7 +3,6 @@
const common = require('../common-tap.js')
const test = require('tap').test
const fs = require('fs')
-const osenv = require('osenv')
const pkg = common.pkg
fs.writeFileSync(pkg + '/package.json', JSON.stringify({
@@ -58,7 +57,7 @@ test(function (t) {
HOME: process.env.HOME,
Path: process.env.PATH,
PATH: process.env.PATH,
- USERPROFILE: osenv.home()
+ USERPROFILE: process.env.USERPROFILE
}
}, function (err, code, stdout, stderr) {
t.comment(stdout)
diff --git a/deps/npm/test/tap/publish-invalid-semver-tag.js b/deps/npm/test/tap/publish-invalid-semver-tag.js
index fed064bb4e..b5d499f377 100644
--- a/deps/npm/test/tap/publish-invalid-semver-tag.js
+++ b/deps/npm/test/tap/publish-invalid-semver-tag.js
@@ -2,54 +2,52 @@ var common = require('../common-tap.js')
var test = require('tap').test
var npm = require('../../lib/npm.js')
var mkdirp = require('mkdirp')
-var rimraf = require('rimraf')
var path = require('path')
var fs = require('fs')
var mr = require('npm-registry-mock')
-var osenv = require('osenv')
-
var PKG_DIR = common.pkg
-var CACHE_DIR = common.cache
+let cacheIteration = 0
+let CACHE_DIR
var DEFAULT_PKG = {
'name': 'examples',
'version': '1.2.3'
}
-var mockServer
-
-const chownr = require('chownr')
-const fixOwner = (
- process.getuid && process.getuid() === 0 &&
- process.env.SUDO_UID && process.env.SUDO_GID
-) ? (path) => chownr.sync(path, +process.env.SUDO_UID, +process.env.SUDO_GID)
- : () => {}
-
+const isRoot = process.getuid && process.getuid() === 0
+const sudoUID = isRoot ? +process.env.SUDO_UID : null
+const sudoGID = isRoot ? +process.env.SUDO_GID : null
+const { chownSync } = require('fs')
function resetPackage (options) {
- rimraf.sync(CACHE_DIR)
+ CACHE_DIR = path.resolve(common.cache, '' + cacheIteration++)
mkdirp.sync(CACHE_DIR)
- fixOwner(CACHE_DIR)
+ npm.config.set('cache', CACHE_DIR)
+
+ if (isRoot && sudoUID && sudoGID) {
+ chownSync(CACHE_DIR, sudoUID, sudoGID)
+ }
fs.writeFileSync(path.resolve(PKG_DIR, 'package.json'), DEFAULT_PKG)
}
test('setup', function (t) {
- process.chdir(osenv.tmpdir())
mkdirp.sync(PKG_DIR)
process.chdir(PKG_DIR)
- resetPackage({})
-
mr({ port: common.port }, function (er, server) {
+ if (er) {
+ throw er
+ }
+ t.parent.teardown(() => server.close())
npm.load({
- cache: CACHE_DIR,
+ cache: common.cache,
registry: common.registry,
cwd: PKG_DIR
}, function (err) {
- t.ifError(err, 'started server')
- mockServer = server
-
+ if (err) {
+ throw err
+ }
t.end()
})
})
@@ -76,12 +74,3 @@ test('attempt publish with semver-like version', function (t) {
t.end()
})
})
-
-test('cleanup', function (t) {
- mockServer.close()
-
- process.chdir(osenv.tmpdir())
- rimraf.sync(PKG_DIR)
-
- t.end()
-})
diff --git a/deps/npm/test/tap/repo.js b/deps/npm/test/tap/repo.js
index 0ee50af192..3e97fdeaed 100644
--- a/deps/npm/test/tap/repo.js
+++ b/deps/npm/test/tap/repo.js
@@ -41,6 +41,41 @@ test('npm repo underscore', function (t) {
})
})
+test('npm repo underscore --json', function (t) {
+ mr({ port: common.port }, function (er, s) {
+ common.npm([
+ 'repo', 'underscore',
+ '--json',
+ '--registry=' + common.registry,
+ '--loglevel=silent',
+ '--no-browser'
+ ], opts, function (err, code, stdout, stderr) {
+ t.ifError(err, 'repo command ran without error')
+ t.equal(code, 0, 'exit ok')
+ t.matchSnapshot(stdout, 'should print json result')
+ s.close()
+ t.end()
+ })
+ })
+})
+
+test('npm repo underscore --no-browser', function (t) {
+ mr({ port: common.port }, function (er, s) {
+ common.npm([
+ 'repo', 'underscore',
+ '--no-browser',
+ '--registry=' + common.registry,
+ '--loglevel=silent'
+ ], opts, function (err, code, stdout, stderr) {
+ t.ifError(err, 'repo command ran without error')
+ t.equal(code, 0, 'exit ok')
+ t.matchSnapshot(stdout, 'should print alternative msg')
+ s.close()
+ t.end()
+ })
+ })
+})
+
test('npm repo optimist - github (https://)', function (t) {
mr({ port: common.port }, function (er, s) {
common.npm([
diff --git a/deps/npm/test/tap/scripts-whitespace-windows.js b/deps/npm/test/tap/scripts-whitespace-windows.js
index 06f06e36eb..9a301dca52 100644
--- a/deps/npm/test/tap/scripts-whitespace-windows.js
+++ b/deps/npm/test/tap/scripts-whitespace-windows.js
@@ -2,8 +2,6 @@ var fs = require('graceful-fs')
var path = require('path')
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap')
@@ -43,7 +41,6 @@ if (process.argv.length === 8)
*/ }.toString().split('\n').slice(1, -1).join('\n')
test('setup', function (t) {
- cleanup()
mkdirp.sync(tmp)
fs.writeFileSync(
path.join(pkg, 'package.json'),
@@ -89,13 +86,3 @@ test('test', function (t) {
t.end()
})
})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/semver-doc.js b/deps/npm/test/tap/semver-doc.js
index 31c75fffd8..1cc978201c 100644
--- a/deps/npm/test/tap/semver-doc.js
+++ b/deps/npm/test/tap/semver-doc.js
@@ -3,7 +3,7 @@ var test = require('tap').test
test('semver doc is up to date', function (t) {
var path = require('path')
var moddoc = path.join(__dirname, '../../node_modules/semver/README.md')
- var mydoc = path.join(__dirname, '../../doc/misc/semver.md')
+ var mydoc = path.join(__dirname, '../../docs/content/using-npm/semver.md')
var fs = require('fs')
var mod = fs.readFileSync(moddoc, 'utf8').replace(/semver\(1\)/, 'semver(7)')
var my = fs.readFileSync(mydoc, 'utf8')
diff --git a/deps/npm/test/tap/shrinkwrap-_auth.js b/deps/npm/test/tap/shrinkwrap-_auth.js
index 156bd9667c..2987e3eec0 100644
--- a/deps/npm/test/tap/shrinkwrap-_auth.js
+++ b/deps/npm/test/tap/shrinkwrap-_auth.js
@@ -5,11 +5,10 @@ var path = require('path')
var writeFileSync = require('graceful-fs').writeFileSync
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
var http = require('http')
-var rimraf = require('rimraf')
var ssri = require('ssri')
-var test = require('tap').test
+var t = require('tap')
+var test = t.test
var common = require('../common-tap.js')
@@ -23,7 +22,34 @@ var tarball = path.resolve(__dirname, '../fixtures/scoped-underscore-1.3.1.tgz')
var tarballIntegrity = ssri.fromData(fs.readFileSync(tarball)).toString()
var _auth = '0xabad1dea'
+
+var contents = '_auth=' + _auth + '\n' +
+ '\'always-auth\'=true\n'
+
+var json = {
+ name: 'test-package-install',
+ version: '1.0.0',
+ dependencies: {
+ '@scoped/underscore': '1.0.0'
+ }
+}
+
+var shrinkwrap = {
+ name: 'test-package-install',
+ version: '1.0.0',
+ lockfileVersion: 1,
+ dependencies: {
+ '@scoped/underscore': {
+ resolved: tarballURL,
+ integrity: tarballIntegrity,
+ version: '1.3.1'
+ }
+ }
+}
+
var server = http.createServer()
+t.teardown(() => server.close())
+
const errors = []
server.on('request', (req, res) => {
const auth = 'Basic ' + _auth
@@ -44,10 +70,14 @@ server.on('request', (req, res) => {
})
test('setup', function (t) {
- server.listen(common.port, () => {
- setup()
- t.done()
- })
+ mkdirp.sync(modules)
+ writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify(json, null, 2) + '\n')
+ writeFileSync(outfile, contents)
+ writeFileSync(
+ path.resolve(pkg, 'npm-shrinkwrap.json'),
+ JSON.stringify(shrinkwrap, null, 2) + '\n'
+ )
+ server.listen(common.port, t.end)
})
test('authed npm install with shrinkwrapped global package using _auth', function (t) {
@@ -77,50 +107,3 @@ test('authed npm install with shrinkwrapped global package using _auth', functio
}
)
})
-
-test('cleanup', function (t) {
- server.close(() => {
- cleanup()
- t.end()
- })
-})
-
-var contents = '_auth=' + _auth + '\n' +
- '\'always-auth\'=true\n'
-
-var json = {
- name: 'test-package-install',
- version: '1.0.0',
- dependencies: {
- '@scoped/underscore': '1.0.0'
- }
-}
-
-var shrinkwrap = {
- name: 'test-package-install',
- version: '1.0.0',
- lockfileVersion: 1,
- dependencies: {
- '@scoped/underscore': {
- resolved: tarballURL,
- integrity: tarballIntegrity,
- version: '1.3.1'
- }
- }
-}
-
-function setup () {
- cleanup()
- mkdirp.sync(modules)
- writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify(json, null, 2) + '\n')
- writeFileSync(outfile, contents)
- writeFileSync(
- path.resolve(pkg, 'npm-shrinkwrap.json'),
- JSON.stringify(shrinkwrap, null, 2) + '\n'
- )
-}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/shrinkwrap-dev-dependency.js b/deps/npm/test/tap/shrinkwrap-dev-dependency.js
index 066372e617..973cb5435b 100644
--- a/deps/npm/test/tap/shrinkwrap-dev-dependency.js
+++ b/deps/npm/test/tap/shrinkwrap-dev-dependency.js
@@ -1,10 +1,7 @@
var fs = require('fs')
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')
@@ -46,26 +43,11 @@ var json = {
}
}
-function setup () {
- cleanup()
- mkdirp.sync(pkg)
- fs.writeFileSync(path.join(pkg, 'package.json'), JSON.stringify(json, null, 2))
- process.chdir(pkg)
-}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
-
-test('setup', function (t) {
- setup()
- t.end()
-})
-
test("shrinkwrap doesn't strip out the dependency", function (t) {
t.plan(3)
- setup()
+
+ fs.writeFileSync(path.join(pkg, 'package.json'), JSON.stringify(json, null, 2))
+ process.chdir(pkg)
mr({port: common.port}, function (er, s) {
common.npm(opts.concat(['install', '.']), {stdio: [0, 'pipe', 2]}, function (err, code) {
@@ -86,8 +68,3 @@ test("shrinkwrap doesn't strip out the dependency", function (t) {
})
})
})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
diff --git a/deps/npm/test/tap/shrinkwrap-empty-deps.js b/deps/npm/test/tap/shrinkwrap-empty-deps.js
index af9b4810af..3c68845745 100644
--- a/deps/npm/test/tap/shrinkwrap-empty-deps.js
+++ b/deps/npm/test/tap/shrinkwrap-empty-deps.js
@@ -2,11 +2,8 @@
const common = require('../common-tap.js')
const fs = require('fs')
-const mkdirp = require('mkdirp')
const mr = require('npm-registry-mock')
-const osenv = require('osenv')
const path = require('path')
-const rimraf = require('rimraf')
const test = require('tap').test
const pkg = common.pkg
@@ -22,8 +19,6 @@ const json = {
}
test('setup', function (t) {
- cleanup()
- mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
JSON.stringify(json, null, 2)
@@ -61,14 +56,3 @@ test('returns a list of removed items', function (t) {
)
})
})
-
-test('cleanup', function (t) {
- cleanup()
-
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/shrinkwrap-extra-metadata.js b/deps/npm/test/tap/shrinkwrap-extra-metadata.js
index a5ff721a7a..6e652e2db0 100644
--- a/deps/npm/test/tap/shrinkwrap-extra-metadata.js
+++ b/deps/npm/test/tap/shrinkwrap-extra-metadata.js
@@ -2,12 +2,9 @@
const common = require('../common-tap.js')
const fs = require('fs')
-const mkdirp = require('mkdirp')
const mr = require('npm-registry-mock')
const npm = require('../../lib/npm.js')
-const osenv = require('osenv')
const path = require('path')
-const rimraf = require('rimraf')
const test = require('tap').test
const pkg = common.pkg
@@ -19,8 +16,6 @@ const json = {
}
test('setup', function (t) {
- cleanup()
- mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
JSON.stringify(json, null, 2)
@@ -32,6 +27,7 @@ test('setup', function (t) {
test('adds additional metadata fields from the pkglock spec', function (t) {
mr({ port: common.port }, function (er, s) {
+ t.teardown(() => s.close())
common.npm(
[
'--registry', common.registry,
@@ -56,21 +52,9 @@ test('adds additional metadata fields from the pkglock spec', function (t) {
'shrinkwrap wrote the expected metadata fields'
)
- s.close()
t.end()
})
}
)
})
})
-
-test('cleanup', function (t) {
- cleanup()
-
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/shrinkwrap-global-auth.js b/deps/npm/test/tap/shrinkwrap-global-auth.js
index e860abd2fe..e14a328a43 100644
--- a/deps/npm/test/tap/shrinkwrap-global-auth.js
+++ b/deps/npm/test/tap/shrinkwrap-global-auth.js
@@ -6,8 +6,6 @@ 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 ssri = require('ssri')
var test = require('tap').test
@@ -22,7 +20,30 @@ var tarballURL = common.registry + tarballPath
var tarball = path.resolve(__dirname, '../fixtures/scoped-underscore-1.3.1.tgz')
var tarballIntegrity = ssri.fromData(fs.readFileSync(tarball)).toString()
-var server
+var contents = 'registry=' + common.registry + '\n' +
+ '_authToken=0xabad1dea\n' +
+ '\'always-auth\'=true\n'
+
+var json = {
+ name: 'test-package-install',
+ version: '1.0.0',
+ dependencies: {
+ '@scoped/underscore': '1.0.0'
+ }
+}
+
+var shrinkwrap = {
+ name: 'test-package-install',
+ version: '1.0.0',
+ lockfileVersion: 1,
+ dependencies: {
+ '@scoped/underscore': {
+ resolved: tarballURL,
+ integrity: tarballIntegrity,
+ version: '1.3.1'
+ }
+ }
+}
function mocks (server) {
var auth = 'Bearer 0xabad1dea'
@@ -34,10 +55,16 @@ function mocks (server) {
}
test('setup', function (t) {
+ mkdirp.sync(modules)
+ writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify(json, null, 2) + '\n')
+ writeFileSync(outfile, contents)
+ writeFileSync(
+ path.resolve(pkg, 'npm-shrinkwrap.json'),
+ JSON.stringify(shrinkwrap, null, 2) + '\n'
+ )
mr({ port: common.port, plugin: mocks }, function (er, s) {
- server = s
+ t.parent.teardown(() => s.close())
t.ok(s, 'set up mock registry')
- setup()
t.end()
})
})
@@ -68,50 +95,3 @@ test('authed npm install with shrinkwrapped global package', function (t) {
}
)
})
-
-test('cleanup', function (t) {
- server.close()
- cleanup()
- t.end()
-})
-
-var contents = 'registry=' + common.registry + '\n' +
- '_authToken=0xabad1dea\n' +
- '\'always-auth\'=true\n'
-
-var json = {
- name: 'test-package-install',
- version: '1.0.0',
- dependencies: {
- '@scoped/underscore': '1.0.0'
- }
-}
-
-var shrinkwrap = {
- name: 'test-package-install',
- version: '1.0.0',
- lockfileVersion: 1,
- dependencies: {
- '@scoped/underscore': {
- resolved: tarballURL,
- integrity: tarballIntegrity,
- version: '1.3.1'
- }
- }
-}
-
-function setup () {
- cleanup()
- mkdirp.sync(modules)
- writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify(json, null, 2) + '\n')
- writeFileSync(outfile, contents)
- writeFileSync(
- path.resolve(pkg, 'npm-shrinkwrap.json'),
- JSON.stringify(shrinkwrap, null, 2) + '\n'
- )
-}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/shrinkwrap-lifecycle.js b/deps/npm/test/tap/shrinkwrap-lifecycle.js
index 5ed35e1868..6e6bc4c287 100644
--- a/deps/npm/test/tap/shrinkwrap-lifecycle.js
+++ b/deps/npm/test/tap/shrinkwrap-lifecycle.js
@@ -1,16 +1,10 @@
var fs = require('graceful-fs')
var path = require('path')
-
-var mkdirp = require('mkdirp')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var test = require('tap').test
-
var common = require('../common-tap.js')
var pkg = common.pkg
test('npm shrinkwrap execution order', function (t) {
- setup()
fs.writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify({
author: 'Simen Bekkhus',
name: 'shrinkwrap-lifecycle',
@@ -22,7 +16,7 @@ test('npm shrinkwrap execution order', function (t) {
postshrinkwrap: 'echo this happens third'
}
}), 'utf8')
- common.npm(['shrinkwrap', '--loglevel=error'], [], function (err, code, stdout, stderr) {
+ common.npm(['shrinkwrap', '--loglevel=error'], { cwd: pkg }, function (err, code, stdout, stderr) {
if (err) throw err
t.comment(stdout)
@@ -41,14 +35,3 @@ test('npm shrinkwrap execution order', function (t) {
t.end()
})
})
-
-test('cleanup', function (t) {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
- t.end()
-})
-
-function setup () {
- mkdirp.sync(pkg)
- process.chdir(pkg)
-}
diff --git a/deps/npm/test/tap/shrinkwrap-optional-dependency.js b/deps/npm/test/tap/shrinkwrap-optional-dependency.js
index 621e6c4c59..a08d153849 100644
--- a/deps/npm/test/tap/shrinkwrap-optional-dependency.js
+++ b/deps/npm/test/tap/shrinkwrap-optional-dependency.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')
@@ -22,17 +20,17 @@ test('shrinkwrap does not fail on missing optional dependency', function (t) {
}
mr({port: common.port, mocks: mocks}, function (er, s) {
- function fail (err) {
- s.close() // Close on failure to allow node to exit
- t.fail(err)
- }
-
+ t.parent.teardown(() => s.close())
setup(function (err) {
- if (err) return fail(err)
+ if (err) {
+ throw err
+ }
// Install without the optional dependency
npm.install('.', function (err) {
- if (err) return fail(err)
+ if (err) {
+ throw err
+ }
// Pretend the optional dependency was specified, but somehow failed to load:
json.optionalDependencies = {
@@ -41,7 +39,9 @@ test('shrinkwrap does not fail on missing optional dependency', function (t) {
writePackage()
npm.commands.shrinkwrap([], true, function (err, results) {
- if (err) return fail(err)
+ if (err) {
+ throw err
+ }
t.deepEqual(results.dependencies, desired.dependencies)
s.close()
@@ -52,11 +52,6 @@ test('shrinkwrap does not fail on missing optional dependency', function (t) {
})
})
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
var desired = {
name: 'npm-test-shrinkwrap-optional-dependency',
version: '0.0.0',
@@ -83,19 +78,14 @@ function writePackage () {
}
function setup (cb) {
- cleanup()
mkdirp.sync(pkg)
writePackage()
process.chdir(pkg)
var opts = {
cache: common.cache,
- registry: common.registry
+ registry: common.registry,
+ cwd: pkg
}
npm.load(opts, cb)
}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/shrinkwrap-optional-property.js b/deps/npm/test/tap/shrinkwrap-optional-property.js
index f9b37f2f30..c2dc8585ae 100644
--- a/deps/npm/test/tap/shrinkwrap-optional-property.js
+++ b/deps/npm/test/tap/shrinkwrap-optional-property.js
@@ -1,10 +1,7 @@
var fs = require('fs')
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')
@@ -16,22 +13,24 @@ test('shrinkwrap adds optional property when optional dependency', function (t)
t.plan(1)
mr({port: common.port}, function (er, s) {
- function fail (err) {
- s.close() // Close on failure to allow node to exit
- t.fail(err)
- }
-
+ t.parent.teardown(() => s.close())
setup(function (err) {
- if (err) return fail(err)
+ if (err) {
+ throw err
+ }
// Install with the optional dependency
npm.install('.', function (err) {
- if (err) return fail(err)
+ if (err) {
+ throw err
+ }
writePackage()
npm.commands.shrinkwrap([], true, function (err, results) {
- if (err) return fail(err)
+ if (err) {
+ throw err
+ }
t.deepEqual(results.dependencies, desired.dependencies)
s.close()
@@ -42,11 +41,6 @@ test('shrinkwrap adds optional property when optional dependency', function (t)
})
})
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
var desired = {
name: 'npm-test-shrinkwrap-optional-dependency',
version: '0.0.0',
@@ -82,8 +76,6 @@ function writePackage () {
}
function setup (cb) {
- cleanup()
- mkdirp.sync(pkg)
writePackage()
process.chdir(pkg)
@@ -93,8 +85,3 @@ function setup (cb) {
}
npm.load(opts, cb)
}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/shrinkwrap-prod-dependency-also.js b/deps/npm/test/tap/shrinkwrap-prod-dependency-also.js
index 96ebe2249e..1e4e9d7438 100644
--- a/deps/npm/test/tap/shrinkwrap-prod-dependency-also.js
+++ b/deps/npm/test/tap/shrinkwrap-prod-dependency-also.js
@@ -1,10 +1,7 @@
var fs = require('fs')
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')
@@ -21,13 +18,42 @@ function reportOutput (t, fh, out) {
t.comment(prefix + trimmed.split(/\n/).join('\n' + prefix))
}
-var server
+var desired = {
+ name: 'npm-test-shrinkwrap-prod-dependency',
+ version: '0.0.0',
+ dependencies: {
+ request: {
+ version: '0.9.0',
+ resolved: common.registry + '/request/-/request-0.9.0.tgz',
+ integrity: 'sha1-EEn1mm9GWI5tAwkh+7hMovDCcU4='
+ },
+ underscore: {
+ dev: true,
+ version: '1.5.1',
+ resolved: common.registry + '/underscore/-/underscore-1.5.1.tgz',
+ integrity: 'sha1-0r3oF9F2/63olKtxRY5oKhS4bck='
+ }
+ }
+}
+
+var json = {
+ author: 'Domenic Denicola',
+ name: 'npm-test-shrinkwrap-prod-dependency',
+ version: '0.0.0',
+ dependencies: {
+ request: '0.9.0'
+ },
+ devDependencies: {
+ underscore: '1.5.1'
+ }
+}
+
test("shrinkwrap --also=development doesn't strip out prod dependencies", function (t) {
t.plan(4)
mr({port: common.port}, function (er, s) {
- server = s
- setup()
+ t.parent.teardown(() => s.close())
+ fs.writeFileSync(path.join(pkg, 'package.json'), JSON.stringify(json, null, 2))
common.npm(['install', '.'].concat(opts), {cwd: pkg}, function (err, code, stdout, stderr) {
if (err) return t.fail(err)
t.is(code, 0, 'install')
@@ -57,50 +83,3 @@ test("shrinkwrap --also=development doesn't strip out prod dependencies", functi
})
})
})
-
-test('cleanup', function (t) {
- server.close()
- cleanup()
- t.end()
-})
-
-var desired = {
- name: 'npm-test-shrinkwrap-prod-dependency',
- version: '0.0.0',
- dependencies: {
- request: {
- version: '0.9.0',
- resolved: common.registry + '/request/-/request-0.9.0.tgz',
- integrity: 'sha1-EEn1mm9GWI5tAwkh+7hMovDCcU4='
- },
- underscore: {
- dev: true,
- version: '1.5.1',
- resolved: common.registry + '/underscore/-/underscore-1.5.1.tgz',
- integrity: 'sha1-0r3oF9F2/63olKtxRY5oKhS4bck='
- }
- }
-}
-
-var json = {
- author: 'Domenic Denicola',
- name: 'npm-test-shrinkwrap-prod-dependency',
- version: '0.0.0',
- dependencies: {
- request: '0.9.0'
- },
- devDependencies: {
- underscore: '1.5.1'
- }
-}
-
-function setup (opts) {
- cleanup()
- mkdirp.sync(pkg)
- fs.writeFileSync(path.join(pkg, 'package.json'), JSON.stringify(json, null, 2))
-}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/shrinkwrap-prod-dependency.js b/deps/npm/test/tap/shrinkwrap-prod-dependency.js
index 6c175af819..bf6d98bf80 100644
--- a/deps/npm/test/tap/shrinkwrap-prod-dependency.js
+++ b/deps/npm/test/tap/shrinkwrap-prod-dependency.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 npm = require('../../')
@@ -12,34 +10,6 @@ var npm = require('../../')
var common = require('../common-tap.js')
var pkg = common.pkg
-test("shrinkwrap --dev doesn't strip out prod dependencies", function (t) {
- t.plan(1)
-
- mr({port: common.port}, function (er, s) {
- setup({}, function (err) {
- if (err) return t.fail(err)
-
- npm.install('.', function (err) {
- if (err) return t.fail(err)
-
- npm.config.set('dev', true)
- npm.commands.shrinkwrap([], true, function (err, results) {
- if (err) return t.fail(err)
-
- t.deepEqual(results.dependencies, desired.dependencies)
- s.close()
- t.end()
- })
- })
- })
- })
-})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
var desired = {
name: 'npm-test-shrinkwrap-prod-dependency',
version: '0.0.0',
@@ -70,8 +40,7 @@ var json = {
}
}
-function setup (opts, cb) {
- cleanup()
+test('setup', function (t) {
mkdirp.sync(pkg)
fs.writeFileSync(path.join(pkg, 'package.json'), JSON.stringify(json, null, 2))
process.chdir(pkg)
@@ -81,14 +50,27 @@ function setup (opts, cb) {
registry: common.registry
}
- for (var key in opts) {
- allOpts[key] = opts[key]
- }
+ npm.load(allOpts, t.end)
+})
- npm.load(allOpts, cb)
-}
+test('mock registry', t => {
+ mr({port: common.port}, function (er, s) {
+ t.parent.teardown(() => s.close())
+ t.end()
+ })
+})
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
+test("shrinkwrap --dev doesn't strip out prod dependencies", t => {
+ t.plan(1)
+ npm.install('.', function (err) {
+ if (err) return t.fail(err)
+
+ npm.config.set('dev', true)
+ npm.commands.shrinkwrap([], true, function (err, results) {
+ if (err) return t.fail(err)
+
+ t.deepEqual(results.dependencies, desired.dependencies)
+ t.end()
+ })
+ })
+})
diff --git a/deps/npm/test/tap/shrinkwrap-save-dev-with-existing-deps.js b/deps/npm/test/tap/shrinkwrap-save-dev-with-existing-deps.js
index a71408e54f..1c35bf226b 100644
--- a/deps/npm/test/tap/shrinkwrap-save-dev-with-existing-deps.js
+++ b/deps/npm/test/tap/shrinkwrap-save-dev-with-existing-deps.js
@@ -1,12 +1,8 @@
/* eslint-disable camelcase */
var fs = require('fs')
var path = require('path')
-
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var test = require('tap').test
-
var common = require('../common-tap.js')
var base = common.pkg
@@ -74,7 +70,6 @@ function writeJson (filename, obj) {
}
test('setup', function (t) {
- cleanup()
writeJson(installme_pkg, installme_pkg_json)
writeJson(example_pkg, example_pkg_json)
writeJson(example_shrinkwrap, example_shrinkwrap_json)
@@ -95,13 +90,3 @@ test('install --save-dev leaves prod deps alone', function (t) {
t.end()
})
})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(base)
-}
diff --git a/deps/npm/test/tap/shrinkwrap-save-with-existing-dev-deps.js b/deps/npm/test/tap/shrinkwrap-save-with-existing-dev-deps.js
index 8a3f449fa8..acf6ac2101 100644
--- a/deps/npm/test/tap/shrinkwrap-save-with-existing-dev-deps.js
+++ b/deps/npm/test/tap/shrinkwrap-save-with-existing-dev-deps.js
@@ -3,8 +3,6 @@ var fs = require('fs')
var path = require('path')
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
@@ -63,7 +61,6 @@ function writeJson (filename, obj) {
}
test('setup', function (t) {
- cleanup()
writeJson(installme_pkg, installme_pkg_json)
writeJson(example_pkg, example_pkg_json)
writeJson(example_shrinkwrap, example_shrinkwrap_json)
@@ -71,24 +68,12 @@ test('setup', function (t) {
t.end()
})
-test('install --save leaves dev deps alone', function (t) {
- common.npm(['install', '--save', 'file://' + installme], EXEC_OPTS, function (er, code, stdout, stderr) {
- t.ifError(er, "spawn didn't catch fire")
- t.is(code, 0, 'install completed ok')
- t.is(stderr, '', 'install completed without error output')
- var shrinkwrap = JSON.parse(fs.readFileSync(example_shrinkwrap))
- t.ok(shrinkwrap.dependencies.installed, "save new install didn't remove dev dep")
- t.ok(shrinkwrap.dependencies.installme, 'save new install DID add new dep')
- t.end()
- })
-})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(base)
-}
+test('install --save leaves dev deps alone', t =>
+ common.npm(['install', '--save', 'file://' + installme], EXEC_OPTS)
+ .then(([code, stdout, stderr]) => {
+ t.is(code, 0, 'install completed ok')
+ t.is(stderr, '', 'install completed without error output')
+ var shrinkwrap = JSON.parse(fs.readFileSync(example_shrinkwrap))
+ t.ok(shrinkwrap.dependencies.installed, "save new install didn't remove dev dep")
+ t.ok(shrinkwrap.dependencies.installme, 'save new install DID add new dep')
+ }))
diff --git a/deps/npm/test/tap/shrinkwrap-scoped-auth.js b/deps/npm/test/tap/shrinkwrap-scoped-auth.js
index 3098b8aa12..cc1b227001 100644
--- a/deps/npm/test/tap/shrinkwrap-scoped-auth.js
+++ b/deps/npm/test/tap/shrinkwrap-scoped-auth.js
@@ -6,8 +6,6 @@ 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 ssri = require('ssri')
var test = require('tap').test
@@ -22,8 +20,6 @@ var tarballURL = common.registry + tarballPath
var tarball = path.resolve(__dirname, '../fixtures/scoped-underscore-1.3.1.tgz')
var tarballIntegrity = ssri.fromData(fs.readFileSync(tarball)).toString()
-var server
-
function mocks (server) {
var auth = 'Bearer 0xabad1dea'
server.get(tarballPath, { authorization: auth }).replyWithFile(200, tarball)
@@ -33,11 +29,41 @@ function mocks (server) {
})
}
+var contents = '@scoped:registry=' + common.registry + '\n' +
+ toNerfDart(common.registry) + ':_authToken=0xabad1dea\n'
+
+var json = {
+ name: 'test-package-install',
+ version: '1.0.0',
+ dependencies: {
+ '@scoped/underscore': '1.0.0'
+ }
+}
+
+var shrinkwrap = {
+ name: 'test-package-install',
+ version: '1.0.0',
+ lockfileVersion: 1,
+ dependencies: {
+ '@scoped/underscore': {
+ resolved: tarballURL,
+ integrity: tarballIntegrity,
+ version: '1.3.1'
+ }
+ }
+}
+
test('setup', function (t) {
+ mkdirp.sync(modules)
+ writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify(json, null, 2) + '\n')
+ writeFileSync(outfile, contents)
+ writeFileSync(
+ path.resolve(pkg, 'npm-shrinkwrap.json'),
+ JSON.stringify(shrinkwrap, null, 2) + '\n'
+ )
mr({ port: common.port, plugin: mocks }, function (er, s) {
- server = s
+ t.parent.teardown(() => s.close())
t.ok(s, 'set up mock registry')
- setup()
t.end()
})
})
@@ -68,49 +94,3 @@ test('authed npm install with shrinkwrapped scoped package', function (t) {
}
)
})
-
-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',
- dependencies: {
- '@scoped/underscore': '1.0.0'
- }
-}
-
-var shrinkwrap = {
- name: 'test-package-install',
- version: '1.0.0',
- lockfileVersion: 1,
- dependencies: {
- '@scoped/underscore': {
- resolved: tarballURL,
- integrity: tarballIntegrity,
- version: '1.3.1'
- }
- }
-}
-
-function setup () {
- cleanup()
- mkdirp.sync(modules)
- writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify(json, null, 2) + '\n')
- writeFileSync(outfile, contents)
- writeFileSync(
- path.resolve(pkg, 'npm-shrinkwrap.json'),
- JSON.stringify(shrinkwrap, null, 2) + '\n'
- )
-}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/startstop.js b/deps/npm/test/tap/startstop.js
index 3491441821..dd07352e0d 100644
--- a/deps/npm/test/tap/startstop.js
+++ b/deps/npm/test/tap/startstop.js
@@ -2,8 +2,6 @@ var fs = require('graceful-fs')
var path = require('path')
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap')
@@ -33,7 +31,6 @@ function testOutput (t, command, er, code, stdout, stderr) {
}
test('setup', function (t) {
- cleanup()
mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
@@ -62,13 +59,3 @@ test('npm restart', function (t) {
t.end()
})
})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/symlink-cycle.js b/deps/npm/test/tap/symlink-cycle.js
index d59a2763bd..ea0c0f5359 100644
--- a/deps/npm/test/tap/symlink-cycle.js
+++ b/deps/npm/test/tap/symlink-cycle.js
@@ -3,8 +3,6 @@ var fs = require('fs')
var path = require('path')
var test = require('tap').test
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var writeFileSync = require('fs').writeFileSync
var common = require('../common-tap.js')
@@ -27,7 +25,12 @@ var cycleJSON = {
}
test('setup', function (t) {
- setup()
+ mkdirp.sync(path.join(cycle, 'node_modules'))
+ writeFileSync(
+ path.join(cycle, 'package.json'),
+ JSON.stringify(cycleJSON, null, 2)
+ )
+ fs.symlinkSync(cycle, path.join(cycle, 'node_modules', 'cycle'), 'junction')
t.end()
})
@@ -39,23 +42,3 @@ test('ls', function (t) {
t.end()
})
})
-
-test('cleanup', function (t) {
- process.chdir(osenv.tmpdir())
- cleanup()
- t.end()
-})
-
-function cleanup () {
- rimraf.sync(base)
-}
-
-function setup () {
- cleanup()
- mkdirp.sync(path.join(cycle, 'node_modules'))
- writeFileSync(
- path.join(cycle, 'package.json'),
- JSON.stringify(cycleJSON, null, 2)
- )
- fs.symlinkSync(cycle, path.join(cycle, 'node_modules', 'cycle'), 'junction')
-}
diff --git a/deps/npm/test/tap/uninstall-package.js b/deps/npm/test/tap/uninstall-package.js
index 87fdee2281..3e0b404b6c 100644
--- a/deps/npm/test/tap/uninstall-package.js
+++ b/deps/npm/test/tap/uninstall-package.js
@@ -1,10 +1,7 @@
var fs = require('graceful-fs')
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')
@@ -24,14 +21,10 @@ var json = {
}
test('setup', function (t) {
- cleanup()
- mkdirp.sync(pkg)
- process.chdir(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
JSON.stringify(json, null, 2)
)
-
t.end()
})
@@ -90,13 +83,3 @@ test('does not fail if installed package lacks a name somehow', function (t) {
}
)
})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
diff --git a/deps/npm/test/tap/uninstall-save.js b/deps/npm/test/tap/uninstall-save.js
index 0605616e07..bf1683edca 100644
--- a/deps/npm/test/tap/uninstall-save.js
+++ b/deps/npm/test/tap/uninstall-save.js
@@ -3,12 +3,10 @@ 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')
-var server
var pkg = common.pkg
@@ -20,10 +18,14 @@ var json = {
}
test('setup', function (t) {
- setup()
+ mkdirp.sync(path.resolve(pkg, 'node_modules'))
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
mr({ port: common.port }, function (er, s) {
t.ifError(er, 'started mock registry')
- server = s
+ t.parent.teardown(() => s.close())
t.end()
})
})
@@ -68,25 +70,3 @@ test('uninstall --save removes rm-ed package from package.json', function (t) {
)
})
})
-
-test('cleanup', function (t) {
- server.close()
- cleanup()
- t.end()
-})
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
-
-function setup () {
- cleanup()
- mkdirp.sync(path.resolve(pkg, 'node_modules'))
- fs.writeFileSync(
- path.join(pkg, 'package.json'),
- JSON.stringify(json, null, 2)
- )
-
- process.chdir(pkg)
-}
diff --git a/deps/npm/test/tap/unpack-foreign-tarball.js b/deps/npm/test/tap/unpack-foreign-tarball.js
index 7e965d9f08..b3a9026f84 100644
--- a/deps/npm/test/tap/unpack-foreign-tarball.js
+++ b/deps/npm/test/tap/unpack-foreign-tarball.js
@@ -1,9 +1,8 @@
var fs = require('graceful-fs')
var path = require('path')
-var test = require('tap').test
+var t = require('tap')
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
var rimraf = require('rimraf')
var common = require('../common-tap.js')
@@ -24,64 +23,62 @@ var EXEC_OPTS = {
cwd: pkg
}
-function verify (t, files, err, code) {
+function verify (t, files, code) {
if (code) {
- t.fail('exited with failure: ' + code)
- return t.end()
+ return t.fail('exited with failure: ' + code)
}
var actual = fs.readdirSync(target).sort()
var expect = files.concat(['.npmignore', 'package.json']).sort()
t.same(actual, expect)
- t.end()
}
-test('setup', function (t) {
- setup()
- t.comment('test for https://github.com/npm/npm/issues/5658')
- t.end()
-})
+t.comment('test for https://github.com/npm/npm/issues/5658')
-test('npmignore only', function (t) {
+t.test('npmignore only', function (t) {
+ t.test('setup', setup)
var file = path.resolve(fixtures, 'npmignore.tgz')
- common.npm(['install', file], EXEC_OPTS, verify.bind(null, t, ['foo']))
+ return t.test('test', t => common.npm(['install', file], EXEC_OPTS)
+ .then(([code]) => verify(t, ['foo'], code)))
})
-test('gitignore only', function (t) {
- setup()
+t.test('gitignore only', function (t) {
+ t.test('setup', setup)
var file = path.resolve(fixtures, 'gitignore.tgz')
- common.npm(['install', file], EXEC_OPTS, verify.bind(null, t, ['foo']))
+ return t.test('test', t => common.npm(['install', file], EXEC_OPTS)
+ .then(([code]) => verify(t, ['foo'], code)))
})
-test('gitignore and npmignore', function (t) {
- setup()
+t.test('gitignore and npmignore', function (t) {
+ t.test('setup', setup)
var file = path.resolve(fixtures, 'gitignore-and-npmignore.tgz')
- common.npm(['install', file], EXEC_OPTS, verify.bind(null, t, ['foo', 'bar']))
+ return t.test('test', t => common.npm(['install', file], EXEC_OPTS)
+ .then(([code]) => verify(t, ['foo', 'bar'], code)))
})
-test('gitignore and npmignore, not gzipped 1/2', function (t) {
- setup()
+t.test('gitignore and npmignore, not gzipped 1/2', function (t) {
+ t.test('setup', setup)
var file = path.resolve(fixtures, 'gitignore-and-npmignore.tar')
- common.npm(['install', file], EXEC_OPTS, verify.bind(null, t, ['foo', 'bar']))
+ return t.test('test', t => common.npm(['install', file], EXEC_OPTS)
+ .then(([code]) => verify(t, ['foo', 'bar'], code)))
})
-test('gitignore and npmignore, not gzipped 2/2', function (t) {
- setup()
+t.test('gitignore and npmignore, not gzipped 2/2', function (t) {
+ t.test('setup', setup)
var file = path.resolve(fixtures, 'gitignore-and-npmignore-2.tar')
- common.npm(['install', file], EXEC_OPTS, verify.bind(null, t, ['foo', 'bar']))
+ return t.test('test', t => common.npm(['install', file], EXEC_OPTS)
+ .then(([code]) => verify(t, ['foo', 'bar'], code)))
})
-test('cleanup', function (t) {
- cleanup()
+function setup (t) {
+ t.test('destroy', t => {
+ t.plan(2)
+ t.test('node_modules', t => rimraf(nm, t.end))
+ t.test('tmp', t => rimraf(tmp, t.end))
+ })
+ t.test('create', t => {
+ mkdirp.sync(nm)
+ mkdirp.sync(tmp)
+ t.end()
+ })
t.end()
-})
-
-function setup () {
- cleanup()
- mkdirp.sync(nm)
- mkdirp.sync(tmp)
-}
-
-function cleanup () {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
}
diff --git a/deps/npm/test/tap/unpublish-config.js b/deps/npm/test/tap/unpublish-config.js
index f358835561..6d5c981d08 100644
--- a/deps/npm/test/tap/unpublish-config.js
+++ b/deps/npm/test/tap/unpublish-config.js
@@ -2,9 +2,6 @@ var fs = require('graceful-fs')
var http = require('http')
var path = require('path')
-var mkdirp = require('mkdirp')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
@@ -18,8 +15,6 @@ var json = {
}
test('setup', function (t) {
- mkdirp.sync(pkg)
-
fs.writeFileSync(
path.join(pkg, 'package.json'),
JSON.stringify(json), 'utf8'
@@ -63,7 +58,7 @@ test('cursory test of unpublishing with config', function (t) {
HOME: process.env.HOME,
Path: process.env.PATH,
PATH: process.env.PATH,
- USERPROFILE: osenv.home()
+ USERPROFILE: process.env.USERPROFILE
}
},
function (err, code) {
@@ -73,9 +68,3 @@ test('cursory test of unpublishing with config', function (t) {
)
})
})
-
-test('cleanup', function (t) {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
- t.end()
-})
diff --git a/deps/npm/test/tap/update-examples.js b/deps/npm/test/tap/update-examples.js
index 8b6323ff1c..2217386de8 100644
--- a/deps/npm/test/tap/update-examples.js
+++ b/deps/npm/test/tap/update-examples.js
@@ -1,11 +1,7 @@
var common = require('../common-tap.js')
var test = require('tap').test
var mkdirp = require('mkdirp')
-var rimraf = require('rimraf')
var mr = require('npm-registry-mock')
-
-var osenv = require('osenv')
-
var requireInject = require('require-inject')
var PKG_DIR = common.pkg
@@ -64,7 +60,6 @@ var registryMocks = {
}
// ** dynamic mocks, cloned from templates and modified **
-var mockServer
var mockDepJson = clone(DEP_PKG)
var mockInstalled = clone(INSTALLED)
var mockParentJson = clone(DEFAULT_PKG)
@@ -83,17 +78,20 @@ function extend (a, b) {
return a
}
-const chownr = require('chownr')
-const fixOwner = (
- process.getuid && process.getuid() === 0 &&
- process.env.SUDO_UID && process.env.SUDO_GID
-) ? (path) => chownr.sync(path, +process.env.SUDO_UID, +process.env.SUDO_GID)
- : () => {}
-
+const path = require('path')
+let cacheIteration = 0
+const isRoot = process.getuid && process.getuid() === 0
+const sudoUID = isRoot ? +process.env.SUDO_UID : null
+const sudoGID = isRoot ? +process.env.SUDO_GID : null
+const { chownSync } = require('fs')
function resetPackage (options) {
- rimraf.sync(CACHE_DIR)
+ CACHE_DIR = path.resolve(common.cache, '' + cacheIteration++)
+ npm.config.set('cache', CACHE_DIR)
mkdirp.sync(CACHE_DIR)
- fixOwner(CACHE_DIR)
+
+ if (isRoot && sudoUID && sudoGID) {
+ chownSync(CACHE_DIR, sudoUID, sudoGID)
+ }
installAskedFor = undefined
@@ -145,20 +143,18 @@ var npm = requireInject.installGlobally('../../lib/npm.js', {
test('setup', function (t) {
t.plan(5)
- process.chdir(osenv.tmpdir())
- mkdirp.sync(PKG_DIR)
process.chdir(PKG_DIR)
t.pass('made ' + PKG_DIR)
- resetPackage({})
-
mr({ port: common.port, mocks: registryMocks }, function (er, server) {
t.pass('mock registry active')
- npm.load({ cache: CACHE_DIR,
+ npm.load({
+ cache: CACHE_DIR,
registry: common.registry,
- cwd: PKG_DIR }, function (err) {
+ cwd: PKG_DIR
+ }, function (err) {
t.ifError(err, 'started server')
- mockServer = server
+ t.parent.teardown(() => server.close())
t.pass('npm.load complete')
@@ -223,12 +219,3 @@ test('update old caret dependency with newer', function (t) {
t.end()
})
})
-
-test('cleanup', function (t) {
- mockServer.close()
-
- process.chdir(osenv.tmpdir())
- rimraf.sync(PKG_DIR)
-
- t.end()
-})
diff --git a/deps/npm/test/tap/url-dependencies.js b/deps/npm/test/tap/url-dependencies.js
index 2017151568..14da5d1fc4 100644
--- a/deps/npm/test/tap/url-dependencies.js
+++ b/deps/npm/test/tap/url-dependencies.js
@@ -1,14 +1,10 @@
var fs = require('graceful-fs')
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')
-var server
var pkg = common.pkg
@@ -27,87 +23,39 @@ var mockRoutes = {
}
}
-test('setup', function (t) {
- mr({ port: common.port, mocks: mockRoutes }, function (er, s) {
- server = s
- t.end()
- })
-})
-
-test('url-dependencies: download first time', function (t) {
- setup()
-
- performInstall(t, function (output) {
- if (!tarballWasFetched(output)) {
- t.fail('Tarball was not fetched')
- } else {
- t.pass('Tarball was fetched')
- }
- t.end()
- })
-})
-
-test('url-dependencies: do not download subsequent times', function (t) {
- setup()
-
- performInstall(t, function () {
- performInstall(t, function (output) {
- if (tarballWasFetched(output)) {
- t.fail('Tarball was fetched second time around')
- } else {
- t.pass('Tarball was not fetched')
- }
- t.end()
- })
- })
-})
-
-test('cleanup', function (t) {
- server.close()
- cleanup()
- t.end()
+const tarballWasFetched = output => output.includes(
+ `GET 200 ${common.registry}/underscore/-/underscore-1.3.1.tgz`)
+
+const performInstall = () => common.npm(['install'], {
+ cwd: pkg,
+ env: {
+ npm_config_registry: common.registry,
+ npm_config_cache_lock_stale: 1000,
+ npm_config_cache_lock_wait: 1000,
+ npm_config_loglevel: 'http',
+ HOME: process.env.HOME,
+ Path: process.env.PATH,
+ PATH: process.env.PATH
+ }
})
-function cleanup () {
- // windows fix for locked files
- process.chdir(osenv.tmpdir())
- rimraf.sync(path.resolve(pkg))
-}
-
-function setup () {
- cleanup()
- mkdirp.sync(pkg)
+test('setup', function (t) {
fs.writeFileSync(
path.join(pkg, 'package.json'),
JSON.stringify(json, null, 2)
)
-}
-
-function tarballWasFetched (output) {
- return output.indexOf(
- 'GET 200 ' +
- common.registry +
- '/underscore/-/underscore-1.3.1.tgz'
- ) > -1
-}
-
-function performInstall (t, cb) {
- var opts = {
- cwd: pkg,
- env: {
- npm_config_registry: common.registry,
- npm_config_cache_lock_stale: 1000,
- npm_config_cache_lock_wait: 1000,
- npm_config_loglevel: 'http',
- HOME: process.env.HOME,
- Path: process.env.PATH,
- PATH: process.env.PATH
- }
- }
- common.npm(['install'], opts, function (err, code, stdout, stderr) {
- t.ifError(err, 'install success')
- t.notOk(code, 'npm install exited with code 0')
+ mr({ port: common.port, mocks: mockRoutes }, function (er, s) {
+ t.parent.teardown(() => s.close())
+ t.end()
+ })
+})
- cb(stderr)
+test('url-dependencies: download first time', t =>
+ performInstall().then(([code, _, output]) => {
+ t.equal(code, 0, 'exited successfully')
+ t.ok(tarballWasFetched(output), 'download first time')
})
-}
+ .then(() => performInstall()).then(([code, _, output]) => {
+ t.equal(code, 0, 'exited successfully')
+ t.notOk(tarballWasFetched(output), 'do not download second time')
+ }))
diff --git a/deps/npm/test/tap/utils.funding.js b/deps/npm/test/tap/utils.funding.js
new file mode 100644
index 0000000000..60a7a1e67e
--- /dev/null
+++ b/deps/npm/test/tap/utils.funding.js
@@ -0,0 +1,480 @@
+'use strict'
+
+const { test } = require('tap')
+const { getFundingInfo } = require('../../lib/utils/funding')
+
+test('empty tree', (t) => {
+ t.deepEqual(
+ getFundingInfo({}),
+ {
+ name: null,
+ dependencies: {},
+ length: 0
+ },
+ 'should return empty list'
+ )
+ t.end()
+})
+
+test('single item missing funding', (t) => {
+ t.deepEqual(
+ getFundingInfo({ name: 'project',
+ dependencies: {
+ 'single-item': {
+ name: 'single-item',
+ version: '1.0.0'
+ }
+ }}),
+ {
+ name: 'project',
+ dependencies: {},
+ length: 0
+ },
+ 'should return empty list'
+ )
+ t.end()
+})
+
+test('use path if name is missing', (t) => {
+ t.deepEqual(
+ getFundingInfo({ name: undefined,
+ path: '/tmp/foo',
+ children: {
+ 'single-item': {
+ name: 'single-item',
+ version: '1.0.0'
+ }
+ }}),
+ {
+ name: '/tmp/foo',
+ dependencies: {},
+ length: 0
+ },
+ 'should use path as top level name'
+ )
+ t.end()
+})
+
+test('single item tree', (t) => {
+ t.deepEqual(
+ getFundingInfo({ name: 'project',
+ dependencies: {
+ 'single-item': {
+ name: 'single-item',
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'http://example.com'
+ }
+ }
+ }}),
+ {
+ name: 'project',
+ dependencies: {
+ 'single-item': {
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'http://example.com'
+ }
+ }
+ },
+ length: 1
+ },
+ 'should return list with a single item'
+ )
+ t.end()
+})
+
+test('duplicate items along the tree', (t) => {
+ t.deepEqual(
+ getFundingInfo({ name: 'project',
+ version: '2.3.4',
+ dependencies: {
+ 'single-item': {
+ name: 'single-item',
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ },
+ dependencies: {
+ 'shared-top-first': {
+ name: 'shared-top-first',
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ }
+ },
+ 'sub-dep': {
+ name: 'sub-dep',
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ },
+ dependencies: {
+ 'shared-nested-first': {
+ name: 'shared-nested-first',
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ },
+ dependencies: {
+ 'shared-top-first': {
+ name: 'shared-top-first',
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ }
+ }
+ }
+ }
+ }
+ },
+ 'shared-nested-first': {
+ name: 'shared-nested-first',
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ }
+ }
+ }
+ }
+ }}),
+ {
+ name: 'project',
+ version: '2.3.4',
+ dependencies: {
+ 'single-item': {
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ },
+ dependencies: {
+ 'shared-top-first': {
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ }
+ },
+ 'sub-dep': {
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ }
+ },
+ 'shared-nested-first': {
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ }
+ }
+ }
+ }
+ },
+ length: 4
+ },
+ 'should return list with a single item'
+ )
+ t.end()
+})
+
+test('multi-level nested items tree', (t) => {
+ t.deepEqual(
+ getFundingInfo({ name: 'project',
+ dependencies: {
+ 'first-level-dep': {
+ name: 'first-level-dep',
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ },
+ dependencies: {
+ 'sub-dep': {
+ name: 'sub-dep',
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ },
+ dependencies: {
+ package: {
+ name: 'sub-sub-dep',
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ },
+ dependencies: {}
+ }
+ }
+ }
+ }
+ }
+ }}),
+ {
+ name: 'project',
+ dependencies: {
+ 'first-level-dep': {
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ },
+ dependencies: {
+ 'sub-dep': {
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ },
+ dependencies: {
+ 'sub-sub-dep': {
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ length: 3
+ },
+ 'should return list with all items'
+ )
+ t.end()
+})
+
+test('missing fund nested items tree', (t) => {
+ t.deepEqual(
+ getFundingInfo({ name: 'project',
+ dependencies: {
+ 'first-level-dep': {
+ name: 'first-level-dep',
+ version: '1.0.0',
+ funding: {
+ type: 'foo'
+ },
+ dependencies: {
+ 'sub-dep': {
+ name: 'sub-dep',
+ version: '1.0.0',
+ dependencies: {
+ 'sub-sub-dep-01': {
+ name: 'sub-sub-dep-01',
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ },
+ dependencies: {
+ 'non-funding-child': {
+ name: 'non-funding-child',
+ version: '1.0.0',
+ dependencies: {
+ 'sub-sub-sub-dep': {
+ name: 'sub-sub-sub-dep',
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ }
+ }
+ }
+ }
+ }
+ },
+ 'sub-sub-dep-02': {
+ name: 'sub-sub-dep-02',
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ },
+ dependencies: {}
+ },
+ 'sub-sub-dep-03': {
+ name: 'sub-sub-dep-03',
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'git://example.git'
+ },
+ dependencies: {
+ 'sub-sub-sub-dep-03': {
+ name: 'sub-sub-sub-dep-03',
+ version: '1.0.0',
+ dependencies: {
+ 'sub-sub-sub-sub-dep': {
+ name: 'sub-sub-sub-sub-dep',
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'http://example.com'
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }}),
+ {
+ name: 'project',
+ dependencies: {
+ 'sub-sub-dep-01': {
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ },
+ dependencies: {
+ 'sub-sub-sub-dep': {
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ }
+ }
+ }
+ },
+ 'sub-sub-dep-02': {
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ }
+ },
+ 'sub-sub-sub-sub-dep': {
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'http://example.com'
+ }
+ }
+ },
+ length: 4
+ },
+ 'should return list excluding missing funding items'
+ )
+ t.end()
+})
+
+test('countOnly option', (t) => {
+ t.deepEqual(
+ getFundingInfo({ name: 'project',
+ dependencies: {
+ 'first-level-dep': {
+ name: 'first-level-dep',
+ version: '1.0.0',
+ funding: {
+ type: 'foo'
+ },
+ dependencies: {
+ 'sub-dep': {
+ name: 'sub-dep',
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ },
+ dependencies: {
+ 'sub-sub-dep': {
+ name: 'sub-sub-dep',
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ }
+ },
+ dependencies: {}
+ }
+ },
+ 'sub-sub-dep': {
+ name: 'sub-sub-dep',
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ }
+ }
+ }
+ }
+ }}, { countOnly: true }),
+ {
+ length: 2
+ },
+ 'should return only the length property'
+ )
+ t.end()
+})
+
+test('handle different versions', (t) => {
+ t.deepEqual(
+ getFundingInfo({ name: 'project',
+ dependencies: {
+ foo: {
+ name: 'foo',
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ },
+ dependencies: {
+ bar: {
+ name: 'bar',
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ }
+ }
+ }
+ },
+ lorem: {
+ dependencies: {
+ fooo: {
+ name: 'foo',
+ version: '2.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ },
+ dependencies: {
+ 'foo-bar': {
+ name: 'foo-bar',
+ version: '1.0.0',
+ funding: {
+ type: 'foo',
+ url: 'https://example.com'
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }, { countOnly: true }),
+ {
+ length: 4
+ },
+ 'should treat different versions as diff packages'
+ )
+ t.end()
+})
diff --git a/deps/npm/test/tap/version-allow-same-version.js b/deps/npm/test/tap/version-allow-same-version.js
index 6b7978edeb..41310e4eb2 100644
--- a/deps/npm/test/tap/version-allow-same-version.js
+++ b/deps/npm/test/tap/version-allow-same-version.js
@@ -1,65 +1,40 @@
-var fs = require('graceful-fs')
-var path = require('path')
+const fs = require('graceful-fs')
+const path = require('path')
+const t = require('tap')
+const common = require('../common-tap.js')
+const npm = require('../../')
+const pkg = common.pkg
+const cache = common.cache
+const npmrc = path.resolve(pkg, './.npmrc')
+const configContents = 'sign-git-tag=false\n'
-var mkdirp = require('mkdirp')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
-var test = require('tap').test
-
-var common = require('../common-tap.js')
-var npm = require('../../')
-var pkg = common.pkg
-var cache = common.cache
-var npmrc = path.resolve(pkg, './.npmrc')
-var configContents = 'sign-git-tag=false\n'
-
-test('npm version <semver> with same version without --allow-same-version', function (t) {
- setup()
+t.test('setup', t => {
+ process.chdir(pkg)
+ fs.writeFileSync(npmrc, configContents, 'ascii')
fs.writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify({
author: 'Lucas Theisen',
name: 'version-allow-same-version',
version: '0.0.1',
description: 'Test for npm version without --allow-same-version'
}), 'utf8')
- npm.load({cache: cache, 'allow-same-version': false, registry: common.registry}, function () {
- var version = require('../../lib/version')
- version(['0.0.1'], function (err) {
- t.ok(err)
- t.like(err.message, /Version not changed/)
- t.end()
- })
- })
+ npm.load({cache: cache, 'allow-same-version': false, registry: common.registry}, t.end)
})
-test('npm version <semver> with same version with --allow-same-version', function (t) {
- setup()
- fs.writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify({
- author: 'Lucas Theisen',
- name: 'version-allow-same-version',
- version: '0.0.1',
- description: 'Test for npm version without --allow-same-version'
- }), 'utf8')
- npm.load({cache: cache, 'allow-same-version': true, registry: common.registry}, function () {
- var version = require('../../lib/version')
- version(['0.0.1'],
- function (err) { t.ok(!err) },
- function () { t.end() })
+
+t.test('without --allow-same-version', t => {
+ npm.config.set('allow-same-version', false)
+ npm.commands.version(['0.0.1'], function (err) {
+ t.isa(err, Error, 'got an error')
+ t.like(err.message, /Version not changed/)
+ t.end()
})
})
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function cleanup () {
- // windows fix for locked files
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
-function setup () {
- mkdirp.sync(pkg)
- mkdirp.sync(path.join(pkg, 'node_modules'))
- mkdirp.sync(cache)
- fs.writeFileSync(npmrc, configContents, 'ascii')
- process.chdir(pkg)
-}
+t.test('with --allow-same-version', t => {
+ npm.config.set('allow-same-version', true)
+ npm.commands.version(['0.0.1'], function (err) {
+ if (err) {
+ throw err
+ }
+ t.end()
+ })
+})
diff --git a/deps/npm/test/tap/version-commit-hooks.js b/deps/npm/test/tap/version-commit-hooks.js
index 568c82b46b..028767ab4e 100644
--- a/deps/npm/test/tap/version-commit-hooks.js
+++ b/deps/npm/test/tap/version-commit-hooks.js
@@ -1,10 +1,7 @@
-var fs = require('graceful-fs')
-var path = require('path')
-var osenv = require('osenv')
-var mkdirp = require('mkdirp')
-var rimraf = require('rimraf')
+const fs = require('graceful-fs')
+const path = require('path')
const common = require('../common-tap.js')
-var pkg = common.pkg
+const pkg = common.pkg
var test = require('tap').test
var npm = require('../../')
@@ -12,7 +9,6 @@ var npm = require('../../')
delete process.env['npm_config_commit_hooks']
test('npm version <semver> with commit-hooks disabled in .npmrc', function (t) {
- mkdirp.sync(pkg)
var npmrc = path.resolve(pkg, '.npmrc')
fs.writeFileSync(npmrc, 'commit-hooks=false\n', 'ascii')
process.chdir(pkg)
@@ -57,9 +53,3 @@ test('npm version <semver> with commit-hooks enabled (default)', function (t) {
t.end()
})
})
-
-test('cleanup', function (t) {
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
- t.end()
-})
diff --git a/deps/npm/test/tap/version-consistent-newlines.js b/deps/npm/test/tap/version-consistent-newlines.js
index 4387c489e2..583874db7a 100644
--- a/deps/npm/test/tap/version-consistent-newlines.js
+++ b/deps/npm/test/tap/version-consistent-newlines.js
@@ -3,11 +3,9 @@
const common = require('../common-tap.js')
const test = require('tap').test
const npm = require('../../')
-const osenv = require('osenv')
const path = require('path')
const fs = require('fs')
const mkdirp = require('mkdirp')
-const rimraf = require('rimraf')
const requireInject = require('require-inject')
const pkg = common.pkg
@@ -66,16 +64,7 @@ test('npm version does not alter the line endings in package.json (CRLF)', funct
})
})
-test('cleanup', function (t) {
- process.chdir(osenv.tmpdir())
-
- rimraf.sync(pkg)
- t.end()
-})
-
function setup (lineEnding) {
- mkdirp.sync(pkg)
- mkdirp.sync(cache)
mkdirp.sync(gitDir)
fs.writeFileSync(
path.resolve(pkg, 'package.json'),
diff --git a/deps/npm/test/tap/version-sub-directory.js b/deps/npm/test/tap/version-sub-directory.js
index 809f24e79f..fc4a41f36e 100644
--- a/deps/npm/test/tap/version-sub-directory.js
+++ b/deps/npm/test/tap/version-sub-directory.js
@@ -3,8 +3,6 @@ var fs = require('fs')
var path = require('path')
var mkdirp = require('mkdirp')
-var osenv = require('osenv')
-var rimraf = require('rimraf')
var test = require('tap').test
var npm = require('../../lib/npm.js')
@@ -17,7 +15,9 @@ var cache = common.cache
var json = { name: 'cat', version: '0.1.2' }
test('npm version <semver> from a subdirectory', function (t) {
- setup()
+ mkdirp.sync(subDirectory)
+ process.chdir(subDirectory)
+ fs.writeFileSync(packagePath, JSON.stringify(json), 'utf8')
npmLoad()
function npmLoad () {
@@ -54,22 +54,3 @@ test('npm version <semver> from a subdirectory', function (t) {
t.end()
}
})
-
-test('cleanup', function (t) {
- cleanup()
- t.end()
-})
-
-function cleanup () {
- // windows fix for locked files
- process.chdir(osenv.tmpdir())
- rimraf.sync(pkg)
-}
-
-function setup () {
- cleanup()
- mkdirp.sync(cache)
- mkdirp.sync(subDirectory)
- process.chdir(subDirectory)
- fs.writeFileSync(packagePath, JSON.stringify(json), 'utf8')
-}
diff --git a/deps/npm/test/tap/view.js b/deps/npm/test/tap/view.js
index a01fa903a2..71d21487ae 100644
--- a/deps/npm/test/tap/view.js
+++ b/deps/npm/test/tap/view.js
@@ -1,10 +1,14 @@
var common = require('../common-tap.js')
-var test = require('tap').test
+const t = require('tap')
+var test = t.test
var osenv = require('osenv')
var path = require('path')
var fs = require('fs')
var rimraf = require('rimraf')
var mkdirp = require('mkdirp')
+
+// this test has to use a tmpdir so that it's outside of
+// the current package context of npm.
var tmp = osenv.tmpdir()
var t1dir = path.resolve(tmp, 'view-local-no-pkg')
var t2dir = path.resolve(tmp, 'view-local-notmine')
@@ -13,6 +17,15 @@ var mr = require('npm-registry-mock')
var server
+t.teardown(() => {
+ rimraf.sync(t1dir)
+ rimraf.sync(t2dir)
+ rimraf.sync(t3dir)
+ if (server) {
+ server.close()
+ }
+})
+
test('setup', function (t) {
mkdirp.sync(t1dir)
mkdirp.sync(t2dir)
@@ -46,7 +59,6 @@ function plugin (server) {
}
test('npm view . in global mode', function (t) {
- process.chdir(t1dir)
common.npm([
'view',
'.',
@@ -61,7 +73,6 @@ test('npm view . in global mode', function (t) {
})
test('npm view --global', function (t) {
- process.chdir(t1dir)
common.npm([
'view',
'--registry=' + common.registry,
@@ -75,7 +86,6 @@ test('npm view --global', function (t) {
})
test('npm view . with no package.json', function (t) {
- process.chdir(t1dir)
common.npm([
'view',
'.',
@@ -89,7 +99,6 @@ test('npm view . with no package.json', function (t) {
})
test('npm view . with no published package', function (t) {
- process.chdir(t3dir)
common.npm([
'view',
'.',
@@ -103,7 +112,6 @@ test('npm view . with no published package', function (t) {
})
test('npm view .', function (t) {
- process.chdir(t2dir)
common.npm([
'view',
'.',
@@ -117,7 +125,6 @@ test('npm view .', function (t) {
})
test('npm view . select fields', function (t) {
- process.chdir(t2dir)
common.npm([
'view',
'.',
@@ -132,7 +139,6 @@ test('npm view . select fields', function (t) {
})
test('npm view .@<version>', function (t) {
- process.chdir(t2dir)
common.npm([
'view',
'.@0.0.0',
@@ -147,7 +153,6 @@ test('npm view .@<version>', function (t) {
})
test('npm view .@<version> version --json', function (t) {
- process.chdir(t2dir)
common.npm([
'view',
'.@0.0.0',
@@ -163,7 +168,6 @@ test('npm view .@<version> version --json', function (t) {
})
test('npm view . --json author name version', function (t) {
- process.chdir(t2dir)
common.npm([
'view',
'.',
@@ -186,7 +190,6 @@ test('npm view . --json author name version', function (t) {
})
test('npm view .@<version> --json author name version', function (t) {
- process.chdir(t2dir)
common.npm([
'view',
'.@0.0.0',
@@ -376,13 +379,3 @@ test('npm view with valid but non existent package name', function (t) {
t.end()
})
})
-
-test('cleanup', function (t) {
- process.chdir(osenv.tmpdir())
- rimraf.sync(t1dir)
- rimraf.sync(t2dir)
- rimraf.sync(t3dir)
- t.pass('cleaned up')
- server.close()
- t.end()
-})