diff options
Diffstat (limited to 'deps/npm/test/tap')
-rw-r--r-- | deps/npm/test/tap/fetch-package-metadata.js | 76 | ||||
-rw-r--r-- | deps/npm/test/tap/files-and-ignores.js | 68 | ||||
-rw-r--r-- | deps/npm/test/tap/install-parse-error.js | 51 | ||||
-rw-r--r-- | deps/npm/test/tap/lifecycle-signal.js | 2 | ||||
-rw-r--r-- | deps/npm/test/tap/progress-config.js | 27 | ||||
-rw-r--r-- | deps/npm/test/tap/view.js | 18 |
6 files changed, 227 insertions, 15 deletions
diff --git a/deps/npm/test/tap/fetch-package-metadata.js b/deps/npm/test/tap/fetch-package-metadata.js new file mode 100644 index 0000000000..c7a7fcbe1a --- /dev/null +++ b/deps/npm/test/tap/fetch-package-metadata.js @@ -0,0 +1,76 @@ +'use strict' +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 npm = require('../../lib/npm.js') + +var pkg = path.resolve(__dirname, path.basename(__filename, '.js')) + +function setup (cb) { + cleanup() + mkdirp.sync(pkg) +} + +function cleanup () { + process.chdir(osenv.tmpdir()) + rimraf.sync(pkg) +} + +test('setup', function (t) { + setup() + process.chdir(pkg) + + var opts = { + cache: path.resolve(pkg, 'cache'), + registry: common.registry, + // important to make sure devDependencies don't get stripped + dev: true + } + npm.load(opts, t.end) +}) + +test('fetch-package-metadata provides resolved metadata', function (t) { + t.plan(5) + + var fetchPackageMetadata = require('../../lib/fetch-package-metadata') + + var testPackage = { + raw: 'test-package@>=0.0.0', + scope: null, + name: 'test-package', + rawSpec: '>=0.0.0', + spec: '>=0.0.0', + type: 'range' + } + + mr({ port: common.port }, thenFetchMetadata) + + var server + function thenFetchMetadata (err, s) { + t.ifError(err, 'setup mock registry') + server = s + + fetchPackageMetadata(testPackage, __dirname, thenVerifyMetadata) + } + + function thenVerifyMetadata (err, pkg) { + 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') + server.close() + t.end() + } +}) + +test('cleanup', function (t) { + cleanup() + t.end() +}) diff --git a/deps/npm/test/tap/files-and-ignores.js b/deps/npm/test/tap/files-and-ignores.js index 02371cfe3e..a8f4b222b8 100644 --- a/deps/npm/test/tap/files-and-ignores.js +++ b/deps/npm/test/tap/files-and-ignores.js @@ -5,10 +5,11 @@ var path = require('path') 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 modulepath = path.resolve(basepath, 'node_modules') -var installedpath = path.resolve(modulepath, 'npm-test-files') +var targetpath = path.resolve(basepath, 'target') var Tacks = require('tacks') var File = Tacks.File var Dir = Tacks.Dir @@ -459,6 +460,9 @@ test('certain files included unconditionally', function (t) { 'changelog', 'CHAngelog', 'ChangeLOG.txt', + 'history', + 'HistorY', + 'HistorY.md', 'license', 'licence', 'LICENSE', @@ -471,6 +475,9 @@ test('certain files included unconditionally', function (t) { 'changelog': File(''), 'CHAngelog': File(''), 'ChangeLOG.txt': File(''), + 'history': File(''), + 'HistorY': File(''), + 'HistorY.md': File(''), 'license': File(''), 'licence': File(''), 'LICENSE': File(''), @@ -494,6 +501,39 @@ test('certain files included unconditionally', function (t) { }) }) +test('unconditional inclusion does not capture modules', function (t) { + var fixture = new Tacks( + Dir({ + 'package.json': File({ + name: 'npm-test-files', + version: '1.2.5' + }), + 'node_modules': Dir({ + 'readme': Dir({ 'file': File('') }), + 'README': Dir({ 'file': File('') }), + 'licence': Dir({ 'file': File('') }), + 'license': Dir({ 'file': File('') }), + 'history': Dir({ 'file': File('') }), + 'History': Dir({ 'file': File('') }), + 'changelog': Dir({ 'file': File('') }), + 'ChangeLOG': Dir({ 'file': File('') }) + }) + }) + ) + withFixture(t, fixture, function (done) { + t.notOk(fileExists('node_modules/readme/file'), 'readme module not included') + t.notOk(fileExists('node_modules/README/file'), 'README module not included') + t.notOk(fileExists('node_modules/licence/file'), 'licence module not included') + t.notOk(fileExists('node_modules/license/file'), 'license module not included') + t.notOk(fileExists('node_modules/history/file'), 'history module not included') + t.notOk(fileExists('node_modules/History/file'), 'History module not included') + t.notOk(fileExists('node_modules/changelog/file'), 'changelog module not included') + t.notOk(fileExists('node_modules/ChangeLOG/file'), 'ChangeLOG module not included') + + done() + }) +}) + test('folder-based inclusion works', function (t) { var fixture = new Tacks( Dir({ @@ -534,7 +574,7 @@ test('folder-based inclusion works', function (t) { function fileExists (file) { try { - return !!fs.statSync(path.resolve(installedpath, file)) + return !!fs.statSync(path.resolve(targetpath, 'package', file)) } catch (_) { return false } @@ -542,11 +582,15 @@ function fileExists (file) { function withFixture (t, fixture, tester) { fixture.create(fixturepath) - mkdirp.sync(modulepath) - common.npm(['install', fixturepath], {cwd: basepath}, installCheckAndTest) - function installCheckAndTest (err, code) { + mkdirp.sync(targetpath) + common.npm(['pack', fixturepath], {cwd: basepath}, extractAndCheck) + function extractAndCheck (err, code) { + if (err) throw err + t.is(code, 0, 'pack went ok') + extractTarball(checkTests) + } + function checkTests (err) { if (err) throw err - t.is(code, 0, 'install went ok') tester(removeAndDone) } function removeAndDone (err) { @@ -556,3 +600,13 @@ function withFixture (t, fixture, tester) { t.done() } } + +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() }) +} diff --git a/deps/npm/test/tap/install-parse-error.js b/deps/npm/test/tap/install-parse-error.js new file mode 100644 index 0000000000..b142abb39a --- /dev/null +++ b/deps/npm/test/tap/install-parse-error.js @@ -0,0 +1,51 @@ +'use strict' +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({ + 'package.json': File( + '{\n' + + "'name': 'some-name',\n" + + "'dependencies': {}\n" + + '}' + ), + 'node_modules': Dir() +})) + +function setup () { + fixture.create(testdir) +} + +function cleanup () { + fixture.remove(testdir) +} + +test('setup', function (t) { + cleanup() + setup() + t.end() +}) + +test('failing to parse package.json should be error', function (t) { + common.npm( + ['install'], + {cwd: testdir}, + function (err, code, stdout, stderr) { + if (err) throw err + t.equal(code, 1, 'exit not ok') + t.similar(stderr, /npm ERR! Failed to parse json/) + t.end() + } + ) +}) + +test('cleanup', function (t) { + cleanup() + t.end() +}) diff --git a/deps/npm/test/tap/lifecycle-signal.js b/deps/npm/test/tap/lifecycle-signal.js index 4c41a9e98a..68fe9db2d6 100644 --- a/deps/npm/test/tap/lifecycle-signal.js +++ b/deps/npm/test/tap/lifecycle-signal.js @@ -56,7 +56,7 @@ test('lifecycle propagate signal term to child', function (t) { cwd: pkg }) child.stderr.on('data', function (data) { - innerChildPid = Number.parseInt(data.toString(), 10) + innerChildPid = parseInt(data.toString(), 10) t.doesNotThrow(function () { process.kill(innerChildPid, 0) // inner child should be running }) diff --git a/deps/npm/test/tap/progress-config.js b/deps/npm/test/tap/progress-config.js index acddc0d07b..634c9e8596 100644 --- a/deps/npm/test/tap/progress-config.js +++ b/deps/npm/test/tap/progress-config.js @@ -1,6 +1,9 @@ 'use strict' +var path = require('path') var test = require('tap').test var log = require('npmlog') +var fs = require('graceful-fs') +var configName = path.join(__dirname, path.basename(__filename, '.js')) + '-npmrc' // We use requireInject to get a fresh copy of // the npm singleton each time we require it. @@ -15,10 +18,15 @@ function hasOnlyAscii (s) { return /^[\000-\177]*$/.test(s) } +test('setup', function (t) { + fs.writeFileSync(configName, '') + t.done() +}) + test('disabled', function (t) { t.plan(1) var npm = requireInject('../../lib/npm.js', {}) - npm.load({progress: false}, function () { + npm.load({userconfig: configName, progress: false}, function () { t.is(log.progressEnabled, false, 'should be disabled') }) }) @@ -26,7 +34,7 @@ test('disabled', function (t) { test('enabled', function (t) { t.plan(1) var npm = requireInject('../../lib/npm.js', {}) - npm.load({progress: true}, function () { + npm.load({userconfig: configName, progress: true}, function () { t.is(log.progressEnabled, true, 'should be enabled') }) }) @@ -34,7 +42,7 @@ test('enabled', function (t) { test('default', function (t) { t.plan(1) var npm = requireInject('../../lib/npm.js', {}) - npm.load({}, function () { + npm.load({userconfig: configName}, function () { t.is(log.progressEnabled, true, 'should be enabled') }) }) @@ -43,7 +51,7 @@ test('default-travis', function (t) { t.plan(1) global.process.env.TRAVIS = 'true' var npm = requireInject('../../lib/npm.js', {}) - npm.load({}, function () { + npm.load({userconfig: configName}, function () { t.is(log.progressEnabled, false, 'should be disabled') delete global.process.env.TRAVIS }) @@ -53,7 +61,7 @@ test('default-ci', function (t) { t.plan(1) global.process.env.CI = 'true' var npm = requireInject('../../lib/npm.js', {}) - npm.load({}, function () { + npm.load({userconfig: configName}, function () { t.is(log.progressEnabled, false, 'should be disabled') delete global.process.env.CI }) @@ -62,7 +70,7 @@ test('default-ci', function (t) { test('unicode-true', function (t) { t.plan(6) var npm = requireInject('../../lib/npm.js', {}) - npm.load({unicode: true}, function () { + npm.load({userconfig: configName, unicode: true}, function () { Object.keys(log.gauge.theme).forEach(function (key) { t.notOk(hasOnlyAscii(log.gauge.theme[key]), 'only unicode') }) @@ -72,9 +80,14 @@ test('unicode-true', function (t) { test('unicode-false', function (t) { t.plan(6) var npm = requireInject('../../lib/npm.js', {}) - npm.load({unicode: false}, function () { + npm.load({userconfig: configName, unicode: false}, function () { Object.keys(log.gauge.theme).forEach(function (key) { t.ok(hasOnlyAscii(log.gauge.theme[key]), 'only ASCII') }) }) }) + +test('cleanup', function (t) { + fs.unlinkSync(configName) + t.done() +}) diff --git a/deps/npm/test/tap/view.js b/deps/npm/test/tap/view.js index 8c5c901ab2..e80031b1c2 100644 --- a/deps/npm/test/tap/view.js +++ b/deps/npm/test/tap/view.js @@ -259,6 +259,24 @@ test('npm view <package name> --global', function (t) { }) }) +test('npm view <package name>@<semver range> versions', function (t) { + mr({ port: common.port, plugin: plugin }, function (er, s) { + common.npm([ + 'view', + 'underscore@^1.5.0', + 'versions', + '--registry=' + common.registry + ], { cwd: t2dir }, function (err, code, stdout) { + t.ifError(err, 'view command finished successfully') + t.equal(code, 0, 'exit ok') + var re = new RegExp('1.5.0') + t.similar(stdout, re, 'should have version `1.5.0`') + s.close() + t.end() + }) + }) +}) + test('npm view <package name> --json', function (t) { t.plan(3) mr({ port: common.port, plugin: plugin }, function (er, s) { |