diff options
author | Kat Marchán <kzm@sykosomatic.org> | 2016-10-25 17:07:19 -0700 |
---|---|---|
committer | Jeremiah Senkpiel <fishrock123@rocketmail.com> | 2016-11-04 17:51:05 -0400 |
commit | 379097850d714494b3cfb92803d79d9999c983ef (patch) | |
tree | 08fc64801758d6239872540e05e0e6952cd40c8c /deps/npm/test/tap/view.js | |
parent | 1a55e9a5672ec654a6cfdd694c20b7067368f5e9 (diff) | |
download | android-node-v8-379097850d714494b3cfb92803d79d9999c983ef.tar.gz android-node-v8-379097850d714494b3cfb92803d79d9999c983ef.tar.bz2 android-node-v8-379097850d714494b3cfb92803d79d9999c983ef.zip |
deps: upgrade npm to 3.10.9
PR-URL: https://github.com/nodejs/node/pull/9286
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'deps/npm/test/tap/view.js')
-rw-r--r-- | deps/npm/test/tap/view.js | 464 |
1 files changed, 235 insertions, 229 deletions
diff --git a/deps/npm/test/tap/view.js b/deps/npm/test/tap/view.js index e80031b1c2..371e1d922d 100644 --- a/deps/npm/test/tap/view.js +++ b/deps/npm/test/tap/view.js @@ -11,6 +11,8 @@ var t2dir = path.resolve(tmp, 'view-local-notmine') var t3dir = path.resolve(tmp, 'view-local-mine') var mr = require('npm-registry-mock') +var server + test('setup', function (t) { mkdirp.sync(t1dir) mkdirp.sync(t2dir) @@ -29,7 +31,11 @@ test('setup', function (t) { }), 'utf8') t.pass('created fixtures') - t.end() + + mr({ port: common.port, plugin: plugin }, function (er, s) { + server = s + t.end() + }) }) function plugin (server) { @@ -84,294 +90,293 @@ test('npm view . with no package.json', function (t) { test('npm view . with no published package', function (t) { process.chdir(t3dir) - mr({ port: common.port, plugin: plugin }, function (er, s) { - common.npm([ - 'view', - '.', - '--registry=' + common.registry - ], { cwd: t3dir }, function (err, code, stdout, stderr) { - t.ifError(err, 'view command finished successfully') - t.equal(code, 1, 'exit not ok') - t.similar(stderr, /version not found/m) - s.close() - t.end() - }) + common.npm([ + 'view', + '.', + '--registry=' + common.registry + ], { cwd: t3dir }, function (err, code, stdout, stderr) { + t.ifError(err, 'view command finished successfully') + t.equal(code, 1, 'exit not ok') + t.similar(stderr, /version not found/m) + t.end() }) }) test('npm view .', function (t) { process.chdir(t2dir) - mr({ port: common.port, plugin: plugin }, function (er, s) { - common.npm([ - 'view', - '.', - '--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("name: 'test-repo-url-https'") - t.similar(stdout, re) - s.close() - t.end() - }) + common.npm([ + 'view', + '.', + '--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("name: 'test-repo-url-https'") + t.similar(stdout, re) + t.end() }) }) test('npm view . select fields', function (t) { process.chdir(t2dir) - mr({ port: common.port, plugin: plugin }, function (er, s) { - common.npm([ - 'view', - '.', - 'main', - '--registry=' + common.registry - ], { cwd: t2dir }, function (err, code, stdout) { - t.ifError(err, 'view command finished successfully') - t.equal(code, 0, 'exit ok') - t.equal(stdout.trim(), 'index.js', 'should print `index.js`') - s.close() - t.end() - }) + common.npm([ + 'view', + '.', + 'main', + '--registry=' + common.registry + ], { cwd: t2dir }, function (err, code, stdout) { + t.ifError(err, 'view command finished successfully') + t.equal(code, 0, 'exit ok') + t.equal(stdout.trim(), 'index.js', 'should print `index.js`') + t.end() }) }) test('npm view .@<version>', function (t) { process.chdir(t2dir) - mr({ port: common.port, plugin: plugin }, function (er, s) { - common.npm([ - 'view', - '.@0.0.0', - 'version', - '--registry=' + common.registry - ], { cwd: t2dir }, function (err, code, stdout) { - t.ifError(err, 'view command finished successfully') - t.equal(code, 0, 'exit ok') - t.equal(stdout.trim(), '0.0.0', 'should print `0.0.0`') - s.close() - t.end() - }) + common.npm([ + 'view', + '.@0.0.0', + 'version', + '--registry=' + common.registry + ], { cwd: t2dir }, function (err, code, stdout) { + t.ifError(err, 'view command finished successfully') + t.equal(code, 0, 'exit ok') + t.equal(stdout.trim(), '0.0.0', 'should print `0.0.0`') + t.end() }) }) test('npm view .@<version> version --json', function (t) { process.chdir(t2dir) - mr({ port: common.port, plugin: plugin }, function (er, s) { - common.npm([ - 'view', - '.@0.0.0', - 'version', - '--json', - '--registry=' + common.registry - ], { cwd: t2dir }, function (err, code, stdout) { - t.ifError(err, 'view command finished successfully') - t.equal(code, 0, 'exit ok') - t.equal(stdout.trim(), '"0.0.0"', 'should print `"0.0.0"`') - s.close() - t.end() - }) + common.npm([ + 'view', + '.@0.0.0', + 'version', + '--json', + '--registry=' + common.registry + ], { cwd: t2dir }, function (err, code, stdout) { + t.ifError(err, 'view command finished successfully') + t.equal(code, 0, 'exit ok') + t.equal(stdout.trim(), '"0.0.0"', 'should print `"0.0.0"`') + t.end() }) }) test('npm view . --json author name version', function (t) { process.chdir(t2dir) - mr({ port: common.port, plugin: plugin }, function (er, s) { - common.npm([ - 'view', - '.', - 'author', - 'name', - 'version', - '--json', - '--registry=' + common.registry - ], { cwd: t2dir }, function (err, code, stdout) { - var expected = JSON.stringify({ - author: 'Evan Lucas <evanlucas@me.com>', - name: 'test-repo-url-https', - version: '0.0.1' - }, null, 2) - t.ifError(err, 'view command finished successfully') - t.equal(code, 0, 'exit ok') - t.equal(stdout.trim(), expected, 'should print ' + expected) - s.close() - t.end() - }) + common.npm([ + 'view', + '.', + 'author', + 'name', + 'version', + '--json', + '--registry=' + common.registry + ], { cwd: t2dir }, function (err, code, stdout) { + var expected = JSON.stringify({ + author: 'Evan Lucas <evanlucas@me.com>', + name: 'test-repo-url-https', + version: '0.0.1' + }, null, 2) + t.ifError(err, 'view command finished successfully') + t.equal(code, 0, 'exit ok') + t.equal(stdout.trim(), expected, 'should print ' + expected) + t.end() }) }) test('npm view .@<version> --json author name version', function (t) { process.chdir(t2dir) - mr({ port: common.port, plugin: plugin }, function (er, s) { - common.npm([ - 'view', - '.@0.0.0', - 'author', - 'name', - 'version', - '--json', - '--registry=' + common.registry - ], { cwd: t2dir }, function (err, code, stdout) { - var expected = JSON.stringify({ - author: 'Evan Lucas <evanlucas@me.com>', - name: 'test-repo-url-https', - version: '0.0.0' - }, null, 2) - t.ifError(err, 'view command finished successfully') - t.equal(code, 0, 'exit ok') - t.equal(stdout.trim(), expected, 'should print ' + expected) - s.close() - t.end() - }) + common.npm([ + 'view', + '.@0.0.0', + 'author', + 'name', + 'version', + '--json', + '--registry=' + common.registry + ], { cwd: t2dir }, function (err, code, stdout) { + var expected = JSON.stringify({ + author: 'Evan Lucas <evanlucas@me.com>', + name: 'test-repo-url-https', + version: '0.0.0' + }, null, 2) + t.ifError(err, 'view command finished successfully') + t.equal(code, 0, 'exit ok') + t.equal(stdout.trim(), expected, 'should print ' + expected) + t.end() }) }) test('npm view <package name>', function (t) { - mr({ port: common.port, plugin: plugin }, function (er, s) { - common.npm([ - 'view', - 'underscore', - '--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("name: 'underscore'") - t.similar(stdout, re, 'should have name `underscore`') - s.close() - t.end() - }) + common.npm([ + 'view', + 'underscore', + '--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("name: 'underscore'") + t.similar(stdout, re, 'should have name `underscore`') + t.end() }) }) test('npm view <package name> --global', function (t) { - mr({ port: common.port, plugin: plugin }, function (er, s) { - common.npm([ - 'view', - 'underscore', - '--global', - '--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("name: 'underscore'") - t.similar(stdout, re, 'should have name `underscore`') - s.close() - t.end() - }) + common.npm([ + 'view', + 'underscore', + '--global', + '--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("name: 'underscore'") + t.similar(stdout, re, 'should have name `underscore`') + t.end() }) }) 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() - }) + 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`') + t.end() + }) +}) + +test('npm view <package name>@<semver range> version --json', function (t) { + common.npm([ + 'view', + 'underscore@~1.5.0', + 'version', + '--json', + '--registry=' + common.registry + ], { cwd: t2dir }, function (err, code, stdout) { + t.ifError(err, 'view command finished successfully') + t.equal(code, 0, 'exit ok') + t.equal(stdout.trim(), JSON.stringify([ + '1.5.0', + '1.5.1' + ], null, 2), 'should have three versions') + t.end() }) }) test('npm view <package name> --json', function (t) { t.plan(3) - mr({ port: common.port, plugin: plugin }, function (er, s) { - common.npm([ - 'view', - 'underscore', - '--json', - '--registry=' + common.registry - ], { cwd: t2dir }, function (err, code, stdout) { - t.ifError(err, 'view command finished successfully') - t.equal(code, 0, 'exit ok') - s.close() - try { - var out = JSON.parse(stdout.trim()) - t.similar(out, { - maintainers: ['jashkenas <jashkenas@gmail.com>'] - }, 'should have the same maintainer') - } catch (er) { - t.fail('Unable to parse JSON') - } - }) + common.npm([ + 'view', + 'underscore', + '--json', + '--registry=' + common.registry + ], { cwd: t2dir }, function (err, code, stdout) { + t.ifError(err, 'view command finished successfully') + t.equal(code, 0, 'exit ok') + try { + var out = JSON.parse(stdout.trim()) + t.similar(out, { + maintainers: ['jashkenas <jashkenas@gmail.com>'] + }, 'should have the same maintainer') + } catch (er) { + t.fail('Unable to parse JSON') + } + }) +}) + +test('npm view <package name>@<invalid version>', function (t) { + common.npm([ + 'view', + 'underscore@12345', + '--registry=' + common.registry + ], { cwd: t2dir }, function (err, code, stdout) { + t.ifError(err, 'view command finished successfully') + t.equal(code, 0, 'exit ok') + t.equal(stdout.trim(), '', 'should return empty') + t.end() + }) +}) + +test('npm view <package name>@<invalid version> --json', function (t) { + common.npm([ + 'view', + 'underscore@12345', + '--json', + '--registry=' + common.registry + ], { cwd: t2dir }, function (err, code, stdout) { + t.ifError(err, 'view command finished successfully') + t.equal(code, 0, 'exit ok') + t.equal(stdout.trim(), '', 'should return empty') + t.end() }) }) test('npm view <package name> <field>', function (t) { - mr({ port: common.port, plugin: plugin }, function (er, s) { - common.npm([ - 'view', - 'underscore', - 'homepage', - '--registry=' + common.registry - ], { cwd: t2dir }, function (err, code, stdout) { - t.ifError(err, 'view command finished successfully') - t.equal(code, 0, 'exit ok') - t.equal(stdout.trim(), 'http://underscorejs.org', - 'homepage should equal `http://underscorejs.org`') - s.close() - t.end() - }) + common.npm([ + 'view', + 'underscore', + 'homepage', + '--registry=' + common.registry + ], { cwd: t2dir }, function (err, code, stdout) { + t.ifError(err, 'view command finished successfully') + t.equal(code, 0, 'exit ok') + t.equal(stdout.trim(), 'http://underscorejs.org', + 'homepage should equal `http://underscorejs.org`') + t.end() }) }) test('npm view with invalid package name', function (t) { var invalidName = 'InvalidPackage' - var obj = {} - obj['/' + invalidName] = [404, {'error': 'not found'}] - - mr({ port: common.port, mocks: { 'get': obj } }, function (er, s) { - common.npm([ - 'view', - invalidName, - '--registry=' + common.registry - ], {}, function (err, code, stdout, stderr) { - t.ifError(err, 'view command finished successfully') - t.equal(code, 1, 'exit not ok') - - t.similar(stderr, new RegExp('is not in the npm registry'), - 'Package should NOT be found') - - t.dissimilar(stderr, new RegExp('use the name yourself!'), - 'Suggestion should not be there') - - t.similar(stderr, new RegExp('name can no longer contain capital letters'), - 'Suggestion about Capital letter should be there') - - s.close() - t.end() - }) + + server.get('/' + invalidName).reply('404', {'error': 'not found'}) + common.npm([ + 'view', + invalidName, + '--registry=' + common.registry + ], {}, function (err, code, stdout, stderr) { + t.ifError(err, 'view command finished successfully') + t.equal(code, 1, 'exit not ok') + + t.similar(stderr, new RegExp('is not in the npm registry'), + 'Package should NOT be found') + + t.dissimilar(stderr, new RegExp('use the name yourself!'), + 'Suggestion should not be there') + + t.similar(stderr, new RegExp('name can no longer contain capital letters'), + 'Suggestion about Capital letter should be there') + + t.end() }) }) test('npm view with valid but non existent package name', function (t) { - mr({ port: common.port, mocks: { - 'get': { - '/valid-but-non-existent-package': [404, {'error': 'not found'}] - } - }}, function (er, s) { - common.npm([ - 'view', - 'valid-but-non-existent-package', - '--registry=' + common.registry - ], {}, function (err, code, stdout, stderr) { - t.ifError(err, 'view command finished successfully') - t.equal(code, 1, 'exit not ok') - - t.similar(stderr, - new RegExp("'valid-but-non-existent-package' is not in the npm registry\."), - 'Package should NOT be found') - - t.similar(stderr, new RegExp('use the name yourself!'), - 'Suggestion should be there') - - s.close() - t.end() - }) + server.get('/valid-but-non-existent-package').reply(404, {'error': 'not found'}) + common.npm([ + 'view', + 'valid-but-non-existent-package', + '--registry=' + common.registry + ], {}, function (err, code, stdout, stderr) { + t.ifError(err, 'view command finished successfully') + t.equal(code, 1, 'exit not ok') + + t.similar(stderr, + new RegExp("'valid-but-non-existent-package' is not in the npm registry\."), + 'Package should NOT be found') + + t.similar(stderr, new RegExp('use the name yourself!'), + 'Suggestion should be there') + + t.end() }) }) @@ -381,5 +386,6 @@ test('cleanup', function (t) { rimraf.sync(t2dir) rimraf.sync(t3dir) t.pass('cleaned up') + server.close() t.end() }) |