summaryrefslogtreecommitdiff
path: root/deps/npm/test/tap
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/test/tap')
-rw-r--r--deps/npm/test/tap/00-config-setup.js2
-rw-r--r--deps/npm/test/tap/add-remote-git-submodule.js5
-rw-r--r--deps/npm/test/tap/adduser-legacy-auth.js10
-rw-r--r--deps/npm/test/tap/bundled-dependencies-nonarray.js6
-rw-r--r--deps/npm/test/tap/bundled-dependencies.js11
-rw-r--r--deps/npm/test/tap/bundled-transitive-deps.js15
-rw-r--r--deps/npm/test/tap/config-basic.js1
-rw-r--r--deps/npm/test/tap/config-builtin.js1
-rw-r--r--deps/npm/test/tap/config-list.js34
-rw-r--r--deps/npm/test/tap/config-save.js2
-rw-r--r--deps/npm/test/tap/files-and-ignores.js103
-rw-r--r--deps/npm/test/tap/git-npmignore.js3
-rw-r--r--deps/npm/test/tap/help.js26
-rw-r--r--deps/npm/test/tap/install-scoped-with-peer-dependency.js2
-rw-r--r--deps/npm/test/tap/install-windows-newlines.js90
-rw-r--r--deps/npm/test/tap/lifecycle-INIT_CWD.js58
-rw-r--r--deps/npm/test/tap/lifecycle.js44
-rw-r--r--deps/npm/test/tap/no-global-warns.js14
-rw-r--r--deps/npm/test/tap/optional-metadep-rollback-collision.js85
-rw-r--r--deps/npm/test/tap/ping.js2
-rw-r--r--deps/npm/test/tap/prune-dev-dep-with-bins.js104
-rw-r--r--deps/npm/test/tap/unit-deps-replaceModule.js8
-rw-r--r--deps/npm/test/tap/unsupported.js26
-rw-r--r--deps/npm/test/tap/verify-no-lifecycle-on-repo.js6
-rw-r--r--deps/npm/test/tap/version-commit-hooks-default.js13
-rw-r--r--deps/npm/test/tap/version-commit-hooks.js64
26 files changed, 555 insertions, 180 deletions
diff --git a/deps/npm/test/tap/00-config-setup.js b/deps/npm/test/tap/00-config-setup.js
index 7303c8328f..448453eded 100644
--- a/deps/npm/test/tap/00-config-setup.js
+++ b/deps/npm/test/tap/00-config-setup.js
@@ -13,7 +13,6 @@ exports.ucData =
'init.author.email': 'i@izs.me',
'init.author.url': 'http://blog.izs.me/',
'init.version': '1.2.3',
- 'proprietary-attribs': false,
'npm:publishtest': true,
'_npmjs.org:couch': 'https://admin:password@localhost:5984/registry',
'npm-www:nocache': '1',
@@ -63,7 +62,6 @@ try {
// project conf not found, probably working with packed npm
fs.writeFileSync(projectConf, function () { /*
save-prefix = ~
-proprietary-attribs = false
legacy-bundling = true
*/ }.toString().split('\n').slice(1, -1).join('\n'))
}
diff --git a/deps/npm/test/tap/add-remote-git-submodule.js b/deps/npm/test/tap/add-remote-git-submodule.js
index 86fcaa0ee2..6e26712c56 100644
--- a/deps/npm/test/tap/add-remote-git-submodule.js
+++ b/deps/npm/test/tap/add-remote-git-submodule.js
@@ -77,6 +77,9 @@ function bootstrap (t) {
}
function setup (cb) {
+ rimraf.sync(pkg)
+ rimraf.sync(repos)
+
mkdirp.sync(topwt)
fs.writeFileSync(resolve(topwt, 'package.json'), pjChild)
mkdirp.sync(subwt)
@@ -120,12 +123,14 @@ function setup (cb) {
var reposopt = { cwd: repos, env: env }
common.makeGitRepo({
path: subwt,
+ message: 'subwt repo: ' + subwt,
added: ['foo.txt'],
commands: [
git.chainableExec(['clone', '--bare', subwt, 'sub.git'], reposopt),
startDaemon,
[common.makeGitRepo, {
path: topwt,
+ message: 'topwt repo: ' + topwt,
commands: [
git.chainableExec(['submodule', 'add', suburl, 'subpath'], topopt),
git.chainableExec(['commit', '-m', 'added submodule'], topopt),
diff --git a/deps/npm/test/tap/adduser-legacy-auth.js b/deps/npm/test/tap/adduser-legacy-auth.js
index 1fc1210edb..67292cf06a 100644
--- a/deps/npm/test/tap/adduser-legacy-auth.js
+++ b/deps/npm/test/tap/adduser-legacy-auth.js
@@ -56,14 +56,14 @@ test('npm login', function (t) {
[
'login',
'--registry', common.registry,
- '--loglevel', 'silent',
+ '--loglevel', 'error',
'--userconfig', outfile
],
opts,
function (err, code, stdout, stderr) {
- t.ifError(err, 'npm ran without issue')
- t.notOk(code, 'exited OK')
- t.notOk(stderr, 'no error output')
+ if (err) throw err
+ t.is(code, 0, 'exited OK')
+ t.is(stderr, '', 'no error output')
var config = fs.readFileSync(outfile, 'utf8')
t.like(config, /:always-auth=false/, 'always-auth is scoped and false (by default)')
s.close()
@@ -80,7 +80,7 @@ test('npm login', function (t) {
remaining--
var label = chunk.toString('utf8').split(':')[0]
- runner.stdin.write(responses[label])
+ if (responses[label]) runner.stdin.write(responses[label])
if (remaining === 0) runner.stdin.end()
} else {
diff --git a/deps/npm/test/tap/bundled-dependencies-nonarray.js b/deps/npm/test/tap/bundled-dependencies-nonarray.js
index 8f8eeb358f..924e1b27b6 100644
--- a/deps/npm/test/tap/bundled-dependencies-nonarray.js
+++ b/deps/npm/test/tap/bundled-dependencies-nonarray.js
@@ -34,7 +34,7 @@ test('setup', function (t) {
t.end()
})
-test('errors on non-array bundleddependencies', function (t) {
+test('handles non-array bundleddependencies', function (t) {
return Bluebird.try(() => {
return common.npm(['pack', 'a-bundled-dep/'], {cwd: dir, stdio: [0, 1, 2]})
}).spread((code) => {
@@ -44,8 +44,8 @@ test('errors on non-array bundleddependencies', function (t) {
t.is(code, 0, 'prepared pkg-with-bundled')
return common.npm(['pack', 'pkg-with-bundled/'], {cwd: dir, stdio: [0, 1, 'pipe']})
}).spread((code, _, stderr) => {
- t.notEqual(code, 0, 'exited with a error code')
- t.like(stderr, /be an array/, 'nice error output')
+ t.equal(code, 0, 'exited with a error code')
+ t.equal(stderr, '')
})
})
diff --git a/deps/npm/test/tap/bundled-dependencies.js b/deps/npm/test/tap/bundled-dependencies.js
index a49610e666..c6d67e3c50 100644
--- a/deps/npm/test/tap/bundled-dependencies.js
+++ b/deps/npm/test/tap/bundled-dependencies.js
@@ -6,7 +6,6 @@ var rimraf = require('rimraf')
var mkdirp = require('mkdirp')
var fs = require('graceful-fs')
var tar = require('tar')
-var zlib = require('zlib')
var basepath = path.resolve(__dirname, path.basename(__filename, '.js'))
var fixturepath = path.resolve(basepath, 'npm-test-bundled-deps')
var targetpath = path.resolve(basepath, 'target')
@@ -103,10 +102,8 @@ function withFixture (t, fixture, tester) {
function extractTarball (cb) {
// Unpack to disk so case-insensitive filesystems are consistent
- fs.createReadStream(path.join(basepath, 'npm-test-files-1.2.5.tgz'))
- .pipe(zlib.Unzip())
- .on('error', cb)
- .pipe(tar.Extract(targetpath))
- .on('error', cb)
- .on('end', function () { cb() })
+ tar.extract({
+ file: path.join(basepath, 'npm-test-files-1.2.5.tgz'),
+ cwd: targetpath
+ }).then(cb, cb)
}
diff --git a/deps/npm/test/tap/bundled-transitive-deps.js b/deps/npm/test/tap/bundled-transitive-deps.js
index 9af12337d6..fe59149062 100644
--- a/deps/npm/test/tap/bundled-transitive-deps.js
+++ b/deps/npm/test/tap/bundled-transitive-deps.js
@@ -7,8 +7,8 @@ var File = Tacks.File
var Dir = Tacks.Dir
var common = require('../common-tap.js')
var npm = require('../../lib/npm.js')
-var tar = require('../../lib/utils/tar.js')
-
+var tar = require('tar')
+var mkdirp = require('mkdirp')
var testdir = path.join(__dirname, path.basename(__filename, '.js'))
var packed = path.join(testdir, 'packed')
@@ -87,10 +87,13 @@ test('bundled-transitive-deps', function (t) {
var tarball = stdout.trim()
t.comment(stderr.trim())
t.is(code, 0, 'pack successful')
- tar.unpack(path.join(testdir, tarball), packed, thenCheckContents)
- }
- function thenCheckContents (err) {
- t.ifError(err, 'unpack successful')
+ mkdirp.sync(packed)
+ tar.extract({
+ file: path.join(testdir, tarball),
+ cwd: packed,
+ strip: 1,
+ sync: true
+ })
var transitivePackedDep = path.join(packed, 'node_modules', 'b')
exists(t, transitivePackedDep)
var nestedScopedDep = path.join(packed, 'node_modules', '@c', 'd', 'node_modules', 'e')
diff --git a/deps/npm/test/tap/config-basic.js b/deps/npm/test/tap/config-basic.js
index cabfa24396..b8102da90c 100644
--- a/deps/npm/test/tap/config-basic.js
+++ b/deps/npm/test/tap/config-basic.js
@@ -5,7 +5,6 @@ var path = require('path')
var projectData = {
'save-prefix': '~',
- 'proprietary-attribs': false,
'legacy-bundling': true
}
diff --git a/deps/npm/test/tap/config-builtin.js b/deps/npm/test/tap/config-builtin.js
index cb1e4eb20f..53d00a31a7 100644
--- a/deps/npm/test/tap/config-builtin.js
+++ b/deps/npm/test/tap/config-builtin.js
@@ -16,7 +16,6 @@ var cli = { foo: 'bar', heading: 'foo', 'git-tag-version': false }
var projectData = {
'save-prefix': '~',
- 'proprietary-attribs': false,
'legacy-bundling': true
}
diff --git a/deps/npm/test/tap/config-list.js b/deps/npm/test/tap/config-list.js
index 1c42b64c2e..b06dc154b2 100644
--- a/deps/npm/test/tap/config-list.js
+++ b/deps/npm/test/tap/config-list.js
@@ -8,28 +8,54 @@ var common = require('../common-tap.js')
var pkg = path.resolve(__dirname, 'config-list')
var opts = { cwd: pkg }
var npmrc = path.resolve(pkg, '.npmrc')
+var npmrcContents = `
+_private=private;
+registry/:_pwd=pwd;
+foo=1234
+`
test('setup', function (t) {
rimraf.sync(pkg)
mkdirp.sync(pkg)
- t.end()
-})
-test('config list includes project config', function (t) {
// Write per-project conf file
- fs.writeFileSync(npmrc, 'foo=1234', 'utf8')
+ fs.writeFileSync(npmrc, npmrcContents, 'utf8')
// Create empty package.json to indicate project root
fs.writeFileSync(path.resolve(pkg, 'package.json'), '{}', 'utf8')
+ t.end()
+})
+test('config list includes project config', function (t) {
common.npm(
['config', 'list'],
opts,
function (err, code, stdout, stderr) {
t.ifError(err)
t.equal(stderr, '', 'stderr is empty')
+
var expected = '; project config ' + npmrc + '\nfoo = "1234"'
t.match(stdout, expected, 'contains project config')
+ t.notMatch(stdout, '_private', 'excludes private config')
+ t.notMatch(stdout, '_pwd', 'excludes private segmented config')
+ t.end()
+ }
+ )
+})
+
+test('config list --json outputs json', function (t) {
+ common.npm(
+ ['config', 'list', '--json'],
+ opts,
+ function (err, code, stdout, stderr) {
+ t.ifError(err)
+ t.equal(stderr, '', 'stderr is empty')
+
+ var json = JSON.parse(stdout)
+ t.equal(json.foo, '1234', 'contains project config')
+ t.equal(json.argv, undefined, 'excludes argv')
+ t.equal(json._private, undefined, 'excludes private config')
+ t.equal(json['registry/:_pwd'], undefined, 'excludes private config')
t.end()
}
)
diff --git a/deps/npm/test/tap/config-save.js b/deps/npm/test/tap/config-save.js
index 903bac7ae3..a7f85d6015 100644
--- a/deps/npm/test/tap/config-save.js
+++ b/deps/npm/test/tap/config-save.js
@@ -12,7 +12,6 @@ var expectConf = [
'init.author.email = i@izs.me',
'init.author.url = http://blog.izs.me/',
'init.version = 1.2.3',
- 'proprietary-attribs = false',
'npm:publishtest = true',
'_npmjs.org:couch = https://admin:password@localhost:5984/registry',
'npm-www:nocache = 1',
@@ -38,7 +37,6 @@ var expectFile = [
'init.author.email = i@izs.me',
'init.author.url = http://blog.izs.me/',
'init.version = 1.2.3',
- 'proprietary-attribs = false',
'npm:publishtest = true',
'_npmjs.org:couch = https://admin:password@localhost:5984/registry',
'npm-www:nocache = 1',
diff --git a/deps/npm/test/tap/files-and-ignores.js b/deps/npm/test/tap/files-and-ignores.js
index d86b17acfa..6d44f3ea35 100644
--- a/deps/npm/test/tap/files-and-ignores.js
+++ b/deps/npm/test/tap/files-and-ignores.js
@@ -6,7 +6,6 @@ var rimraf = require('rimraf')
var mkdirp = require('mkdirp')
var fs = require('graceful-fs')
var tar = require('tar')
-var zlib = require('zlib')
var basepath = path.resolve(__dirname, path.basename(__filename, '.js'))
var fixturepath = path.resolve(basepath, 'npm-test-files')
var targetpath = path.resolve(basepath, 'target')
@@ -210,14 +209,14 @@ test('.npmignore should always be overridden by files array', function (t) {
include: File(''),
ignore: File(''),
sub: Dir({
- include: File('')
+ included: File('')
})
})
)
withFixture(t, fixture, function (done) {
t.notOk(fileExists('ignore'), 'toplevel file excluded')
t.ok(fileExists('include'), 'unignored file included')
- t.ok(fileExists('sub/include'), 'nested file included')
+ t.ok(fileExists('sub/included'), 'nested file included')
done()
})
})
@@ -384,7 +383,55 @@ test('include main file', function (t) {
})
})
-test('certain files ignored unconditionally', function (t) {
+test('certain files ignored by default', function (t) {
+ var fixture = new Tacks(
+ Dir({
+ 'package.json': File({
+ name: 'npm-test-files',
+ version: '1.2.5'
+ }),
+ '.git': Dir({foo: File('')}),
+ '.svn': Dir({foo: File('')}),
+ 'CVS': Dir({foo: File('')}),
+ '.hg': Dir({foo: File('')}),
+ '.lock-wscript': File(''),
+ '.wafpickle-0': File(''),
+ '.wafpickle-5': File(''),
+ '.wafpickle-50': File(''),
+ 'build': Dir({'config.gypi': File('')}),
+ 'npm-debug.log': File(''),
+ '.npmrc': File(''),
+ '.foo.swp': File(''),
+ '.DS_Store': Dir({foo: File('')}),
+ '._ohno': File(''),
+ '._ohnoes': Dir({noes: File('')}),
+ 'foo.orig': File(''),
+ 'package-lock.json': File('')
+ })
+ )
+ withFixture(t, fixture, function (done) {
+ t.notOk(fileExists('.git'), '.git not included')
+ t.notOk(fileExists('.svn'), '.svn not included')
+ t.notOk(fileExists('CVS'), 'CVS not included')
+ t.notOk(fileExists('.hg'), '.hg not included')
+ t.notOk(fileExists('.lock-wscript'), '.lock-wscript not included')
+ t.notOk(fileExists('.wafpickle-0'), '.wafpickle-0 not included')
+ t.notOk(fileExists('.wafpickle-5'), '.wafpickle-5 not included')
+ t.notOk(fileExists('.wafpickle-50'), '.wafpickle-50 not included')
+ t.notOk(fileExists('build/config.gypi'), 'build/config.gypi not included')
+ t.notOk(fileExists('npm-debug.log'), 'npm-debug.log not included')
+ t.notOk(fileExists('.npmrc'), '.npmrc not included')
+ t.notOk(fileExists('.foo.swp'), '.foo.swp not included')
+ t.notOk(fileExists('.DS_Store'), '.DS_Store not included')
+ t.notOk(fileExists('._ohno'), '._ohno not included')
+ t.notOk(fileExists('._ohnoes'), '._ohnoes not included')
+ t.notOk(fileExists('foo.orig'), 'foo.orig not included')
+ t.notOk(fileExists('package-lock.json'), 'package-lock.json not included')
+ done()
+ })
+})
+
+test('default-ignored files can be explicitly included', function (t) {
var fixture = new Tacks(
Dir({
'package.json': File({
@@ -405,6 +452,7 @@ test('certain files ignored unconditionally', function (t) {
'.foo.swp',
'.DS_Store',
'._ohno',
+ '._ohnoes',
'foo.orig',
'package-lock.json'
]
@@ -429,23 +477,23 @@ test('certain files ignored unconditionally', function (t) {
})
)
withFixture(t, fixture, function (done) {
- t.notOk(fileExists('.git'), '.git not included')
- t.notOk(fileExists('.svn'), '.svn not included')
- t.notOk(fileExists('CVS'), 'CVS not included')
- t.notOk(fileExists('.hg'), '.hg not included')
- t.notOk(fileExists('.lock-wscript'), '.lock-wscript not included')
- t.notOk(fileExists('.wafpickle-0'), '.wafpickle-0 not included')
- t.notOk(fileExists('.wafpickle-5'), '.wafpickle-5 not included')
- t.notOk(fileExists('.wafpickle-50'), '.wafpickle-50 not included')
- t.notOk(fileExists('build/config.gypi'), 'build/config.gypi not included')
- t.notOk(fileExists('npm-debug.log'), 'npm-debug.log not included')
- t.notOk(fileExists('.npmrc'), '.npmrc not included')
- t.notOk(fileExists('.foo.swp'), '.foo.swp not included')
- t.notOk(fileExists('.DS_Store'), '.DS_Store not included')
- t.notOk(fileExists('._ohno'), '._ohno not included')
- t.notOk(fileExists('._ohnoes'), '._ohnoes not included')
- t.notOk(fileExists('foo.orig'), 'foo.orig not included')
- t.notOk(fileExists('package-lock.json'), 'package-lock.json not included')
+ t.ok(fileExists('.git'), '.git included')
+ t.ok(fileExists('.svn'), '.svn included')
+ t.ok(fileExists('CVS'), 'CVS included')
+ t.ok(fileExists('.hg'), '.hg included')
+ t.ok(fileExists('.lock-wscript'), '.lock-wscript included')
+ t.ok(fileExists('.wafpickle-0'), '.wafpickle-0 included')
+ t.ok(fileExists('.wafpickle-5'), '.wafpickle-5 included')
+ t.ok(fileExists('.wafpickle-50'), '.wafpickle-50 included')
+ t.ok(fileExists('build/config.gypi'), 'build/config.gypi included')
+ t.ok(fileExists('npm-debug.log'), 'npm-debug.log included')
+ t.ok(fileExists('.npmrc'), '.npmrc included')
+ t.ok(fileExists('.foo.swp'), '.foo.swp included')
+ t.ok(fileExists('.DS_Store'), '.DS_Store included')
+ t.ok(fileExists('._ohno'), '._ohno included')
+ t.ok(fileExists('._ohnoes'), '._ohnoes included')
+ t.ok(fileExists('foo.orig'), 'foo.orig included')
+ t.ok(fileExists('package-lock.json'), 'package-lock.json included')
done()
})
})
@@ -609,10 +657,11 @@ function withFixture (t, fixture, tester) {
function extractTarball (cb) {
// Unpack to disk so case-insensitive filesystems are consistent
- fs.createReadStream(path.join(basepath, 'npm-test-files-1.2.5.tgz'))
- .pipe(zlib.Unzip())
- .on('error', cb)
- .pipe(tar.Extract(targetpath))
- .on('error', cb)
- .on('end', function () { cb() })
+ tar.extract({
+ file: basepath + '/npm-test-files-1.2.5.tgz',
+ cwd: targetpath,
+ sync: true
+ })
+
+ cb()
}
diff --git a/deps/npm/test/tap/git-npmignore.js b/deps/npm/test/tap/git-npmignore.js
index 819e0a6285..1fe2ca24e6 100644
--- a/deps/npm/test/tap/git-npmignore.js
+++ b/deps/npm/test/tap/git-npmignore.js
@@ -50,8 +50,7 @@ var modules = resolve(testdir, 'node_modules')
var installed = resolve(modules, 'gitch')
var expected = [
'a.js',
- 'package.json',
- '.npmignore'
+ 'package.json'
].sort()
var NPM_OPTS = {
diff --git a/deps/npm/test/tap/help.js b/deps/npm/test/tap/help.js
new file mode 100644
index 0000000000..0b8c22a7b8
--- /dev/null
+++ b/deps/npm/test/tap/help.js
@@ -0,0 +1,26 @@
+var test = require('tap').test
+var common = require('../common-tap')
+
+test('npm food', function (t) {
+ common.npm('food', {}, function (err, code, stdout, stderr) {
+ if (err) throw err
+ t.equal(code, 1, 'command ran with error')
+
+ t.has(stdout, 'Did you mean this?')
+
+ t.notOk(stderr, 'stderr should be empty')
+ t.end()
+ })
+})
+
+test('npm jet', function (t) {
+ common.npm('jet', {}, function (err, code, stdout, stderr) {
+ if (err) throw err
+ t.equal(code, 1, 'command ran with error')
+
+ t.has(stdout, 'Did you mean one of these?')
+
+ t.notOk(stderr, 'stderr should be empty')
+ t.end()
+ })
+})
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 71584b115a..7f60c73221 100644
--- a/deps/npm/test/tap/install-scoped-with-peer-dependency.js
+++ b/deps/npm/test/tap/install-scoped-with-peer-dependency.js
@@ -30,7 +30,7 @@ test('it should install peerDependencies in same tree level as the parent packag
common.npm(['install', '--loglevel=warn', './package'], EXEC_OPTS, function (err, code, stdout, stderr) {
t.ifError(err, 'install local package successful')
t.equal(code, 0, 'npm install exited with code')
- t.match(stderr, /npm WARN @scope[/]package@0[.]0[.]0 requires a peer of underscore@[*] but none was installed[.]\n/,
+ t.match(stderr, /npm WARN @scope[/]package@0[.]0[.]0 requires a peer of underscore@[*] but none is installed[.] You must install peer dependencies yourself[.]\n/,
'npm install warned about unresolved peer dep')
t.end()
diff --git a/deps/npm/test/tap/install-windows-newlines.js b/deps/npm/test/tap/install-windows-newlines.js
new file mode 100644
index 0000000000..56ef172a29
--- /dev/null
+++ b/deps/npm/test/tap/install-windows-newlines.js
@@ -0,0 +1,90 @@
+var fs = require('graceful-fs')
+var path = require('path')
+var existsSync = fs.existsSync || path.existsSync
+
+var mkdirp = require('mkdirp')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var common = require('../common-tap.js')
+
+var pkg = path.join(__dirname, 'install-windows-newlines')
+
+var EXEC_OPTS = { cwd: pkg, stdio: [0, 1, 2] }
+
+var json = {
+ name: 'install-windows-newlines',
+ description: 'fixture',
+ version: '0.0.0',
+ dependencies: {
+ 'cli-dependency': 'file:cli-dependency'
+ }
+}
+
+var dependency = {
+ name: 'cli-dependency',
+ description: 'fixture',
+ version: '0.0.0',
+ bin: {
+ hashbang: './hashbang.js',
+ nohashbang: './nohashbang.js'
+ }
+}
+
+test('setup', function (t) {
+ cleanup()
+ mkdirp.sync(path.join(pkg, 'cli-dependency'))
+ fs.writeFileSync(
+ path.join(pkg, 'cli-dependency', 'package.json'),
+ JSON.stringify(dependency, null, 2)
+ )
+ fs.writeFileSync(
+ path.join(pkg, 'cli-dependency', 'hashbang.js'),
+ '#!/usr/bin/env node\r\nconsole.log(\'Hello, world!\')\r\n'
+ )
+ fs.writeFileSync(
+ path.join(pkg, 'cli-dependency', 'nohashbang.js'),
+ '\'use strict\'\r\nconsole.log(\'Goodbye, world!\')\r\n'
+ )
+
+ mkdirp.sync(path.join(pkg, 'node_modules'))
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+
+ return common.npm(['install'], EXEC_OPTS).spread((code) => {
+ t.equal(code, 0, 'npm install did not raise error code')
+ t.ok(
+ existsSync(path.resolve(pkg, 'node_modules/.bin/hashbang')),
+ 'hashbang installed'
+ )
+ t.ok(
+ existsSync(path.resolve(pkg, 'node_modules/.bin/nohashbang')),
+ 'nohashbang installed'
+ )
+ t.notOk(
+ fs.readFileSync(
+ path.resolve(pkg, 'node_modules/cli-dependency/hashbang.js'),
+ 'utf8'
+ ).includes('\r\n'),
+ 'hashbang dependency cli newlines converted'
+ )
+ t.ok(
+ fs.readFileSync(
+ path.resolve(pkg, 'node_modules/cli-dependency/nohashbang.js'),
+ 'utf8'
+ ).includes('\r\n'),
+ 'nohashbang dependency cli newlines retained'
+ )
+ })
+})
+
+test('cleanup', function (t) {
+ cleanup()
+ t.end()
+})
+
+function cleanup () {
+ rimraf.sync(pkg)
+}
diff --git a/deps/npm/test/tap/lifecycle-INIT_CWD.js b/deps/npm/test/tap/lifecycle-INIT_CWD.js
new file mode 100644
index 0000000000..eec5c266ee
--- /dev/null
+++ b/deps/npm/test/tap/lifecycle-INIT_CWD.js
@@ -0,0 +1,58 @@
+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 = path.resolve(__dirname, 'lifecycle-initcwd')
+var subdir = path.resolve(pkg, 'subdir')
+
+var json = {
+ name: 'init-cwd',
+ version: '1.0.0',
+ scripts: {
+ initcwd: 'echo "$INIT_CWD"'
+ }
+}
+
+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)
+}
diff --git a/deps/npm/test/tap/lifecycle.js b/deps/npm/test/tap/lifecycle.js
deleted file mode 100644
index 1a98bf3db7..0000000000
--- a/deps/npm/test/tap/lifecycle.js
+++ /dev/null
@@ -1,44 +0,0 @@
-var test = require('tap').test
-var npm = require('../../')
-var lifecycle = require('../../lib/utils/lifecycle')
-
-test('lifecycle: make env correctly', function (t) {
- npm.load({enteente: Infinity}, function () {
- var env = lifecycle.makeEnv({}, null, process.env)
-
- t.equal('Infinity', env.npm_config_enteente)
- t.end()
- })
-})
-
-test('lifecycle : accepts wd for package that matches project\'s name', function (t) {
- npm.load({}, function () {
- var wd = '/opt/my-time/node_modules/time'
- var pkg = {name: 'time'}
-
- t.equal(lifecycle._incorrectWorkingDirectory(wd, pkg), false)
- t.end()
- })
-})
-
-test('lifecycle : accepts wd for package that doesn\'t match project\'s name', function (t) {
- npm.load({}, function () {
- var wd = '/opt/my-project/node_modules/time'
- var pkg = {name: 'time'}
-
- t.equal(lifecycle._incorrectWorkingDirectory(wd, pkg), false)
- t.end()
- })
-})
-
-test('lifecycle : rejects wd for ', function (t) {
- npm.load({}, function () {
- var wd = '/opt/my-time/node_modules/time/invalid'
- var pkg = {
- name: 'time'
- }
-
- t.equal(lifecycle._incorrectWorkingDirectory(wd, pkg), true)
- t.end()
- })
-})
diff --git a/deps/npm/test/tap/no-global-warns.js b/deps/npm/test/tap/no-global-warns.js
index cae62fff99..577b393122 100644
--- a/deps/npm/test/tap/no-global-warns.js
+++ b/deps/npm/test/tap/no-global-warns.js
@@ -14,7 +14,16 @@ var toInstall = path.join(base, 'to-install')
var config = 'prefix = ' + base
var configPath = path.join(base, '_npmrc')
-var OPTS = { }
+// use a clean environment for this test
+// otherwise local dev-time npm settings can throw it off
+var OPTS = {
+ env: Object.keys(process.env).filter(function (k) {
+ return !/^npm_config_/i.test(k)
+ }).reduce(function (set, k) {
+ set[k] = process.env[k]
+ return set
+ }, {})
+}
var installJSON = {
name: 'to-install',
@@ -43,6 +52,9 @@ test('no-global-warns', function (t) {
OPTS,
function (err, code, stdout, stderr) {
t.ifError(err, 'installed w/o error')
+ const preWarn = 'npm WARN You are using a pre-release version ' +
+ 'of node and things may not work as expected'
+ stderr = stderr.trim().replace(preWarn, '')
t.is(stderr, '', 'no warnings printed to stderr')
t.end()
})
diff --git a/deps/npm/test/tap/optional-metadep-rollback-collision.js b/deps/npm/test/tap/optional-metadep-rollback-collision.js
index 862e6e8c72..ce62e005ba 100644
--- a/deps/npm/test/tap/optional-metadep-rollback-collision.js
+++ b/deps/npm/test/tap/optional-metadep-rollback-collision.js
@@ -1,3 +1,4 @@
+'use strict'
var fs = require('graceful-fs')
var path = require('path')
@@ -12,7 +13,9 @@ var pkg = path.resolve(__dirname, 'optional-metadep-rollback-collision')
var deps = path.resolve(pkg, 'deps')
var opdep = path.resolve(pkg, 'node_modules', 'opdep')
var cache = path.resolve(pkg, 'cache')
-var pidfile = path.resolve(pkg, 'child.pid')
+var createServer = require('http').createServer
+var mr = require('npm-registry-mock')
+var serverPort = 27991
var json = {
name: 'optional-metadep-rollback-collision',
@@ -31,7 +34,7 @@ var d1 = {
preinstall: 'sleep 1'
},
dependencies: {
- foo: 'http://localhost:8080/'
+ foo: 'http://localhost:' + serverPort + '/'
}
}
@@ -43,9 +46,9 @@ var d2 = {
postinstall: 'node blart.js'
},
dependencies: {
- 'graceful-fs': '^3.0.2',
- mkdirp: '^0.5.0',
- rimraf: '^2.2.8'
+ 'request': '^0.9.0',
+ mkdirp: '^0.3.5',
+ wordwrap: '^0.0.2'
}
}
@@ -54,52 +57,12 @@ var opdep_json = {
version: '1.0.0',
description: 'To explode, of course!',
main: 'index.js',
- scripts: {
- preinstall: 'node bad-server.js'
- },
dependencies: {
d1: 'file:../d1',
d2: 'file:../d2'
}
}
-var badServer = function () { /*
-var createServer = require('http').createServer
-var spawn = require('child_process').spawn
-var fs = require('fs')
-var path = require('path')
-var pidfile = path.resolve(__dirname, '..', '..', 'child.pid')
-
-if (process.argv[2]) {
- console.log('ok')
- createServer(function (req, res) {
- setTimeout(function () {
- res.writeHead(404)
- res.end()
- }, 1000)
- this.close()
- }).listen(8080)
-} else {
- var child = spawn(
- process.execPath,
- [__filename, 'whatever'],
- {
- stdio: [0, 1, 2],
- detached: true
- }
- )
- child.unref()
-
- // kill any prior children, if existing.
- try {
- var pid = +fs.readFileSync(pidfile)
- process.kill(pid, 'SIGKILL')
- } catch (er) {}
-
- fs.writeFileSync(pidfile, child.pid + '\n')
-}
-*/ }.toString().split('\n').slice(1, -1).join('\n')
-
var blart = function () { /*
var rando = require('crypto').randomBytes
var resolve = require('path').resolve
@@ -153,8 +116,17 @@ mkdirp(BASEDIR, function go () {
}, 3 * 1000)
})
*/ }.toString().split('\n').slice(1, -1).join('\n')
+
+let badServer
+let mockServer
test('setup', function (t) {
cleanup()
+ badServer = createServer(function (req, res) {
+ setTimeout(function () {
+ res.writeHead(404)
+ res.end()
+ }, 1000)
+ }).listen(serverPort)
mkdirp.sync(pkg)
fs.writeFileSync(
@@ -180,17 +152,19 @@ test('setup', function (t) {
path.join(deps, 'opdep', 'package.json'),
JSON.stringify(opdep_json, null, 2)
)
- fs.writeFileSync(path.join(deps, 'opdep', 'bad-server.js'), badServer)
-
- t.end()
+ mr({ port: common.port }, function (er, server) {
+ mockServer = server
+ t.end()
+ })
})
-
test('go go test racer', function (t) {
common.npm(
[
'--prefix', pkg,
'--fetch-retries', '0',
- '--loglevel', 'silent',
+ '--loglevel', 'error',
+ '--no-progress',
+ '--registry', common.registry,
'--parseable',
'--cache', cache,
'install'
@@ -200,12 +174,13 @@ test('go go test racer', function (t) {
env: {
PATH: process.env.PATH,
Path: process.env.Path
- }
+ },
+ stdio: [ 0, 'pipe', 2 ]
},
function (er, code, stdout, stderr) {
t.ifError(er, 'install ran to completion without error')
t.is(code, 0, 'npm install exited with code 0')
- t.comment(stdout.trim())
+ t.comment(stderr.trim())
// stdout should be empty, because we only have one, optional, dep and
// if it fails we shouldn't try installing anything
t.equal(stdout, '')
@@ -223,16 +198,14 @@ test('verify results', function (t) {
})
test('cleanup', function (t) {
+ mockServer.close()
+ badServer.close()
cleanup()
t.end()
})
function cleanup () {
process.chdir(osenv.tmpdir())
- try {
- var pid = +fs.readFileSync(pidfile)
- process.kill(pid, 'SIGKILL')
- } catch (er) {}
rimraf.sync(pkg)
}
diff --git a/deps/npm/test/tap/ping.js b/deps/npm/test/tap/ping.js
index 13fc4bec9c..76d115a482 100644
--- a/deps/npm/test/tap/ping.js
+++ b/deps/npm/test/tap/ping.js
@@ -47,7 +47,7 @@ test('npm ping', function (t) {
t.ifError(err, 'no error output')
t.notOk(code, 'exited OK')
- t.same(JSON.parse(stdout), pingResponse)
+ t.same(stdout, 'Ping success: ' + JSON.stringify(pingResponse) + '\n')
t.end()
})
})
diff --git a/deps/npm/test/tap/prune-dev-dep-with-bins.js b/deps/npm/test/tap/prune-dev-dep-with-bins.js
new file mode 100644
index 0000000000..c22b6343ab
--- /dev/null
+++ b/deps/npm/test/tap/prune-dev-dep-with-bins.js
@@ -0,0 +1,104 @@
+'use strict'
+var fs = require('fs')
+var path = require('path')
+var test = require('tap').test
+var Tacks = require('tacks')
+var File = Tacks.File
+var Dir = Tacks.Dir
+var common = require('../common-tap.js')
+var testdir = path.join(__dirname, path.basename(__filename, '.js'))
+
+var fixture = new Tacks(
+ Dir({
+ node_modules: Dir({
+ 'yes': Dir({
+ 'package.json': File({
+ _requested: {
+ rawSpec: 'file:///mods/yes'
+ },
+ dependencies: {},
+ bin: {
+ 'yes': 'yes.js'
+ },
+ name: 'yes',
+ version: '1.0.0'
+ }),
+ 'yes.js': File('while (true) { console.log("y") }')
+ }),
+ '.bin': Dir({
+ // verbose, but needed for `read-cmd-shim` to properly identify which
+ // package this belongs to
+ 'yes': File(
+ '#!/bin/sh\n' +
+ 'basedir=$(dirname "$(echo "$0" | sed -e \'s,\\\\,/,g\')")\n' +
+ '\n' +
+ 'case `uname` in\n' +
+ ' *CYGWIN*) basedir=`cygpath -w "$basedir"`;;\n' +
+ 'esac\n' +
+ '\n' +
+ 'if [ -x "$basedir/node" ]; then\n' +
+ ' "$basedir/node" "$basedir/../yes/yes.js" "$@"\n' +
+ ' ret=$?\n' +
+ 'else\n' +
+ ' node "$basedir/../yes/yes.js" "$@"\n' +
+ ' ret=$?\n' +
+ 'fi\n' +
+ 'exit $ret\n'),
+ 'yes.cmd': File(
+ '@IF EXIST "%~dp0\node.exe" (\n' +
+ '"%~dp0\\node.exe" "%~dp0\\..\\yes\\yes.js" %*\n' +
+ ') ELSE (\n' +
+ '@SETLOCAL\n' +
+ '@SET PATHEXT=%PATHEXT:;.JS;=;%\n' +
+ 'node "%~dp0\..\yes\yes.js" %*')
+ })
+ }),
+ 'package.json': File({
+ name: 'test',
+ version: '1.0.0',
+ devDependencies: {
+ 'yes': 'file:///mods/yes'
+ }
+ })
+ })
+)
+
+function setup () {
+ cleanup()
+ fixture.create(testdir)
+}
+
+function cleanup () {
+ fixture.remove(testdir)
+}
+
+test('setup', function (t) {
+ setup()
+ t.end()
+})
+
+function readdir (dir) {
+ try {
+ return fs.readdirSync(dir)
+ } catch (ex) {
+ if (ex.code === 'ENOENT') return []
+ throw ex
+ }
+}
+
+test('prune cycle in dev deps', function (t) {
+ common.npm(['prune', '--production', '--json'], {cwd: testdir}, function (err, code, stdout, stderr) {
+ if (err) throw err
+ t.is(code, 0, 'prune finished successfully')
+ t.like(JSON.parse(stdout), {removed: [{name: 'yes'}]}, 'removed the right modules')
+ var dirs = readdir(testdir + '/node_modules').sort()
+ // bindirs are never removed, it's ok for them to remain after prune
+ t.same(dirs, ['.bin'])
+ t.end()
+ })
+})
+
+test('cleanup', function (t) {
+ cleanup()
+ t.end()
+})
diff --git a/deps/npm/test/tap/unit-deps-replaceModule.js b/deps/npm/test/tap/unit-deps-replaceModule.js
index d5f0fdbf89..15cce005d5 100644
--- a/deps/npm/test/tap/unit-deps-replaceModule.js
+++ b/deps/npm/test/tap/unit-deps-replaceModule.js
@@ -10,7 +10,7 @@ test('replaceModuleByName', function (t) {
var replaceModuleByName = require('../../lib/install/deps')._replaceModuleByName
var mods = []
for (var ii = 0; ii < 10; ++ii) {
- mods.push({package: {name: ii}, path: '/path/to/' + ii})
+ mods.push({package: {name: String(ii)}, path: '/path/to/' + ii})
}
var test = {}
@@ -21,7 +21,7 @@ test('replaceModuleByName', function (t) {
t.isDeeply(test.A, mods.slice(0, 4).concat(mods[7]), 'replacing a new module appends')
test.B = mods.slice(0, 4)
- var replacement = {package: {name: 1}, isReplacement: true}
+ var replacement = {package: {name: '1'}, isReplacement: true}
replaceModuleByName(test, 'B', replacement)
t.isDeeply(test.B, [mods[0], replacement, mods[2], mods[3]], 'replacing existing module swaps out for the new version')
@@ -39,7 +39,7 @@ test('replaceModuleByPath', function (t) {
var replaceModuleByPath = require('../../lib/install/deps')._replaceModuleByPath
var mods = []
for (var ii = 0; ii < 10; ++ii) {
- mods.push({package: {name: ii}, path: '/path/to/' + ii})
+ mods.push({package: {name: String(ii)}, path: '/path/to/' + ii})
}
var test = {}
@@ -50,7 +50,7 @@ test('replaceModuleByPath', function (t) {
t.isDeeply(test.A, mods.slice(0, 4).concat(mods[7]), 'replacing a new module appends')
test.B = mods.slice(0, 4)
- var replacement = {package: {name: 1}, isReplacement: true, path: '/path/to/1'}
+ var replacement = {package: {name: '1'}, isReplacement: true, path: '/path/to/1'}
replaceModuleByPath(test, 'B', replacement)
t.isDeeply(test.B, [mods[0], replacement, mods[2], mods[3]], 'replacing existing module swaps out for the new version')
diff --git a/deps/npm/test/tap/unsupported.js b/deps/npm/test/tap/unsupported.js
index b0dd8448aa..1a4ef61438 100644
--- a/deps/npm/test/tap/unsupported.js
+++ b/deps/npm/test/tap/unsupported.js
@@ -11,20 +11,22 @@ var versions = [
['v0.5.3', true, true],
['v0.6.17', true, true],
['v0.7.8', true, true],
- ['v0.8.28', false, true],
- ['v0.9.6', false, true],
- ['v0.10.48', false, true],
- ['v0.11.16', false, true],
- ['v0.12.9', false, true],
- ['v1.0.1', false, true],
- ['v1.6.0', false, true],
- ['v2.3.1', false, true],
- ['v3.0.0', false, true],
- ['v4.5.0', false, false],
- ['v5.7.1', false, false],
+ ['v0.8.28', true, true],
+ ['v0.9.6', true, true],
+ ['v0.10.48', true, true],
+ ['v0.11.16', true, true],
+ ['v0.12.9', true, true],
+ ['v1.0.1', true, true],
+ ['v1.6.0', true, true],
+ ['v2.3.1', true, true],
+ ['v3.0.0', true, true],
+ ['v4.5.0', true, true],
+ ['v4.8.4', false, false],
+ ['v5.7.1', false, true],
['v6.8.1', false, false],
['v7.0.0-beta23', false, false],
- ['v7.2.3', false, false]
+ ['v7.2.3', false, false],
+ ['v8.4.0', false, false]
]
test('versions', function (t) {
diff --git a/deps/npm/test/tap/verify-no-lifecycle-on-repo.js b/deps/npm/test/tap/verify-no-lifecycle-on-repo.js
index eedaa756b8..babdfb7dac 100644
--- a/deps/npm/test/tap/verify-no-lifecycle-on-repo.js
+++ b/deps/npm/test/tap/verify-no-lifecycle-on-repo.js
@@ -23,7 +23,11 @@ var baseJSON = {
var lastOpened
var npm = requireInject.installGlobally('../../lib/npm.js', {
- '../../lib/utils/lifecycle.js': function (pkg, stage, wd, unsafe, failOk, cb) {
+ '../../lib/utils/lifecycle.js': function (pkg, stage, wd, moreOpts, cb) {
+ if (typeof moreOpts === 'function') {
+ cb = moreOpts
+ }
+
cb(new Error("Shouldn't be calling lifecycle scripts"))
},
opener: function (url, options, cb) {
diff --git a/deps/npm/test/tap/version-commit-hooks-default.js b/deps/npm/test/tap/version-commit-hooks-default.js
new file mode 100644
index 0000000000..890aa55410
--- /dev/null
+++ b/deps/npm/test/tap/version-commit-hooks-default.js
@@ -0,0 +1,13 @@
+var test = require('tap').test
+var npm = require('../../')
+
+// This test has to be separate from `version-commit-hooks.js`, due to
+// mutual exclusivity with the first test in that file. Initial configuration
+// seems to only work as expected for defaults during the first `npm.load()`.
+
+test('npm config `commit-hooks` defaults to `true`', function (t) {
+ npm.load({}, function () {
+ t.same(npm.config.get('commit-hooks'), true)
+ t.end()
+ })
+})
diff --git a/deps/npm/test/tap/version-commit-hooks.js b/deps/npm/test/tap/version-commit-hooks.js
new file mode 100644
index 0000000000..4791fc3f3c
--- /dev/null
+++ b/deps/npm/test/tap/version-commit-hooks.js
@@ -0,0 +1,64 @@
+var fs = require('graceful-fs')
+var path = require('path')
+var osenv = require('osenv')
+var mkdirp = require('mkdirp')
+var rimraf = require('rimraf')
+var pkg = path.resolve(__dirname, 'version-commit-hooks')
+
+var test = require('tap').test
+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)
+
+ npm.load({ prefix: pkg, userconfig: npmrc }, function (err, conf) {
+ if (err) {
+ t.fail('error loading npm')
+ }
+ t.same(npm.config.get('commit-hooks'), false)
+ t.end()
+ })
+})
+
+test('npm version <semver> with commit-hooks disabled', function (t) {
+ npm.load({}, function () {
+ npm.config.set('commit-hooks', false)
+
+ var version = require('../../lib/version')
+ var args1 = version.buildCommitArgs()
+ var args2 = version.buildCommitArgs([ 'commit' ])
+ var args3 = version.buildCommitArgs([ 'commit', '-m', 'some commit message' ])
+
+ t.same(args1, [ 'commit', '-n' ])
+ t.same(args2, [ 'commit', '-n' ])
+ t.same(args3, [ 'commit', '-m', 'some commit message', '-n' ])
+ t.end()
+ })
+})
+
+test('npm version <semver> with commit-hooks enabled (default)', function (t) {
+ npm.load({}, function () {
+ npm.config.set('commit-hooks', true)
+
+ var version = require('../../lib/version')
+ var args1 = version.buildCommitArgs()
+ var args2 = version.buildCommitArgs([ 'commit' ])
+ var args3 = version.buildCommitArgs([ 'commit', '-m', 'some commit message' ])
+
+ t.same(args1, [ 'commit' ])
+ t.same(args2, [ 'commit' ])
+ t.same(args3, [ 'commit', '-m', 'some commit message' ])
+ t.end()
+ })
+})
+
+test('cleanup', function (t) {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+ t.end()
+})