diff options
31 files changed, 185 insertions, 527 deletions
diff --git a/test/common-tap.js b/test/common-tap.js index 3a9f9d4d2..03ffc05cf 100644 --- a/test/common-tap.js +++ b/test/common-tap.js @@ -26,6 +26,7 @@ process.env.npm_config_userconfig = exports.npm_config_userconfig = path.join(__ process.env.npm_config_globalconfig = exports.npm_config_globalconfig = path.join(__dirname, 'fixtures', 'config', 'globalconfig') process.env.npm_config_global_style = 'false' process.env.npm_config_legacy_bundling = 'false' +process.env.npm_config_fetch_retries = '0' process.env.random_env_var = 'foo' // suppress warnings about using a prerelease version of node process.env.npm_config_node_version = process.version.replace(/-.*$/, '') diff --git a/test/tap/404-parent.js b/test/tap/404-parent.js index a8bd95163..4321f7d82 100644 --- a/test/tap/404-parent.js +++ b/test/tap/404-parent.js @@ -40,14 +40,14 @@ function setup () { process.chdir(pkg) } -function plugin (server) { - server.get('/test-npm-404-parent-test') - .reply(404, {'error': 'version not found'}) -} - function performInstall (cb) { - mr({port: common.port, plugin: plugin}, function (er, s) { // create mock registry. - npm.load({registry: common.registry}, function () { + mr({port: common.port}, function (er, s) { // create mock registry. + s.get('/test-npm-404-parent-test') + .many().reply(404, {'error': 'version not found'}) + npm.load({ + registry: common.registry + }, function () { + npm.config.set('fetch-retries', 0) var pwd = process.cwd() process.chdir(pkg) npm.commands.install([], function (err) { diff --git a/test/tap/404-private-registry-scoped.js b/test/tap/404-private-registry-scoped.js index 0f0cbc4ec..48889376c 100644 --- a/test/tap/404-private-registry-scoped.js +++ b/test/tap/404-private-registry-scoped.js @@ -42,7 +42,7 @@ test('scoped package names not mangled on error with non-root registry', functio t.ifError(er, 'correctly handled 404') t.equal(code, 1, 'exited with error') t.match(stderr, /E404/, 'should notify the sort of error as a 404') - t.match(stderr, /@scope\/foo/, 'should have package name in error') + t.match(stderr, /@scope(?:%2f|\/)foo/, 'should have package name in error') server.done() t.end() } diff --git a/test/tap/add-local.js b/test/tap/add-local.js deleted file mode 100644 index 8f07012e0..000000000 --- a/test/tap/add-local.js +++ /dev/null @@ -1,137 +0,0 @@ -var path = require('path') -var test = require('tap').test -var mkdirp = require('mkdirp') -var osenv = require('osenv') -var rimraf = require('rimraf') -var requireInject = require('require-inject') - -var pkg = path.join(__dirname, '/local-dir') -var cache = path.join(pkg, '/cache') -var tmp = path.join(pkg, '/tmp') -var prefix = path.join(pkg, '/prefix') - -var Tacks = require('tacks') -var File = Tacks.File -var Dir = Tacks.Dir - -test('addLocal directory race on Windows', function (t) { - setup() - var p = { - name: 'test', - version: '1.0.0', - type: 'directory', - fetchSpec: pkg - } - var fixture = new Tacks( - Dir({ - 'package.json': File(p) - }) - ) - var addLocal = requireInject('../../lib/cache/add-local', { - '../../lib/npm.js': { - cache: cache, - tmp: tmp, - prefix: prefix - }, - '../../lib/cache/get-stat': function (cb) { - cb(null, {}) - }, - chownr: function (x, y, z, cb) { - cb(new Error('chownr should never have been called')) - }, - '../../lib/cache/add-local-tarball.js': function (tgz, data, shasum, cb) { - cb(null) - }, - '../../lib/utils/lifecycle.js': function (data, cycle, p, cb) { - cb(null) - }, - '../../lib/utils/tar.js': { - pack: function (tgz, p, data, cb) { - cb(null) - } - }, - 'sha': { - get: function (tgz, cb) { - cb(null, 'deadbeef') - } - } - }) - - fixture.create(pkg) - addLocal(p, null, function (err) { - t.ifErr(err, 'addLocal completed without error') - t.done() - }) -}) - -test('addLocal temporary cache file race', function (t) { - // See https://github.com/npm/npm/issues/12669 - setup() - var p = { - name: 'test', - version: '1.0.0', - type: 'directory', - fetchSpec: pkg - } - var fixture = new Tacks( - Dir({ - 'package.json': File(p) - }) - ) - var addLocal = requireInject('../../lib/cache/add-local', { - // basic setup/mock stuff - '../../lib/npm.js': { - cache: cache, - tmp: tmp, - prefix: prefix - }, - '../../lib/cache/add-local-tarball.js': function (tgz, data, shasum, cb) { - cb(null) - }, - '../../lib/utils/lifecycle.js': function (data, cycle, p, cb) { - cb(null) - }, - '../../lib/utils/tar.js': { - pack: function (tgz, p, data, cb) { - cb(null) - } - }, - 'sha': { - get: function (tgz, cb) { - cb(null, 'deadbeef') - } - }, - - // Test-specific mocked values to simulate race. - '../../lib/cache/get-stat': function (cb) { - cb(null, {uid: 1, gid: 2}) - }, - chownr: function (x, y, z, cb) { - // Simulate a race condition between `tar.pack` and `chownr` - // where the latter will return `ENOENT` when an async process - // removes a file that its internal `fs.readdir` listed. - cb({code: 'ENOENT'}) - } - }) - - fixture.create(pkg) - addLocal(p, null, function (err) { - t.ifErr(err, 'addLocal completed without error') - t.done() - }) -}) - -test('cleanup', function (t) { - cleanup() - t.done() -}) - -function setup () { - mkdirp.sync(cache) - mkdirp.sync(tmp) -} - -function cleanup () { - process.chdir(osenv.tmpdir()) - rimraf.sync(pkg) -} diff --git a/test/tap/add-named-update-protocol-port.js b/test/tap/add-named-update-protocol-port.js index 78130e2f8..37851e106 100644 --- a/test/tap/add-named-update-protocol-port.js +++ b/test/tap/add-named-update-protocol-port.js @@ -72,6 +72,7 @@ test('tarball paths should update port if updating protocol', function (t) { {}, function (er, code, stdout, stderr) { if (er) { throw er } + t.equal(stderr, '', 'no error output') t.equal(code, 0, 'addNamed worked') server1.done() t.end() diff --git a/test/tap/add-remote-git-fake-windows.js b/test/tap/add-remote-git-fake-windows.js deleted file mode 100644 index 24175c545..000000000 --- a/test/tap/add-remote-git-fake-windows.js +++ /dev/null @@ -1,132 +0,0 @@ -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 = resolve(__dirname, 'add-remote-git') -var repo = resolve(__dirname, 'add-remote-git-repo') - -var daemon -var daemonPID -var git - -var pjParent = JSON.stringify({ - name: 'parent', - version: '1.2.3', - dependencies: { - child: 'git://localhost:1234/child.git' - } -}, null, 2) + '\n' - -var pjChild = JSON.stringify({ - name: 'child', - version: '1.0.3' -}, null, 2) + '\n' - -test('setup', function (t) { - bootstrap() - setup(function (er, r) { - if (er) { - throw er - } - - if (!er) { - daemon = r[r.length - 2] - daemonPID = r[r.length - 1] - } - - t.end() - }) -}) - -test('install from repo on \'Windows\'', function (t) { - // before we confuse everything by switching the platform - require('../../lib/install.js') - require('../../lib/unbuild.js') - process.platform = 'win32' - 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() - }) - process.kill(daemonPID) -}) - -function bootstrap () { - rimraf.sync(pkg) - mkdirp.sync(pkg) - fs.writeFileSync(resolve(pkg, 'package.json'), pjParent) -} - -function setup (cb) { - rimraf.sync(repo) - mkdirp.sync(repo) - fs.writeFileSync(resolve(repo, 'package.json'), pjChild) - npm.load({ registry: common.registry, loglevel: 'silent' }, function () { - // some really cheesy monkeypatching - require('module')._cache[require.resolve('which')] = { - exports: function (_, cb) { cb() } - } - git = require('../../lib/utils/git.js') - - function startDaemon (cb) { - // start git server - var d = git.spawn( - [ - 'daemon', - '--verbose', - '--listen=localhost', - '--export-all', - '--base-path=.', - '--reuseaddr', - '--port=1234' - ], - { - cwd: pkg, - env: process.env, - stdio: ['pipe', 'pipe', 'pipe'] - } - ) - d.stderr.on('data', childFinder) - - function childFinder (c) { - var cpid = c.toString().match(/^\[(\d+)\]/) - if (cpid[1]) { - this.removeListener('data', childFinder) - cb(null, [d, cpid[1]]) - } - } - } - - common.makeGitRepo({ - path: repo, - commands: [ - git.chainableExec( - ['clone', '--bare', repo, 'child.git'], - { cwd: pkg, env: process.env } - ), - startDaemon - ] - }, cb) - }) -} - -function cleanup () { - process.chdir(osenv.tmpdir()) - rimraf.sync(repo) - rimraf.sync(pkg) -} diff --git a/test/tap/add-remote-git-file.js b/test/tap/add-remote-git-file.js index eff4a62e2..546a73ff6 100644 --- a/test/tap/add-remote-git-file.js +++ b/test/tap/add-remote-git-file.js @@ -1,3 +1,5 @@ +'use strict' + var fs = require('fs') var resolve = require('path').resolve var url = require('url') @@ -32,16 +34,13 @@ test('setup', function (t) { test('cache from repo', function (t) { process.chdir(pkg) - var addRemoteGit = require('../../lib/cache/add-remote-git.js') - addRemoteGit(cloneURL, function (er, data) { - t.ifError(er, 'cached via git') + return npm.commands.cache.add(cloneURL).then((data) => { t.equal( - url.parse(data._resolved).protocol, + url.parse(data.manifest._resolved).protocol, 'git+file:', 'npm didn\'t go crazy adding git+git+git+git' ) - - t.end() + t.equal(data.manifest._spec.type, 'git', 'cached git') }) }) diff --git a/test/tap/add-remote-git-shrinkwrap.js b/test/tap/add-remote-git-shrinkwrap.js index b79405c2b..e63bf3ee9 100644 --- a/test/tap/add-remote-git-shrinkwrap.js +++ b/test/tap/add-remote-git-shrinkwrap.js @@ -66,12 +66,6 @@ test('shrinkwrap gets correct _from and _resolved (#7121)', function (t) { t.equal(stderr.trim(), '', 'no error output on successful shrinkwrap') var shrinkwrap = require(resolve(pkg, 'npm-shrinkwrap.json')) - t.equal( - shrinkwrap.dependencies.child.from, - 'git://localhost:1234/child.git#master', - 'npm shrinkwrapped from correctly' - ) - git.whichAndExec( ['rev-list', '-n1', 'master'], { cwd: repo, env: process.env }, diff --git a/test/tap/anon-cli-metrics.js b/test/tap/anon-cli-metrics.js index 44db5a036..16b9c380f 100644 --- a/test/tap/anon-cli-metrics.js +++ b/test/tap/anon-cli-metrics.js @@ -145,4 +145,3 @@ test('cleanup', function (t) { cleanup() t.done() }) - diff --git a/test/tap/bearer-token-check.js b/test/tap/bearer-token-check.js index 9871b2e75..42c8f313e 100644 --- a/test/tap/bearer-token-check.js +++ b/test/tap/bearer-token-check.js @@ -98,7 +98,6 @@ var shrinkwrap = { dependencies: { '@scoped/underscore': { resolved: tarballURL, - from: '>=1.3.1 <2', version: '1.3.1' } } diff --git a/test/tap/bitbucket-https-url-with-creds-package.js b/test/tap/bitbucket-https-url-with-creds-package.js index 7268b5040..ce65f15b2 100644 --- a/test/tap/bitbucket-https-url-with-creds-package.js +++ b/test/tap/bitbucket-https-url-with-creds-package.js @@ -1,4 +1,7 @@ 'use strict' + +const BB = require('bluebird') + var fs = require('graceful-fs') var path = require('path') @@ -31,17 +34,16 @@ test('bitbucket-https-url-with-creds-package', function (t) { ] var npm = requireInject.installGlobally('../../lib/npm.js', { - 'child_process': { - 'execFile': function (cmd, args, options, cb) { - process.nextTick(function () { - if (args.indexOf('clone') === -1) return cb(null, '', '') + 'pacote/lib/util/git': { + 'revs': (repo, opts) => { + return BB.resolve().then(() => { var cloneUrl = cloneUrls.shift() if (cloneUrl) { - t.is(args[args.length - 2], cloneUrl[0], cloneUrl[1]) + t.is(repo, cloneUrl[0], cloneUrl[1]) } else { t.fail('too many attempts to clone') } - cb(new Error()) + throw new Error('git.revs mock fails on purpose') }) } } @@ -55,8 +57,8 @@ test('bitbucket-https-url-with-creds-package', function (t) { } npm.load(opts, function (er) { t.ifError(er, 'npm loaded without error') - npm.commands.install([], function (er) { - t.ok(er, 'mocked install failed as expected') + npm.commands.install([], function (err) { + t.match(err.message, /mock fails on purpose/, 'mocked install failed as expected') t.end() }) }) diff --git a/test/tap/bitbucket-https-url-with-creds.js b/test/tap/bitbucket-https-url-with-creds.js index 846e3ae74..ae87d8584 100644 --- a/test/tap/bitbucket-https-url-with-creds.js +++ b/test/tap/bitbucket-https-url-with-creds.js @@ -1,4 +1,7 @@ 'use strict' + +const BB = require('bluebird') + var fs = require('graceful-fs') var path = require('path') @@ -28,17 +31,16 @@ test('bitbucket-https-url-with-creds', function (t) { ] var npm = requireInject.installGlobally('../../lib/npm.js', { - 'child_process': { - 'execFile': function (cmd, args, options, cb) { - process.nextTick(function () { - if (args.indexOf('clone') === -1) return cb(null, '', '') + 'pacote/lib/util/git': { + 'revs': (repo, opts) => { + return BB.resolve().then(() => { var cloneUrl = cloneUrls.shift() if (cloneUrl) { - t.is(args[args.length - 2], cloneUrl[0], cloneUrl[1]) + t.is(repo, cloneUrl[0], cloneUrl[1]) } else { t.fail('too many attempts to clone') } - cb(new Error('execFile mock fails on purpose')) + throw new Error('git.revs mock fails on purpose') }) } } @@ -52,8 +54,8 @@ test('bitbucket-https-url-with-creds', function (t) { } npm.load(opts, function (er) { t.ifError(er, 'npm loaded without error') - npm.commands.install(['git+https://user:pass@bitbucket.org/foo/private.git'], function (er) { - t.ok(er, 'mocked install failed as expected') + npm.commands.install(['git+https://user:pass@bitbucket.org/foo/private.git'], function (err) { + t.match(err, /mock fails on purpose/, 'mocked install failed as expected') t.end() }) }) diff --git a/test/tap/bitbucket-shortcut-package.js b/test/tap/bitbucket-shortcut-package.js index b5fafb67e..8c418d37d 100644 --- a/test/tap/bitbucket-shortcut-package.js +++ b/test/tap/bitbucket-shortcut-package.js @@ -1,4 +1,7 @@ 'use strict' + +const BB = require('bluebird') + var fs = require('graceful-fs') var path = require('path') @@ -32,17 +35,16 @@ test('bitbucket-shortcut', function (t) { ] var npm = requireInject.installGlobally('../../lib/npm.js', { - 'child_process': { - 'execFile': function (cmd, args, options, cb) { - process.nextTick(function () { - if (args.indexOf('clone') === -1) return cb(null, '', '') + 'pacote/lib/util/git': { + 'revs': (repo, opts) => { + return BB.resolve().then(() => { var cloneUrl = cloneUrls.shift() if (cloneUrl) { - t.is(args[args.length - 2], cloneUrl[0], cloneUrl[1]) + t.is(repo, cloneUrl[0], cloneUrl[1]) } else { t.fail('too many attempts to clone') } - cb(new Error()) + throw new Error('git.revs mock fails on purpose') }) } } @@ -56,8 +58,8 @@ test('bitbucket-shortcut', function (t) { } npm.load(opts, function (er) { t.ifError(er, 'npm loaded without error') - npm.commands.install([], function (er) { - t.ok(er, 'mocked install failed as expected') + npm.commands.install([], function (err) { + t.match(err.message, /fails on purpose/, 'mocked install failed as expected') t.end() }) }) diff --git a/test/tap/bitbucket-shortcut.js b/test/tap/bitbucket-shortcut.js index 0781f6e9d..f8167fdd2 100644 --- a/test/tap/bitbucket-shortcut.js +++ b/test/tap/bitbucket-shortcut.js @@ -1,4 +1,7 @@ 'use strict' + +const BB = require('bluebird') + var fs = require('graceful-fs') var path = require('path') @@ -29,17 +32,16 @@ test('bitbucket-shortcut', function (t) { ] var npm = requireInject.installGlobally('../../lib/npm.js', { - 'child_process': { - 'execFile': function (cmd, args, options, cb) { - process.nextTick(function () { - if (args.indexOf('clone') === -1) return cb(null, '', '') + 'pacote/lib/util/git': { + 'revs': (repo, opts) => { + return BB.resolve().then(() => { var cloneUrl = cloneUrls.shift() if (cloneUrl) { - t.is(args[args.length - 2], cloneUrl[0], cloneUrl[1]) + t.is(repo, cloneUrl[0], cloneUrl[1]) } else { t.fail('too many attempts to clone') } - cb(new Error('execFile mock fails on purpose')) + throw new Error('git.revs mock fails on purpose') }) } } @@ -53,8 +55,8 @@ test('bitbucket-shortcut', function (t) { } npm.load(opts, function (er) { t.ifError(er, 'npm loaded without error') - npm.commands.install(['bitbucket:foo/private'], function (er) { - t.ok(er, 'mocked install failed as expected') + npm.commands.install(['bitbucket:foo/private'], function (err) { + t.match(err.message, /mock fails on purpose/, 'mocked install failed as expected') t.end() }) }) diff --git a/test/tap/cache-ls-filenames.js b/test/tap/cache-ls-filenames.js deleted file mode 100644 index 6dc1f8848..000000000 --- a/test/tap/cache-ls-filenames.js +++ /dev/null @@ -1,51 +0,0 @@ -var t = require('tap') -var path = require('path') -var fs = require('fs') -var mkdirp = require('mkdirp') -var rimraf = require('rimraf') -var spawn = require('child_process').spawn -var npm = require.resolve('../../bin/npm-cli.js') -var dir = path.resolve(__dirname, 'cache-ls-filenames') -var node = process.execPath - -t.test('setup', function (t) { - rimraf.sync(dir) - mkdirp.sync(dir + '/a/b/c/d') - for (var i = 0; i < 5; i++) { - fs.writeFileSync(dir + '/file-' + i, 'x\n') - fs.writeFileSync(dir + '/a/b/file-' + i, 'x\n') - } - t.end() -}) - -function test (t, args) { - var child = spawn(node, [npm, 'cache', 'ls', '--cache=' + dir].concat(args), {stdio: [0, 'pipe', 2]}) - var out = '' - child.stdout.on('data', function (c) { - out += c - }) - child.on('close', function (code, signal) { - t.equal(code, 0) - t.equal(signal, null) - out.trim().split(/[\n\r]+/).map(function (filename) { - return filename.replace(/^~/, process.env.HOME) - }).forEach(function (file) { - // verify that all exist - t.ok(fs.existsSync(file), 'exists: ' + file) - }) - t.end() - }) -} - -t.test('without path arg', function (t) { - test(t, []) -}) - -t.test('with path arg', function (t) { - test(t, ['a']) -}) - -t.test('cleanup', function (t) { - rimraf.sync(dir) - t.end() -}) diff --git a/test/tap/cache-shasum.js b/test/tap/cache-shasum.js deleted file mode 100644 index 40495c099..000000000 --- a/test/tap/cache-shasum.js +++ /dev/null @@ -1,50 +0,0 @@ -var test = require('tap').test -var path = require('path') -var rimraf = require('rimraf') -var mkdirp = require('mkdirp') -var mr = require('npm-registry-mock') -var common = require('../common-tap.js') -var cache = path.resolve(__dirname, 'cache-shasum') -var sha = require('sha') -var server - -test('mock reg', function (t) { - rimraf.sync(cache) - mkdirp.sync(cache) - mr({ port: common.port }, function (er, s) { - server = s - t.pass('ok') - t.end() - }) -}) - -test('npm cache add request', function (t) { - common.npm([ - 'cache', 'add', 'request@2.27.0', - '--cache=' + cache, - '--registry=' + common.registry, - '--loglevel=error' - ], {}, function (err, code, stdout) { - if (err) throw err - t.is(code, 0, 'cmd ran without error') - t.is(stdout, '', 'should not get data on stdout') - t.end() - }) -}) - -test('compare', function (t) { - var d = path.resolve(__dirname, 'cache-shasum/request') - var p = path.resolve(d, '2.27.0/package.tgz') - var r = require('./cache-shasum/localhost_1337/request/.cache.json') - var rshasum = r.versions['2.27.0'].dist.shasum - sha.get(p, function (er, pshasum) { - if (er) throw er - t.equal(pshasum, rshasum) - t.end() - }) -}) - -test('cleanup', function (t) { - server.close() - rimraf(cache, t.end) -}) diff --git a/test/tap/config-meta.js b/test/tap/config-meta.js index 168ab2a2e..c35d5d6c1 100644 --- a/test/tap/config-meta.js +++ b/test/tap/config-meta.js @@ -18,6 +18,7 @@ var DOC = {} var exceptions = [ path.resolve(lib, 'adduser.js'), path.resolve(lib, 'config.js'), + path.resolve(lib, 'config', 'pacote.js'), path.resolve(lib, 'publish.js'), path.resolve(lib, 'utils', 'lifecycle.js'), path.resolve(lib, 'utils', 'map-to-registry.js'), diff --git a/test/tap/doctor.js b/test/tap/doctor.js index 573bd9e23..bb1a5a945 100644 --- a/test/tap/doctor.js +++ b/test/tap/doctor.js @@ -1,45 +1,75 @@ 'use strict' -var http = require('http') -var which = require('which') -var mr = require('npm-registry-mock') -var test = require('tap').test -var common = require('../common-tap.js') -var npm = require('../../lib/npm.js') -var server -var node_url -var pingResponse = { + +const common = require('../common-tap.js') +const http = require('http') +const mr = require('npm-registry-mock') +const npm = require('../../lib/npm.js') +const path = require('path') +const Tacks = require('tacks') +const test = require('tap').test +const which = require('which') + +const Dir = Tacks.Dir +const File = Tacks.File + +const ROOT = path.join(__dirname, path.basename(__filename, '.js')) +const CACHE = path.join(ROOT, 'cache') +const TMP = path.join(ROOT, 'tmp') +const PREFIX = path.join(ROOT, 'global-prefix') +const PKG = path.join(ROOT, 'pkg') + +let server +let node_url +const pingResponse = { host: 'registry.npmjs.org', ok: true, username: null, peer: 'example.com' } -var npmResponse = { +const npmResponse = { + name: 'npm', 'dist-tags': {latest: '0.0.0'}, 'versions': { '0.0.0': { + name: 'npm', version: '0.0.0', + _shrinkwrap: null, + _hasShrinkwrap: false, dist: { - shasum: '', - tarball: '' + shasum: 'deadbeef', + tarball: 'https://reg.eh/npm-0.0.0.tgz' } } } } -test('setup', function (t) { - var port = common.port + 1 +test('setup', (t) => { + const port = common.port + 1 http.createServer(function (q, s) { s.end(JSON.stringify([{lts: true, version: '0.0.0'}])) this.close() - }).listen(port, function () { + }).listen(port, () => { node_url = 'http://localhost:' + port - mr({port: common.port}, function (e, s) { - t.ifError(e, 'registry mocked successfully') + mr({port: common.port}, (err, s) => { + t.ifError(err, 'registry mocked successfully') server = s server.get('/-/ping?write=true').reply(200, JSON.stringify(pingResponse)) server.get('/npm').reply(200, JSON.stringify(npmResponse)) - npm.load({registry: common.registry, loglevel: 'silent'}, function (e) { - t.ifError(e, 'npm loaded successfully') + const fixture = new Tacks(Dir({ + [path.basename(PKG)]: Dir({ + 'package.json': File({name: 'foo', version: '1.0.0'}) + }), + [path.basename(PREFIX)]: Dir({}) + })) + fixture.create(ROOT) + npm.load({ + registry: common.registry, + loglevel: 'silent', + cache: CACHE, + tmp: TMP, + prefix: PREFIX + }, (err) => { + t.ifError(err, 'npm loaded successfully') t.pass('all set up') t.done() }) @@ -58,7 +88,7 @@ test('npm doctor', function (t) { t.same(list[5][1], 'ok', 'Perms check on cached files') t.same(list[6][1], 'ok', 'Perms check on global node_modules') t.same(list[7][1], 'ok', 'Perms check on local node_modules') - t.same(list[8][1], 'ok', 'Checksum cached files') + t.match(list[8][1], /^verified \d+ tarballs?$/, 'Cache verified') which('git', function (e, resolvedPath) { t.ifError(e, 'git command is installed') t.same(list[4][1], resolvedPath, 'which git') diff --git a/test/tap/fetch-package-metadata.js b/test/tap/fetch-package-metadata.js index 51d85f791..2fc501369 100644 --- a/test/tap/fetch-package-metadata.js +++ b/test/tap/fetch-package-metadata.js @@ -3,6 +3,7 @@ var path = require('path') var mkdirp = require('mkdirp') var mr = require('npm-registry-mock') +var npa = require('npm-package-arg') var osenv = require('osenv') var rimraf = require('rimraf') var test = require('tap').test @@ -36,18 +37,11 @@ test('setup', function (t) { }) test('fetch-package-metadata provides resolved metadata', function (t) { - t.plan(5) + t.plan(4) var fetchPackageMetadata = require('../../lib/fetch-package-metadata') - var testPackage = { - raw: 'test-package@>=0.0.0', - scope: null, - name: 'test-package', - rawSpec: '>=0.0.0', - fetchSpec: '>=0.0.0', - type: 'range' - } + var testPackage = npa('test-package@>=0.0.0') mr({ port: common.port }, thenFetchMetadata) @@ -63,8 +57,7 @@ test('fetch-package-metadata provides resolved metadata', function (t) { t.ifError(err, 'fetched metadata') t.equals(pkg._resolved, 'http://localhost:1337/test-package/-/test-package-0.0.0.tgz', '_resolved') - t.equals(pkg._shasum, 'b0d32b6c45c259c578ba2003762b205131bdfbd1', '_shasum') - t.equals(pkg._from, 'test-package@>=0.0.0', '_from') + t.equals(pkg._integrity, 'sha1-sNMrbEXCWcV4uiADdisgUTG9+9E=', '_integrity') server.close() t.end() } diff --git a/test/tap/github-shortcut.js b/test/tap/github-shortcut.js index 068d46213..641d64f3b 100644 --- a/test/tap/github-shortcut.js +++ b/test/tap/github-shortcut.js @@ -1,18 +1,21 @@ 'use strict' -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 +const BB = require('bluebird') -var common = require('../common-tap.js') +const fs = require('graceful-fs') +const path = require('path') -var pkg = path.resolve(__dirname, 'github-shortcut') +const mkdirp = require('mkdirp') +const osenv = require('osenv') +const requireInject = require('require-inject') +const rimraf = require('rimraf') +const test = require('tap').test -var json = { +const common = require('../common-tap.js') + +const pkg = path.resolve(__dirname, 'github-shortcut') + +const json = { name: 'github-shortcut', version: '0.0.0' } @@ -23,38 +26,38 @@ test('setup', function (t) { }) test('github-shortcut', function (t) { - var cloneUrls = [ + 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'], ['ssh://git@github.com/foo/private.git', 'GitHub shortcuts try SSH third'] ] - var npm = requireInject.installGlobally('../../lib/npm.js', { - 'child_process': { - 'execFile': function (cmd, args, options, cb) { - process.nextTick(function () { - if (args.indexOf('clone') === -1) return cb(null, '', '') - var cloneUrl = cloneUrls.shift() + const npm = requireInject.installGlobally('../../lib/npm.js', { + 'pacote/lib/util/git': { + 'revs': (repo, opts) => { + return BB.resolve().then(() => { + const cloneUrl = cloneUrls.shift() if (cloneUrl) { - t.is(args[args.length - 2], cloneUrl[0], cloneUrl[1]) + t.is(repo, cloneUrl[0], cloneUrl[1]) } else { t.fail('too many attempts to clone') } - cb(new Error('execFile mock fails on purpose')) + throw new Error('git.revs mock fails on purpose') }) } } }) - var opts = { + const opts = { cache: path.resolve(pkg, 'cache'), prefix: pkg, registry: common.registry, loglevel: 'silent' } - t.plan(1 + cloneUrls.length) + t.plan(2 + cloneUrls.length) npm.load(opts, function (err) { t.ifError(err, 'npm loaded without error') - npm.commands.install(['foo/private'], function (er, result) { + npm.commands.install(['foo/private'], function (err, result) { + t.match(err.message, /mock fails on purpose/, 'mocked install failed as expected') t.end() }) }) diff --git a/test/tap/ls-depth-cli.js b/test/tap/ls-depth-cli.js index 87eafced2..8b0121426 100644 --- a/test/tap/ls-depth-cli.js +++ b/test/tap/ls-depth-cli.js @@ -120,16 +120,16 @@ test('npm ls --depth=0 --json', function (t) { function (er, c, out) { t.ifError(er, 'npm ls ran without issue') t.equal(c, 0, 'ls ran without raising error code') - t.has( - out, - /test-package-with-one-dep@0\.0\.0/, - 'output contains test-package-with-one-dep@0.0.0' - ) - t.doesNotHave( - out, - /test-package@0\.0\.0/, - 'output not contains test-package@0.0.0' - ) + t.deepEqual(JSON.parse(out), { + 'name': 'ls-depth-cli', + 'version': '0.0.0', + 'dependencies': { + 'test-package-with-one-dep': { + 'version': '0.0.0', + 'resolved': 'http://localhost:1337/test-package-with-one-dep/-/test-package-with-one-dep-0.0.0.tgz' + } + } + }) t.end() } ) @@ -144,16 +144,22 @@ test('npm ls --depth=Infinity --json', function (t) { function (er, c, out) { t.ifError(er, 'npm ls ran without issue') t.equal(c, 0, 'ls ran without raising error code') - t.has( - out, - /test-package-with-one-dep@0\.0\.0/, - 'output contains test-package-with-one-dep@0.0.0' - ) - t.has( - out, - /test-package@0\.0\.0/, - 'output contains test-package@0.0.0' - ) + t.deepEqual(JSON.parse(out), { + 'name': 'ls-depth-cli', + 'version': '0.0.0', + 'dependencies': { + 'test-package-with-one-dep': { + 'version': '0.0.0', + 'resolved': 'http://localhost:1337/test-package-with-one-dep/-/test-package-with-one-dep-0.0.0.tgz', + 'dependencies': { + 'test-package': { + 'version': '0.0.0', + 'resolved': 'http://localhost:1337/test-package/-/test-package-0.0.0.tgz' + } + } + } + } + }) t.end() } ) diff --git a/test/tap/peer-deps-toplevel.js b/test/tap/peer-deps-toplevel.js index a4384a7a5..e2285e769 100644 --- a/test/tap/peer-deps-toplevel.js +++ b/test/tap/peer-deps-toplevel.js @@ -35,12 +35,10 @@ var expected = { dependencies: { 'npm-test-peer-deps': { version: '0.0.0', - from: 'npm-test-peer-deps@*', resolved: common.registry + '/npm-test-peer-deps/-/npm-test-peer-deps-0.0.0.tgz', dependencies: { underscore: { version: '1.3.1', - from: 'underscore@1.3.1', resolved: common.registry + '/underscore/-/underscore-1.3.1.tgz' } } @@ -133,4 +131,3 @@ test('cleanup', function (t) { cleanup() t.done() }) - diff --git a/test/tap/prepublish.js b/test/tap/prepublish.js index ef55d79b3..18bfe5f22 100644 --- a/test/tap/prepublish.js +++ b/test/tap/prepublish.js @@ -59,7 +59,7 @@ test('prepublish deprecation warning on `npm pack`', function (t) { t.equal(code, 0, 'pack finished successfully') t.ifErr(err, 'pack finished successfully') - t.match(stderr, /`prepublish` scripts will run only for `npm publish`/) + t.match(stderr, /`prepublish` scripts are deprecated/) var c = stdout.trim() var regex = new RegExp('' + '> npm-test-prepublish@1.2.5 prepublish [^\\r\\n]+\\r?\\n' + diff --git a/test/tap/shrinkwrap-dev-dependency.js b/test/tap/shrinkwrap-dev-dependency.js index 332813462..20e2de1d2 100644 --- a/test/tap/shrinkwrap-dev-dependency.js +++ b/test/tap/shrinkwrap-dev-dependency.js @@ -22,13 +22,13 @@ var desired = { dependencies: { request: { version: '0.9.0', - from: 'request@0.9.0', - resolved: common.registry + '/request/-/request-0.9.0.tgz' + resolved: common.registry + '/request/-/request-0.9.0.tgz', + integrity: 'sha1-EEn1mm9GWI5tAwkh+7hMovDCcU4=' }, underscore: { version: '1.3.1', - from: 'underscore@1.3.1', - resolved: common.registry + '/underscore/-/underscore-1.3.1.tgz' + resolved: common.registry + '/underscore/-/underscore-1.3.1.tgz', + integrity: 'sha1-bLiq0Od+tdu/tUsivNhpcwnPlkE=' } } } diff --git a/test/tap/shrinkwrap-local-dependency.js b/test/tap/shrinkwrap-local-dependency.js index d3537756c..827a3960f 100644 --- a/test/tap/shrinkwrap-local-dependency.js +++ b/test/tap/shrinkwrap-local-dependency.js @@ -17,12 +17,10 @@ var shrinkwrap = { dependencies: { mod2: { version: '1.0.0', - from: path.join('mods', 'mod2'), resolved: 'file:' + path.join('mods', 'mod2'), dependencies: { mod1: { version: '1.0.0', - from: path.join('mods', 'mod1'), resolved: 'file:' + path.join('mods', 'mod1') } } diff --git a/test/tap/shrinkwrap-optional-dependency.js b/test/tap/shrinkwrap-optional-dependency.js index ee44b9a7b..0e9b3b202 100644 --- a/test/tap/shrinkwrap-optional-dependency.js +++ b/test/tap/shrinkwrap-optional-dependency.js @@ -63,8 +63,8 @@ var desired = { dependencies: { 'test-package': { version: '0.0.0', - from: 'test-package@0.0.0', - resolved: common.registry + '/test-package/-/test-package-0.0.0.tgz' + resolved: common.registry + '/test-package/-/test-package-0.0.0.tgz', + integrity: 'sha1-sNMrbEXCWcV4uiADdisgUTG9+9E=' } } } diff --git a/test/tap/shrinkwrap-optional-property.js b/test/tap/shrinkwrap-optional-property.js index 47f11a750..52deba863 100644 --- a/test/tap/shrinkwrap-optional-property.js +++ b/test/tap/shrinkwrap-optional-property.js @@ -53,14 +53,14 @@ var desired = { dependencies: { 'test-package': { version: '0.0.0', - from: 'test-package@0.0.0', - resolved: common.registry + '/test-package/-/test-package-0.0.0.tgz' + resolved: common.registry + '/test-package/-/test-package-0.0.0.tgz', + integrity: 'sha1-sNMrbEXCWcV4uiADdisgUTG9+9E=' }, 'underscore': { version: '1.3.3', - from: 'underscore@1.3.3', resolved: 'http://localhost:1337/underscore/-/underscore-1.3.3.tgz', - optional: true + optional: true, + integrity: 'sha1-R6xTaD2vgyv6lS4XdEF9pHgXrkI=' } } } diff --git a/test/tap/shrinkwrap-prod-dependency-also.js b/test/tap/shrinkwrap-prod-dependency-also.js index d3e86fcd6..4d18aedca 100644 --- a/test/tap/shrinkwrap-prod-dependency-also.js +++ b/test/tap/shrinkwrap-prod-dependency-also.js @@ -66,14 +66,14 @@ var desired = { dependencies: { request: { version: '0.9.0', - from: 'request@0.9.0', - resolved: common.registry + '/request/-/request-0.9.0.tgz' + resolved: common.registry + '/request/-/request-0.9.0.tgz', + integrity: 'sha1-EEn1mm9GWI5tAwkh+7hMovDCcU4=' }, underscore: { dev: true, version: '1.5.1', - from: 'underscore@1.5.1', - resolved: common.registry + '/underscore/-/underscore-1.5.1.tgz' + resolved: common.registry + '/underscore/-/underscore-1.5.1.tgz', + integrity: 'sha1-0r3oF9F2/63olKtxRY5oKhS4bck=' } } } diff --git a/test/tap/shrinkwrap-prod-dependency.js b/test/tap/shrinkwrap-prod-dependency.js index 57d6ecd3b..cdb6416cc 100644 --- a/test/tap/shrinkwrap-prod-dependency.js +++ b/test/tap/shrinkwrap-prod-dependency.js @@ -46,14 +46,14 @@ var desired = { dependencies: { request: { version: '0.9.0', - from: 'request@0.9.0', - resolved: common.registry + '/request/-/request-0.9.0.tgz' + resolved: common.registry + '/request/-/request-0.9.0.tgz', + integrity: 'sha1-EEn1mm9GWI5tAwkh+7hMovDCcU4=' }, underscore: { dev: true, version: '1.5.1', - from: 'underscore@1.5.1', - resolved: common.registry + '/underscore/-/underscore-1.5.1.tgz' + resolved: common.registry + '/underscore/-/underscore-1.5.1.tgz', + integrity: 'sha1-0r3oF9F2/63olKtxRY5oKhS4bck=' } } } diff --git a/test/tap/shrinkwrap-shared-dev-dependency.js b/test/tap/shrinkwrap-shared-dev-dependency.js index 0011f7b6f..1683dc2ad 100644 --- a/test/tap/shrinkwrap-shared-dev-dependency.js +++ b/test/tap/shrinkwrap-shared-dev-dependency.js @@ -46,14 +46,13 @@ var desired = { dependencies: { 'test-package-with-one-dep': { version: '0.0.0', - from: 'test-package-with-one-dep@0.0.0', - resolved: common.registry + - '/test-package-with-one-dep/-/test-package-with-one-dep-0.0.0.tgz' + resolved: common.registry + '/test-package-with-one-dep/-/test-package-with-one-dep-0.0.0.tgz', + integrity: 'sha1-JWwVltusKyPRImjatagCuy42Wsg=' }, 'test-package': { version: '0.0.0', - from: 'test-package@0.0.0', - resolved: common.registry + '/test-package/-/test-package-0.0.0.tgz' + resolved: common.registry + '/test-package/-/test-package-0.0.0.tgz', + integrity: 'sha1-sNMrbEXCWcV4uiADdisgUTG9+9E=' } } } diff --git a/test/tap/url-dependencies.js b/test/tap/url-dependencies.js index bc54da711..66b3e1a63 100644 --- a/test/tap/url-dependencies.js +++ b/test/tap/url-dependencies.js @@ -85,7 +85,7 @@ function setup () { function tarballWasFetched (output) { return output.indexOf( - 'http fetch GET ' + + 'GET 200 ' + common.registry + '/underscore/-/underscore-1.3.1.tgz' ) > -1 |