diff options
author | Kat Marchán <kzm@sykosomatic.org> | 2017-02-14 15:12:22 -0800 |
---|---|---|
committer | Jeremiah Senkpiel <fishrock123@rocketmail.com> | 2017-03-22 18:27:31 -0400 |
commit | e1834ff5da0117457a14fe76a097ed7763cfb61f (patch) | |
tree | 15ae7076df1333fb02cb20d5fafb542f0d526874 /deps/npm/test/tap/search.js | |
parent | caf9ae748b1324c34284b324f2951b91368ca840 (diff) | |
download | android-node-v8-e1834ff5da0117457a14fe76a097ed7763cfb61f.tar.gz android-node-v8-e1834ff5da0117457a14fe76a097ed7763cfb61f.tar.bz2 android-node-v8-e1834ff5da0117457a14fe76a097ed7763cfb61f.zip |
deps: upgrade npm to 4.2.0
PR-URL: https://github.com/nodejs/node/pull/11389
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'deps/npm/test/tap/search.js')
-rw-r--r-- | deps/npm/test/tap/search.js | 259 |
1 files changed, 43 insertions, 216 deletions
diff --git a/deps/npm/test/tap/search.js b/deps/npm/test/tap/search.js index dcc46df78e..78436e1e29 100644 --- a/deps/npm/test/tap/search.js +++ b/deps/npm/test/tap/search.js @@ -1,5 +1,6 @@ var path = require('path') var mkdirp = require('mkdirp') +var mr = require('npm-registry-mock') var osenv = require('osenv') var rimraf = require('rimraf') var cacheFile = require('npm-cache-filename') @@ -14,28 +15,26 @@ var CACHE_DIR = path.resolve(PKG_DIR, 'cache') var cacheBase = cacheFile(CACHE_DIR)(common.registry + '/-/all') var cachePath = path.join(cacheBase, '.cache.json') +var server + test('setup', function (t) { - t.pass('all set up') - t.done() + mr({port: common.port, throwOnUnmatched: true}, function (err, s) { + t.ifError(err, 'registry mocked successfully') + server = s + t.pass('all set up') + t.done() + }) }) test('notifies when there are no results', function (t) { setup() - var now = Date.now() - var cacheContents = { - '_updated': now, - bar: { name: 'bar', version: '1.0.0' }, - cool: { name: 'cool', version: '1.0.0' }, - foo: { name: 'foo', version: '2.0.0' }, - other: { name: 'other', version: '1.0.0' } - } - var fixture = new Tacks(File(cacheContents)) - fixture.create(cachePath) + server.get('/-/v1/search?text=none&size=20').once().reply(200, { + objects: [] + }) common.npm([ - 'search', 'nomatcheswhatsoeverfromthis', + 'search', 'none', '--registry', common.registry, - '--loglevel', 'error', - '--cache', CACHE_DIR + '--loglevel', 'error' ], {}, function (err, code, stdout, stderr) { if (err) throw err t.equal(stderr, '', 'no error output') @@ -47,6 +46,8 @@ test('notifies when there are no results', function (t) { test('spits out a useful error when no cache nor network', function (t) { setup() + server.get('/-/v1/search?text=foo&size=20').once().reply(404, {}) + server.get('/-/all').many().reply(404, {}) var cacheContents = {} var fixture = new Tacks(File(cacheContents)) fixture.create(cachePath) @@ -54,6 +55,7 @@ test('spits out a useful error when no cache nor network', function (t) { 'search', 'foo', '--registry', common.registry, '--loglevel', 'silly', + '--json', '--fetch-retry-mintimeout', 0, '--fetch-retry-maxtimeout', 0, '--cache', CACHE_DIR @@ -68,16 +70,12 @@ test('spits out a useful error when no cache nor network', function (t) { test('can switch to JSON mode', function (t) { setup() - var now = Date.now() - var cacheContents = { - '_updated': now, - bar: { name: 'bar', version: '1.0.0' }, - cool: { name: 'cool', version: '1.0.0' }, - foo: { name: 'foo', version: '2.0.0' }, - other: { name: 'other', version: '1.0.0' } - } - var fixture = new Tacks(File(cacheContents)) - fixture.create(cachePath) + server.get('/-/v1/search?text=oo&size=20').once().reply(200, { + objects: [ + { package: { name: 'cool', version: '1.0.0' } }, + { package: { name: 'foo', version: '2.0.0' } } + ] + }) common.npm([ 'search', 'oo', '--json', @@ -86,30 +84,23 @@ test('can switch to JSON mode', function (t) { '--cache', CACHE_DIR ], {}, function (err, code, stdout, stderr) { if (err) throw err - t.deepEquals(JSON.parse(stdout), [ - { name: 'cool', version: '1.0.0' }, - { name: 'foo', version: '2.0.0' } - ], 'results returned as valid json') t.equal(stderr, '', 'no error output') t.equal(code, 0, 'search gives 0 error code even if no matches') + t.deepEquals(JSON.parse(stdout), [ + { name: 'cool', version: '1.0.0', date: null }, + { name: 'foo', version: '2.0.0', date: null } + ], 'results returned as valid json') t.done() }) }) test('JSON mode does not notify on empty', function (t) { setup() - var now = Date.now() - var cacheContents = { - '_updated': now, - bar: { name: 'bar', version: '1.0.0' }, - cool: { name: 'cool', version: '1.0.0' }, - foo: { name: 'foo', version: '2.0.0' }, - other: { name: 'other', version: '1.0.0' } - } - var fixture = new Tacks(File(cacheContents)) - fixture.create(cachePath) + server.get('/-/v1/search?text=oo&size=20').once().reply(200, { + objects: [] + }) common.npm([ - 'search', 'nomatcheswhatsoeverfromthis', + 'search', 'oo', '--json', '--registry', common.registry, '--loglevel', 'error', @@ -125,16 +116,12 @@ test('JSON mode does not notify on empty', function (t) { test('can switch to tab separated mode', function (t) { setup() - var now = Date.now() - var cacheContents = { - '_updated': now, - bar: { name: 'bar', version: '1.0.0' }, - cool: { name: 'cool', version: '1.0.0' }, - foo: { name: 'foo', description: 'this\thas\ttabs', version: '2.0.0' }, - other: { name: 'other', version: '1.0.0' } - } - var fixture = new Tacks(File(cacheContents)) - fixture.create(cachePath) + server.get('/-/v1/search?text=oo&size=20').once().reply(200, { + objects: [ + { package: { name: 'cool', version: '1.0.0' } }, + { package: { name: 'foo', description: 'this\thas\ttabs', version: '2.0.0' } } + ] + }) common.npm([ 'search', 'oo', '--parseable', @@ -152,18 +139,11 @@ test('can switch to tab separated mode', function (t) { test('tab mode does not notify on empty', function (t) { setup() - var now = Date.now() - var cacheContents = { - '_updated': now, - bar: { name: 'bar', version: '1.0.0' }, - cool: { name: 'cool', version: '1.0.0' }, - foo: { name: 'foo', version: '2.0.0' }, - other: { name: 'other', version: '1.0.0' } - } - var fixture = new Tacks(File(cacheContents)) - fixture.create(cachePath) + server.get('/-/v1/search?text=oo&size=20').once().reply(200, { + objects: [] + }) common.npm([ - 'search', 'nomatcheswhatsoeverfromthis', + 'search', 'oo', '--parseable', '--registry', common.registry, '--loglevel', 'error', @@ -192,163 +172,9 @@ test('no arguments provided should error', function (t) { }) }) -var searches = [ - { - term: 'cool', - description: 'non-regex search', - location: 103 - }, - { - term: '/cool/', - description: 'regex search', - location: 103 - }, - { - term: 'cool', - description: 'searches name field', - location: 103 - }, - { - term: 'ool', - description: 'excludes matches for --searchexclude', - location: 205, - inject: { - other: { name: 'other', description: 'this is a simple tool' } - }, - extraOpts: ['--searchexclude', 'cool'] - }, - { - term: 'neat lib', - description: 'searches description field', - location: 141, - inject: { - cool: { - name: 'cool', version: '5.0.0', description: 'this is a neat lib' - } - } - }, - { - term: 'foo', - description: 'skips description field with --no-description', - location: 80, - inject: { - cool: { - name: 'cool', version: '5.0.0', description: 'foo bar!' - } - }, - extraOpts: ['--no-description'] - }, - { - term: 'zkat', - description: 'searches maintainers by name', - location: 155, - inject: { - cool: { - name: 'cool', - version: '5.0.0', - maintainers: [{ - name: 'zkat' - }] - } - } - }, - { - term: '=zkat', - description: 'searches maintainers unambiguously by =name', - location: 154, - inject: { - bar: { name: 'bar', description: 'zkat thing', version: '1.0.0' }, - cool: { - name: 'cool', - version: '5.0.0', - maintainers: [{ - name: 'zkat' - }] - } - } - }, - { - term: 'github.com', - description: 'searches projects by url', - location: 205, - inject: { - bar: { - name: 'bar', - url: 'gitlab.com/bar', - // For historical reasons, `url` is only present if `versions` is there - versions: ['1.0.0'], - version: '1.0.0' - }, - cool: { - name: 'cool', - version: '5.0.0', - versions: ['1.0.0'], - url: 'github.com/cool/cool' - } - } - }, - { - term: 'monad', - description: 'searches projects by keywords', - location: 197, - inject: { - cool: { - name: 'cool', - version: '5.0.0', - keywords: ['monads'] - } - } - } -] - -searches.forEach(function (search) { - test(search.description, function (t) { - setup() - var now = Date.now() - var cacheContents = { - '_updated': now, - bar: { name: 'bar', version: '1.0.0' }, - cool: { name: 'cool', version: '5.0.0' }, - foo: { name: 'foo', version: '2.0.0' }, - other: { name: 'other', version: '1.0.0' } - } - for (var k in search.inject) { - cacheContents[k] = search.inject[k] - } - var fixture = new Tacks(File(cacheContents)) - fixture.create(cachePath) - common.npm([ - 'search', search.term, - '--registry', common.registry, - '--cache', CACHE_DIR, - '--loglevel', 'error', - '--color', 'always' - ].concat(search.extraOpts || []), - {}, - function (err, code, stdout, stderr) { - t.equal(stderr, '', 'no error output') - t.notEqual(stdout, '', 'got output') - t.equal(code, 0, 'search finished successfully') - t.ifErr(err, 'search finished successfully') - // \033 == \u001B - var markStart = '\u001B\\[[0-9][0-9]m' - var markEnd = '\u001B\\[0m' - - var re = new RegExp(markStart + '.*?' + markEnd) - - var cnt = stdout.search(re) - t.equal( - cnt, - search.location, - search.description + ' search for ' + search.term - ) - t.end() - }) - }) -}) - test('cleanup', function (t) { cleanup() + server.close() t.end() }) @@ -358,6 +184,7 @@ function setup () { } function cleanup () { + server.done() process.chdir(osenv.tmpdir()) rimraf.sync(PKG_DIR) } |