summaryrefslogtreecommitdiff
path: root/deps/npm/test
diff options
context:
space:
mode:
authorKat Marchán <kzm@sykosomatic.org>2017-02-14 15:12:22 -0800
committerJeremiah Senkpiel <fishrock123@rocketmail.com>2017-03-22 18:27:31 -0400
commite1834ff5da0117457a14fe76a097ed7763cfb61f (patch)
tree15ae7076df1333fb02cb20d5fafb542f0d526874 /deps/npm/test
parentcaf9ae748b1324c34284b324f2951b91368ca840 (diff)
downloadandroid-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')
-rw-r--r--deps/npm/test/tap/debug-logs.js101
-rw-r--r--deps/npm/test/tap/gently-rm-overeager.js13
-rw-r--r--deps/npm/test/tap/run-script.js19
-rw-r--r--deps/npm/test/tap/search.all-package-search.js201
-rw-r--r--deps/npm/test/tap/search.esearch.js192
-rw-r--r--deps/npm/test/tap/search.js259
6 files changed, 562 insertions, 223 deletions
diff --git a/deps/npm/test/tap/debug-logs.js b/deps/npm/test/tap/debug-logs.js
new file mode 100644
index 0000000000..fbd244446e
--- /dev/null
+++ b/deps/npm/test/tap/debug-logs.js
@@ -0,0 +1,101 @@
+'use strict'
+var path = require('path')
+var test = require('tap').test
+var Tacks = require('tacks')
+var glob = require('glob')
+var asyncMap = require('slide').asyncMap
+var File = Tacks.File
+var Dir = Tacks.Dir
+var extend = Object.assign || require('util')._extend
+var common = require('../common-tap.js')
+
+var basedir = path.join(__dirname, path.basename(__filename, '.js'))
+var testdir = path.join(basedir, 'testdir')
+var cachedir = path.join(basedir, 'cache')
+var globaldir = path.join(basedir, 'global')
+var tmpdir = path.join(basedir, 'tmp')
+
+var conf = {
+ cwd: testdir,
+ env: extend(extend({}, process.env), {
+ npm_config_cache: cachedir,
+ npm_config_tmp: tmpdir,
+ npm_config_prefix: globaldir,
+ npm_config_registry: common.registry,
+ npm_config_loglevel: 'warn'
+ })
+}
+
+var fixture = new Tacks(Dir({
+ cache: Dir(),
+ global: Dir(),
+ tmp: Dir(),
+ testdir: Dir({
+ 'package.json': File({
+ name: 'debug-logs',
+ version: '1.0.0',
+ scripts: {
+ true: 'node -e "process.exit(0)"',
+ false: 'node -e "process.exit(1)"'
+ }
+ })
+ })
+}))
+
+function setup () {
+ cleanup()
+ fixture.create(basedir)
+}
+
+function cleanup () {
+ fixture.remove(basedir)
+}
+
+test('setup', function (t) {
+ setup()
+ t.done()
+})
+
+test('example', function (t) {
+ common.npm(['run', 'false'], conf, function (err, code, stdout, stderr) {
+ if (err) throw err
+ t.is(code, 1, 'command errored')
+ var matches = stderr.match(/Please include the following file with any support request:.*\nnpm ERR! {5,5}(.*)/)
+ t.ok(matches, 'debug log mentioned in error message')
+ if (matches) {
+ var logfile = matches[1]
+ t.matches(path.relative(cachedir, logfile), /^_logs/, 'debug log is inside the cache in _logs')
+ }
+
+ // we run a bunch concurrently, this will actually create > than our limit as the check is done
+ // when the command starts
+ var todo = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
+ asyncMap(todo, function (num, next) {
+ common.npm(['run', '--logs-max=10', 'false'], conf, function (err, code) {
+ if (err) throw err
+ t.is(code, 1, 'run #' + num + ' errored as expected')
+ next()
+ })
+ }, function () {
+ // now we do one more and that should clean up the list
+ common.npm(['run', '--logs-max=10', 'false'], conf, function (err, code) {
+ if (err) throw err
+ t.is(code, 1, 'final run errored as expected')
+ var files = glob.sync(path.join(cachedir, '_logs', '*'))
+ t.is(files.length, 10, 'there should never be more than 10 log files')
+ common.npm(['run', '--logs-max=5', 'true'], conf, function (err, code) {
+ if (err) throw err
+ t.is(code, 0, 'success run is ok')
+ var files = glob.sync(path.join(cachedir, '_logs', '*'))
+ t.is(files.length, 4, 'after success there should be logs-max - 1 log files')
+ t.done()
+ })
+ })
+ })
+ })
+})
+
+test('cleanup', function (t) {
+ cleanup()
+ t.done()
+})
diff --git a/deps/npm/test/tap/gently-rm-overeager.js b/deps/npm/test/tap/gently-rm-overeager.js
index c266f1c4dc..08fa72bc71 100644
--- a/deps/npm/test/tap/gently-rm-overeager.js
+++ b/deps/npm/test/tap/gently-rm-overeager.js
@@ -1,4 +1,4 @@
-var resolve = require('path').resolve
+var path = require('path')
var fs = require('graceful-fs')
var test = require('tap').test
var mkdirp = require('mkdirp')
@@ -6,8 +6,8 @@ var rimraf = require('rimraf')
var common = require('../common-tap.js')
-var pkg = resolve(__dirname, 'gently-rm-overeager')
-var dep = resolve(__dirname, 'test-whoops')
+var pkg = path.join(__dirname, 'gently-rm-overeager')
+var dep = path.join(__dirname, 'test-whoops')
var EXEC_OPTS = { cwd: pkg }
@@ -32,8 +32,7 @@ test('cache add', function (t) {
t.ok(c, 'test-whoops install also failed')
fs.readdir(pkg, function (er, files) {
t.ifError(er, 'package directory is still there')
- t.deepEqual(files, ['npm-debug.log'], 'only debug log remains')
-
+ t.deepEqual(files, [], 'no files remain')
t.end()
})
})
@@ -53,7 +52,7 @@ function cleanup () {
function setup () {
mkdirp.sync(pkg)
// so it doesn't try to install into npm's own node_modules
- mkdirp.sync(resolve(pkg, 'node_modules'))
+ mkdirp.sync(path.join(pkg, 'node_modules'))
mkdirp.sync(dep)
- fs.writeFileSync(resolve(dep, 'package.json'), JSON.stringify(fixture))
+ fs.writeFileSync(path.join(dep, 'package.json'), JSON.stringify(fixture))
}
diff --git a/deps/npm/test/tap/run-script.js b/deps/npm/test/tap/run-script.js
index 3892337cee..4dea9b8360 100644
--- a/deps/npm/test/tap/run-script.js
+++ b/deps/npm/test/tap/run-script.js
@@ -67,6 +67,14 @@ var preversionOnly = {
}
}
+var exitCode = {
+ name: 'scripted',
+ version: '1.2.3',
+ scripts: {
+ 'start': 'node -e "process.exit(7)"'
+ }
+}
+
function testOutput (t, command, er, code, stdout, stderr) {
var lines
@@ -323,6 +331,17 @@ test('npm run-script no-params (direct only)', function (t) {
})
})
+test('npm run-script keep non-zero exit code', function (t) {
+ writeMetadata(exitCode)
+
+ common.npm(['run-script', 'start'], opts, function (err, code, stdout, stderr) {
+ t.ifError(err, 'ran run-script without parameters without crashing')
+ t.equal(code, 7, 'got expected exit code')
+ t.ok(stderr, 'should generate errors')
+ t.end()
+ })
+})
+
test('cleanup', function (t) {
cleanup()
t.end()
diff --git a/deps/npm/test/tap/search.all-package-search.js b/deps/npm/test/tap/search.all-package-search.js
new file mode 100644
index 0000000000..c70f4f8e7e
--- /dev/null
+++ b/deps/npm/test/tap/search.all-package-search.js
@@ -0,0 +1,201 @@
+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')
+var test = require('tap').test
+var Tacks = require('tacks')
+var File = Tacks.File
+
+var common = require('../common-tap.js')
+
+var PKG_DIR = path.resolve(__dirname, 'search')
+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) {
+ mr({port: common.port, throwOnUnmatched: true}, function (err, s) {
+ t.ifError(err, 'registry mocked successfully')
+ server = s
+ t.pass('all set up')
+ t.done()
+ })
+})
+
+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']
+ }
+ }
+ }
+]
+
+// These test classic hand-matched searches
+searches.forEach(function (search) {
+ test(search.description, function (t) {
+ setup()
+ server.get('/-/v1/search?text=' + encodeURIComponent(search.term) + '&size=20').once().reply(404, {})
+ 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()
+})
+
+function setup () {
+ cleanup()
+ mkdirp.sync(cacheBase)
+}
+
+function cleanup () {
+ server.done()
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(PKG_DIR)
+}
diff --git a/deps/npm/test/tap/search.esearch.js b/deps/npm/test/tap/search.esearch.js
new file mode 100644
index 0000000000..d892aec957
--- /dev/null
+++ b/deps/npm/test/tap/search.esearch.js
@@ -0,0 +1,192 @@
+var common = require('../common-tap.js')
+var finished = require('mississippi').finished
+var mkdirp = require('mkdirp')
+var mr = require('npm-registry-mock')
+var npm = require('../../')
+var osenv = require('osenv')
+var path = require('path')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var SEARCH = '/-/v1/search'
+var PKG_DIR = path.resolve(__dirname, 'create-entry-update-stream')
+var CACHE_DIR = path.resolve(PKG_DIR, 'cache')
+
+var esearch = require('../../lib/search/esearch')
+
+var server
+
+function setup () {
+ cleanup()
+ mkdirp.sync(CACHE_DIR)
+ process.chdir(CACHE_DIR)
+}
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(PKG_DIR)
+}
+
+test('setup', function (t) {
+ mr({port: common.port, throwOnUnmatched: true}, function (err, s) {
+ t.ifError(err, 'registry mocked successfully')
+ npm.load({ cache: CACHE_DIR, registry: common.registry }, function (err) {
+ t.ifError(err, 'npm loaded successfully')
+ server = s
+ t.pass('all set up')
+ t.done()
+ })
+ })
+})
+
+test('basic test', function (t) {
+ setup()
+ server.get(SEARCH + '?text=oo&size=1').once().reply(200, {
+ objects: [
+ { package: { name: 'cool', version: '1.0.0' } },
+ { package: { name: 'foo', version: '2.0.0' } }
+ ]
+ })
+ var results = []
+ var s = esearch({
+ include: ['oo'],
+ limit: 1
+ })
+ t.ok(s, 'got a stream')
+ s.on('data', function (d) {
+ results.push(d)
+ })
+ finished(s, function (err) {
+ if (err) { throw err }
+ t.ok(true, 'stream finished without error')
+ t.deepEquals(results, [{
+ name: 'cool',
+ version: '1.0.0',
+ description: null,
+ maintainers: null,
+ keywords: null,
+ date: null
+ }, {
+ name: 'foo',
+ version: '2.0.0',
+ description: null,
+ maintainers: null,
+ keywords: null,
+ date: null
+ }])
+ server.done()
+ t.done()
+ })
+})
+
+test('only returns certain fields for each package', function (t) {
+ setup()
+ var date = new Date()
+ server.get(SEARCH + '?text=oo&size=1').once().reply(200, {
+ objects: [{
+ package: {
+ name: 'cool',
+ version: '1.0.0',
+ description: 'desc',
+ maintainers: [
+ {username: 'x', email: 'a@b.c'},
+ {username: 'y', email: 'c@b.a'}
+ ],
+ keywords: ['a', 'b', 'c'],
+ date: date.toISOString(),
+ extra: 'lol'
+ }
+ }]
+ })
+ var results = []
+ var s = esearch({
+ include: ['oo'],
+ limit: 1
+ })
+ t.ok(s, 'got a stream')
+ s.on('data', function (d) {
+ results.push(d)
+ })
+ finished(s, function (err) {
+ if (err) { throw err }
+ t.ok(true, 'stream finished without error')
+ t.deepEquals(results, [{
+ name: 'cool',
+ version: '1.0.0',
+ description: 'desc',
+ maintainers: [
+ {username: 'x', email: 'a@b.c'},
+ {username: 'y', email: 'c@b.a'}
+ ],
+ keywords: ['a', 'b', 'c'],
+ date: date
+ }])
+ server.done()
+ t.done()
+ })
+})
+
+test('accepts a limit option', function (t) {
+ setup()
+ server.get(SEARCH + '?text=oo&size=3').once().reply(200, {
+ objects: [
+ { package: { name: 'cool', version: '1.0.0' } },
+ { package: { name: 'cool', version: '1.0.0' } }
+ ]
+ })
+ var results = 0
+ var s = esearch({
+ include: ['oo'],
+ limit: 3
+ })
+ s.on('data', function () { results++ })
+ finished(s, function (err) {
+ if (err) { throw err }
+ t.ok(true, 'request sent with correct size')
+ t.equal(results, 2, 'behaves fine with fewer results than size')
+ server.done()
+ t.done()
+ })
+})
+
+test('passes foo:bar syntax params directly', function (t) {
+ setup()
+ server.get(SEARCH + '?text=foo%3Abar&size=1').once().reply(200, {
+ objects: []
+ })
+ var s = esearch({
+ include: ['foo:bar'],
+ limit: 1
+ })
+ s.on('data', function () {})
+ finished(s, function (err) {
+ if (err) { throw err }
+ t.ok(true, 'request sent with correct params')
+ server.done()
+ t.done()
+ })
+})
+
+test('space-separates and URI-encodes multiple search params', function (t) {
+ setup()
+ server.get(SEARCH + '?text=foo%20bar%3Abaz%20quux%3F%3D&size=1').once().reply(200, {
+ objects: []
+ })
+ var s = esearch({
+ include: ['foo', 'bar:baz', 'quux?='],
+ limit: 1
+ })
+ s.on('data', function () {})
+ finished(s, function (err) {
+ if (err) { throw err }
+ t.ok(true, 'request sent with correct params')
+ server.done()
+ t.done()
+ })
+})
+
+test('cleanup', function (t) {
+ server.close()
+ cleanup()
+ t.done()
+})
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)
}