diff --git a/.eslintrc.json b/.eslintrc.json index cec6ba762..7f488f145 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -18,9 +18,14 @@ "endOfLine": "auto" } ], - /*temporarily turn off no-unused-vars, open an issue to track https://github.com/opensearch-project/opensearch-js/issues/241*/ - "no-unused-vars": "off", /*temporarily turn off no-dupe-else-if, open an issue to track https://github.com/opensearch-project/opensearch-js/issues/240*/ - "no-dupe-else-if": "off" + "no-dupe-else-if": "off", + "no-unused-vars": [ + "error", + { + "varsIgnorePattern": "^_.*", + "argsIgnorePattern": "^_.*" + } + ] } -} \ No newline at end of file +} diff --git a/index.js b/index.js index e36a0b679..56c02520c 100644 --- a/index.js +++ b/index.js @@ -286,7 +286,7 @@ class Client extends OpenSearchAPI { close(callback) { if (callback == null) { - return new Promise((resolve, reject) => { + return new Promise((resolve) => { this.close(resolve); }); } diff --git a/lib/Connection.js b/lib/Connection.js index 66f562c68..389c8d704 100644 --- a/lib/Connection.js +++ b/lib/Connection.js @@ -249,7 +249,8 @@ class Connection { // We want to hide `auth`, `agent` and `ssl` since they made // the logs very hard to read. The user can still // access them with `instance.agent` and `instance.ssl`. - [inspect.custom](depth, options) { + [inspect.custom]() { + // eslint-disable-next-line no-unused-vars const { authorization, ...headers } = this.headers; return { @@ -265,6 +266,7 @@ class Connection { } toJSON() { + // eslint-disable-next-line no-unused-vars const { authorization, ...headers } = this.headers; return { diff --git a/lib/Helpers.js b/lib/Helpers.js index 20d220531..b5aa12da6 100644 --- a/lib/Helpers.js +++ b/lib/Helpers.js @@ -97,7 +97,6 @@ class Helpers { } params.scroll = params.scroll || '1m'; appendFilterPath('_scroll_id', params, false); - const { method, body, index, ...querystring } = params; let response = null; for (let i = 0; i <= maxRetries; i++) { @@ -132,9 +131,8 @@ class Helpers { for (let i = 0; i <= maxRetries; i++) { response = await this[kClient].scroll( { - scroll: querystring.scroll, - rest_total_hits_as_int: - querystring.rest_total_hits_as_int || querystring.restTotalHitsAsInt, + scroll: params.scroll, + rest_total_hits_as_int: params.rest_total_hits_as_int || params.restTotalHitsAsInt, body: { scroll_id }, }, options @@ -199,7 +197,7 @@ class Helpers { let timeoutRef = null; const operationsStream = new Readable({ objectMode: true, - read(size) {}, + read() {}, }); const p = iterate(); @@ -332,7 +330,7 @@ class Helpers { return { semaphore, finish }; function finish() { - return new Promise((resolve, reject) => { + return new Promise((resolve) => { if (running === 0) { resolve(); } else { @@ -346,7 +344,7 @@ class Helpers { running += 1; return pImmediate(send); } else { - return new Promise((resolve, reject) => { + return new Promise((resolve) => { resolveSemaphore = resolve; }); } @@ -648,7 +646,7 @@ class Helpers { running += 1; return pImmediate(send); } else { - return new Promise((resolve, reject) => { + return new Promise((resolve) => { resolveSemaphore = resolve; }); } diff --git a/lib/Transport.js b/lib/Transport.js index f25e9f82d..69e78d32c 100644 --- a/lib/Transport.js +++ b/lib/Transport.js @@ -682,7 +682,7 @@ function randomSelector(connections) { function generateRequestId() { const maxInt = 2147483647; let nextReqId = 0; - return function genReqId(params, options) { + return function genReqId() { return (nextReqId = (nextReqId + 1) & maxInt); }; } diff --git a/scripts/release-canary.js b/scripts/release-canary.js index 6cc9dc88b..5f51348c2 100644 --- a/scripts/release-canary.js +++ b/scripts/release-canary.js @@ -90,8 +90,8 @@ async function release(opts) { await writeFile(join(__dirname, '..', '.npmignore'), originalNpmIgnore, 'utf8'); } -function confirm(question) { - return new Promise((resolve, reject) => { +function confirm() { + return new Promise((resolve) => { const rl = readline.createInterface({ input: process.stdin, output: process.stdout, diff --git a/scripts/utils/generateApis.js b/scripts/utils/generateApis.js index 496697537..4d83da36f 100644 --- a/scripts/utils/generateApis.js +++ b/scripts/utils/generateApis.js @@ -267,7 +267,7 @@ function generateSingleApi(version, spec, common) { documentation: generateDocumentation(spec[api], api), }; - function genRequiredChecks(param) { + function genRequiredChecks() { const code = required.map(_genRequiredCheck).concat(_noBody()).filter(Boolean); if (code.length) { @@ -319,7 +319,7 @@ function generateSingleApi(version, spec, common) { : str.replace(/_([a-z])/g, (k) => k[1].toUpperCase()); }; - return acceptedQuerystring.reduce((acc, val, index) => { + return acceptedQuerystring.reduce((acc, val) => { if (toCamelCase(val) !== val) { acc[toCamelCase(val)] = val; } diff --git a/test/acceptance/events-order.test.js b/test/acceptance/events-order.test.js index 7030823a9..ac0795aac 100644 --- a/test/acceptance/events-order.test.js +++ b/test/acceptance/events-order.test.js @@ -57,27 +57,27 @@ test('No errors', (t) => { const order = [events.SERIALIZATION, events.REQUEST, events.DESERIALIZATION, events.RESPONSE]; - client.on(events.SERIALIZATION, (err, request) => { + client.on(events.SERIALIZATION, (err) => { t.error(err); t.equal(order.shift(), events.SERIALIZATION); }); - client.on(events.REQUEST, (err, request) => { + client.on(events.REQUEST, (err) => { t.error(err); t.equal(order.shift(), events.REQUEST); }); - client.on(events.DESERIALIZATION, (err, request) => { + client.on(events.DESERIALIZATION, (err) => { t.error(err); t.equal(order.shift(), events.DESERIALIZATION); }); - client.on(events.RESPONSE, (err, request) => { + client.on(events.RESPONSE, (err) => { t.error(err); t.equal(order.shift(), events.RESPONSE); }); - client.info((err, result) => { + client.info((err) => { t.error(err); t.equal(order.length, 0); }); @@ -94,26 +94,26 @@ test('Connection error', (t) => { const order = [events.SERIALIZATION, events.REQUEST, events.REQUEST, events.RESPONSE]; - client.on(events.SERIALIZATION, (err, request) => { + client.on(events.SERIALIZATION, (err) => { t.error(err); t.equal(order.shift(), events.SERIALIZATION); }); - client.on(events.REQUEST, (err, request) => { + client.on(events.REQUEST, (err) => { t.error(err); t.equal(order.shift(), events.REQUEST); }); - client.on(events.DESERIALIZATION, (_err, request) => { + client.on(events.DESERIALIZATION, () => { t.fail('Should not be called'); }); - client.on(events.RESPONSE, (err, request) => { + client.on(events.RESPONSE, (err) => { t.ok(err instanceof ConnectionError); t.equal(order.shift(), events.RESPONSE); }); - client.info((err, result) => { + client.info((err) => { t.ok(err instanceof ConnectionError); t.equal(order.length, 0); }); @@ -130,26 +130,26 @@ test('TimeoutError error', (t) => { const order = [events.SERIALIZATION, events.REQUEST, events.REQUEST, events.RESPONSE]; - client.on(events.SERIALIZATION, (err, request) => { + client.on(events.SERIALIZATION, (err) => { t.error(err); t.equal(order.shift(), events.SERIALIZATION); }); - client.on(events.REQUEST, (err, request) => { + client.on(events.REQUEST, (err) => { t.error(err); t.equal(order.shift(), events.REQUEST); }); - client.on(events.DESERIALIZATION, (_err, request) => { + client.on(events.DESERIALIZATION, () => { t.fail('Should not be called'); }); - client.on(events.RESPONSE, (err, request) => { + client.on(events.RESPONSE, (err) => { t.ok(err instanceof TimeoutError); t.equal(order.shift(), events.RESPONSE); }); - client.info((err, result) => { + client.info((err) => { t.ok(err instanceof TimeoutError); t.equal(order.length, 0); }); @@ -166,26 +166,26 @@ test('RequestAbortedError error', (t) => { const order = [events.SERIALIZATION, events.REQUEST, events.RESPONSE]; - client.on(events.SERIALIZATION, (err, request) => { + client.on(events.SERIALIZATION, (err) => { t.error(err); t.equal(order.shift(), events.SERIALIZATION); }); - client.on(events.REQUEST, (err, request) => { + client.on(events.REQUEST, (err) => { t.error(err); t.equal(order.shift(), events.REQUEST); }); - client.on(events.DESERIALIZATION, (_err, request) => { + client.on(events.DESERIALIZATION, () => { t.fail('Should not be called'); }); - client.on(events.RESPONSE, (err, request) => { + client.on(events.RESPONSE, (err) => { t.ok(err instanceof RequestAbortedError); t.equal(order.shift(), events.RESPONSE); }); - const request = client.info((err, result) => { + const request = client.info((err) => { t.ok(err instanceof RequestAbortedError); t.equal(order.length, 0); }); @@ -197,7 +197,7 @@ test('ResponseError error (no retry)', (t) => { t.plan(10); const MockConnection = buildMockConnection({ - onRequest(params) { + onRequest() { return { statusCode: 400, body: { hello: 'world' }, @@ -213,27 +213,27 @@ test('ResponseError error (no retry)', (t) => { const order = [events.SERIALIZATION, events.REQUEST, events.DESERIALIZATION, events.RESPONSE]; - client.on(events.SERIALIZATION, (err, request) => { + client.on(events.SERIALIZATION, (err) => { t.error(err); t.equal(order.shift(), events.SERIALIZATION); }); - client.on(events.REQUEST, (err, request) => { + client.on(events.REQUEST, (err) => { t.error(err); t.equal(order.shift(), events.REQUEST); }); - client.on(events.DESERIALIZATION, (err, request) => { + client.on(events.DESERIALIZATION, (err) => { t.error(err); t.equal(order.shift(), events.DESERIALIZATION); }); - client.on(events.RESPONSE, (err, request) => { + client.on(events.RESPONSE, (err) => { t.ok(err instanceof ResponseError); t.equal(order.shift(), events.RESPONSE); }); - client.info((err, result) => { + client.info((err) => { t.ok(err instanceof ResponseError); t.equal(order.length, 0); }); @@ -243,7 +243,7 @@ test('ResponseError error (with retry)', (t) => { t.plan(14); const MockConnection = buildMockConnection({ - onRequest(params) { + onRequest() { return { statusCode: 504, body: { hello: 'world' }, @@ -266,27 +266,27 @@ test('ResponseError error (with retry)', (t) => { events.RESPONSE, ]; - client.on(events.SERIALIZATION, (err, request) => { + client.on(events.SERIALIZATION, (err) => { t.error(err); t.equal(order.shift(), events.SERIALIZATION); }); - client.on(events.REQUEST, (err, request) => { + client.on(events.REQUEST, (err) => { t.error(err); t.equal(order.shift(), events.REQUEST); }); - client.on(events.DESERIALIZATION, (err, request) => { + client.on(events.DESERIALIZATION, (err) => { t.error(err); t.equal(order.shift(), events.DESERIALIZATION); }); - client.on(events.RESPONSE, (err, request) => { + client.on(events.RESPONSE, (err) => { t.ok(err instanceof ResponseError); t.equal(order.shift(), events.RESPONSE); }); - client.info((err, result) => { + client.info((err) => { t.ok(err instanceof ResponseError); t.equal(order.length, 0); }); @@ -303,27 +303,27 @@ test('Serialization Error', (t) => { const order = [events.SERIALIZATION, events.REQUEST]; - client.on(events.SERIALIZATION, (err, request) => { + client.on(events.SERIALIZATION, (err) => { t.error(err); t.equal(order.shift(), events.SERIALIZATION); }); - client.on(events.REQUEST, (err, request) => { + client.on(events.REQUEST, (err) => { t.ok(err instanceof SerializationError); t.equal(order.shift(), events.REQUEST); }); - client.on(events.DESERIALIZATION, (_err, request) => { + client.on(events.DESERIALIZATION, () => { t.fail('Should not be called'); }); - client.on(events.RESPONSE, (_err, request) => { + client.on(events.RESPONSE, () => { t.fail('Should not be called'); }); const body = {}; body.o = body; - client.index({ index: 'test', body }, (err, result) => { + client.index({ index: 'test', body }, (err) => { t.ok(err instanceof SerializationError); t.equal(order.length, 0); }); @@ -357,27 +357,27 @@ test('Deserialization Error', (t) => { const order = [events.SERIALIZATION, events.REQUEST, events.DESERIALIZATION, events.RESPONSE]; - client.on(events.SERIALIZATION, (err, request) => { + client.on(events.SERIALIZATION, (err) => { t.error(err); t.equal(order.shift(), events.SERIALIZATION); }); - client.on(events.REQUEST, (err, request) => { + client.on(events.REQUEST, (err) => { t.error(err); t.equal(order.shift(), events.REQUEST); }); - client.on(events.DESERIALIZATION, (err, request) => { + client.on(events.DESERIALIZATION, (err) => { t.error(err); t.equal(order.shift(), events.DESERIALIZATION); }); - client.on(events.RESPONSE, (err, request) => { + client.on(events.RESPONSE, (err) => { t.ok(err instanceof DeserializationError); t.equal(order.shift(), events.RESPONSE); }); - client.info((err, result) => { + client.info((err) => { t.ok(err instanceof DeserializationError); t.equal(order.length, 0); }); @@ -408,27 +408,27 @@ test('Socket destroyed while reading the body', (t) => { events.RESPONSE, ]; - client.on(events.SERIALIZATION, (err, request) => { + client.on(events.SERIALIZATION, (err) => { t.error(err); t.equal(order.shift(), events.SERIALIZATION); }); - client.on(events.REQUEST, (err, request) => { + client.on(events.REQUEST, (err) => { t.error(err); t.equal(order.shift(), events.REQUEST); }); - client.on(events.DESERIALIZATION, (err, request) => { + client.on(events.DESERIALIZATION, (err) => { t.error(err); t.equal(order.shift(), events.DESERIALIZATION); }); - client.on(events.RESPONSE, (err, request) => { + client.on(events.RESPONSE, (err) => { t.ok(err instanceof ConnectionError); t.equal(order.shift(), events.RESPONSE); }); - client.info((err, result) => { + client.info((err) => { t.ok(err instanceof ConnectionError); t.equal(order.length, 0); server.stop(); diff --git a/test/acceptance/resurrect.test.js b/test/acceptance/resurrect.test.js index 6f8f12fd7..8a66b6cce 100644 --- a/test/acceptance/resurrect.test.js +++ b/test/acceptance/resurrect.test.js @@ -82,7 +82,7 @@ test('Should execute the recurrect API with the ping strategy', (t) => { }); q.add((q, done) => { - client.info((err, result) => { + client.info((err) => { t.ok(err); done(); }); @@ -90,7 +90,7 @@ test('Should execute the recurrect API with the ping strategy', (t) => { q.add((q, done) => { clock.tick(1000 * 61); - client.info((err, result) => { + client.info((err) => { t.error(err); done(); }); @@ -146,7 +146,7 @@ test('Resurrect a node and handle 502/3/4 status code', (t) => { }); q.add((q, done) => { - client.info((err, result) => { + client.info((err) => { t.ok(err); done(); }); @@ -154,7 +154,7 @@ test('Resurrect a node and handle 502/3/4 status code', (t) => { q.add((q, done) => { clock.tick(1000 * 61); - client.info((err, result) => { + client.info((err) => { t.error(err); done(); }); @@ -162,7 +162,7 @@ test('Resurrect a node and handle 502/3/4 status code', (t) => { q.add((q, done) => { clock.tick(1000 * 10 * 60); - client.info((err, result) => { + client.info((err) => { t.error(err); done(); }); @@ -211,7 +211,7 @@ test('Should execute the recurrect API with the optimistic strategy', (t) => { }); q.add((q, done) => { - client.info((err, result) => { + client.info((err) => { t.ok(err); done(); }); @@ -219,7 +219,7 @@ test('Should execute the recurrect API with the optimistic strategy', (t) => { q.add((q, done) => { clock.tick(1000 * 61); - client.info((err, result) => { + client.info((err) => { t.error(err); done(); }); diff --git a/test/acceptance/sniff.test.js b/test/acceptance/sniff.test.js index ea2896a79..6fbc95f41 100644 --- a/test/acceptance/sniff.test.js +++ b/test/acceptance/sniff.test.js @@ -238,7 +238,7 @@ test('Sniff interval', (t) => { test('Sniff on start', (t) => { t.plan(4); - buildCluster(({ nodes, shutdown, kill }) => { + buildCluster(({ nodes, shutdown }) => { const client = new Client({ node: nodes[Object.keys(nodes)[0]].url, sniffOnStart: true, @@ -259,7 +259,7 @@ test('Sniff on start', (t) => { test('Should not close living connections', (t) => { t.plan(3); - buildCluster(({ nodes, shutdown, kill }) => { + buildCluster(({ nodes, shutdown }) => { class MyConnection extends Connection { close() { t.fail('Should not be called'); @@ -287,7 +287,7 @@ test('Should not close living connections', (t) => { test('Sniff on connection fault', (t) => { t.plan(5); - buildCluster(({ nodes, shutdown, kill }) => { + buildCluster(({ nodes, shutdown }) => { class MyConnection extends Connection { request(params, callback) { if (this.id === 'http://localhost:9200/') { @@ -315,7 +315,7 @@ test('Sniff on connection fault', (t) => { t.equal(reason, Transport.sniffReasons.SNIFF_ON_CONNECTION_FAULT); }); - client.info((err, result) => { + client.info((err) => { t.ok(err instanceof errors.ConnectionError); }); diff --git a/test/benchmarks/micro/basic.bench.js b/test/benchmarks/micro/basic.bench.js index 33c6eb8fa..47766d5e1 100644 --- a/test/benchmarks/micro/basic.bench.js +++ b/test/benchmarks/micro/basic.bench.js @@ -24,7 +24,7 @@ const { connection } = require('../../utils'); bench('Initialization', { warmup: 5, measure: 10, iterations: 1000 }, async (b) => { b.start(); for (let i = 0; i < b.iterations; i++) { - const client = new Client({ + new Client({ // eslint-disable-line node: 'http://localhost:9200', }); diff --git a/test/benchmarks/suite.js b/test/benchmarks/suite.js index 2baf27469..1e171c130 100644 --- a/test/benchmarks/suite.js +++ b/test/benchmarks/suite.js @@ -125,7 +125,7 @@ function buildBenchmark(options = {}) { } // task that elaborate the collected stats - async function elaborateStats(q) { + async function elaborateStats() { const times = stats[title].map((s) => s.milliseconds / b.iterations); reports.push({ description: title, diff --git a/test/bundlers/parcel-test/index.js b/test/bundlers/parcel-test/index.js index d122d9c47..55fac2b21 100644 --- a/test/bundlers/parcel-test/index.js +++ b/test/bundlers/parcel-test/index.js @@ -13,6 +13,6 @@ const { Client } = require('../../../index'); const client = new Client({ node: 'http://localhost:9200' }); -client.info((err, result) => { +client.info((err) => { process.exit(err ? 1 : 0); }); diff --git a/test/bundlers/rollup-test/index.js b/test/bundlers/rollup-test/index.js index d122d9c47..55fac2b21 100644 --- a/test/bundlers/rollup-test/index.js +++ b/test/bundlers/rollup-test/index.js @@ -13,6 +13,6 @@ const { Client } = require('../../../index'); const client = new Client({ node: 'http://localhost:9200' }); -client.info((err, result) => { +client.info((err) => { process.exit(err ? 1 : 0); }); diff --git a/test/bundlers/webpack-test/index.js b/test/bundlers/webpack-test/index.js index d122d9c47..55fac2b21 100644 --- a/test/bundlers/webpack-test/index.js +++ b/test/bundlers/webpack-test/index.js @@ -13,6 +13,6 @@ const { Client } = require('../../../index'); const client = new Client({ node: 'http://localhost:9200' }); -client.info((err, result) => { +client.info((err) => { process.exit(err ? 1 : 0); }); diff --git a/test/integration/helpers-secure/search.test.js b/test/integration/helpers-secure/search.test.js index 1f672d3e8..8e003ac9e 100644 --- a/test/integration/helpers-secure/search.test.js +++ b/test/integration/helpers-secure/search.test.js @@ -37,7 +37,7 @@ beforeEach(async () => { const result = await client.helpers.bulk({ datasource: stream.pipe(split()), refreshOnCompletion: true, - onDocument(doc) { + onDocument() { return { index: { _index: INDEX }, }; diff --git a/test/integration/helpers/bulk.test.js b/test/integration/helpers/bulk.test.js index 15521ffa7..46b8f27b0 100644 --- a/test/integration/helpers/bulk.test.js +++ b/test/integration/helpers/bulk.test.js @@ -57,10 +57,10 @@ test('bulk index', async (t) => { const result = await client.helpers.bulk({ datasource: stream.pipe(split()), refreshOnCompletion: INDEX, - onDrop(doc) { + onDrop() { t.fail('It should not drop any document'); }, - onDocument(doc) { + onDocument() { return { index: { _index: INDEX }, }; @@ -85,7 +85,7 @@ test('bulk index with custom id', async (t) => { const stream = createReadStream(datasetPath); const result = await client.helpers.bulk({ datasource: stream.pipe(split(JSON.parse)), - onDrop(doc) { + onDrop() { t.fail('It should not drop any document'); }, onDocument(doc) { @@ -159,7 +159,7 @@ test('bulk delete', async (t) => { const indexResult = await client.helpers.bulk({ datasource: createReadStream(datasetPath).pipe(split(JSON.parse)), refreshOnCompletion: true, - onDrop(doc) { + onDrop() { t.fail('It should not drop any document'); }, onDocument(doc) { @@ -188,7 +188,7 @@ test('bulk delete', async (t) => { const deleteResult = await client.helpers.bulk({ datasource: createReadStream(datasetPath).pipe(split(JSON.parse)), refreshOnCompletion: true, - onDrop(doc) { + onDrop() { t.fail('It should not drop any document'); }, onDocument(doc) { diff --git a/test/integration/helpers/msearch.test.js b/test/integration/helpers/msearch.test.js index 6815e13f6..bd566f069 100644 --- a/test/integration/helpers/msearch.test.js +++ b/test/integration/helpers/msearch.test.js @@ -49,7 +49,7 @@ beforeEach(async () => { const result = await client.helpers.bulk({ datasource: stream.pipe(split()), refreshOnCompletion: true, - onDocument(doc) { + onDocument() { return { index: { _index: INDEX }, }; @@ -90,7 +90,7 @@ test('Bad request', (t) => { t.equal(result.body.hits.total.value, 106); }); - m.search({ index: INDEX }, { query: { foo: { title: 'ruby' } } }, (err, result) => { + m.search({ index: INDEX }, { query: { foo: { title: 'ruby' } } }, (err) => { t.ok(err instanceof errors.ResponseError); }); diff --git a/test/integration/helpers/scroll.test.js b/test/integration/helpers/scroll.test.js index 54cb46528..edb5fca5d 100644 --- a/test/integration/helpers/scroll.test.js +++ b/test/integration/helpers/scroll.test.js @@ -49,7 +49,7 @@ beforeEach(async () => { const result = await client.helpers.bulk({ datasource: stream.pipe(split()), refreshOnCompletion: true, - onDocument(doc) { + onDocument() { return { index: { _index: INDEX }, }; diff --git a/test/integration/helpers/search.test.js b/test/integration/helpers/search.test.js index fc3a3307b..92995ccd5 100644 --- a/test/integration/helpers/search.test.js +++ b/test/integration/helpers/search.test.js @@ -49,7 +49,7 @@ beforeEach(async () => { const result = await client.helpers.bulk({ datasource: stream.pipe(split()), refreshOnCompletion: true, - onDocument(doc) { + onDocument() { return { index: { _index: INDEX }, }; diff --git a/test/unit/api.test.js b/test/unit/api.test.js index 058bb60bd..6c1281b9a 100644 --- a/test/unit/api.test.js +++ b/test/unit/api.test.js @@ -106,7 +106,7 @@ test('Error (callback)', (t) => { index: 'test', q: 'foo:bar', }, - (err, { body }) => { + (err) => { t.ok(err); server.stop(); } @@ -306,7 +306,7 @@ test('If the API uses the same key for both url and query parameter, the url sho index: 'index', body: [], }, - (err, { body, warnings }) => { + (err) => { t.error(err); server.stop(); } @@ -325,7 +325,7 @@ test('ConfigurationError (callback)', (t) => { { body: { foo: 'bar' }, }, - (err, { body }) => { + (err) => { t.ok(err instanceof errors.ConfigurationError); } ); @@ -353,7 +353,7 @@ test('The callback with a sync error should be called in the next tick', (t) => node: 'http://localhost:9200', }); - const transportReturn = client.index({ body: { foo: 'bar' } }, (err, result) => { + const transportReturn = client.index({ body: { foo: 'bar' } }, (err) => { t.ok(err instanceof errors.ConfigurationError); }); diff --git a/test/unit/child.test.js b/test/unit/child.test.js index 854c95e7f..4a08e059e 100644 --- a/test/unit/child.test.js +++ b/test/unit/child.test.js @@ -61,9 +61,9 @@ test('Should create a child client (headers check)', (t) => { headers: { 'x-baz': 'faz' }, }); - client.info((err, res) => { + client.info((err) => { t.error(err); - child.info((err, res) => { + child.info((err) => { t.error(err); server.stop(); }); @@ -85,9 +85,9 @@ test('Should create a child client (timeout check)', (t) => { const client = new Client({ node: `http://localhost:${port}` }); const child = client.child({ requestTimeout: 25, maxRetries: 0 }); - client.info((err, res) => { + client.info((err) => { t.error(err); - child.info((err, res) => { + child.info((err) => { t.ok(err instanceof errors.TimeoutError); server.stop(); }); @@ -156,11 +156,11 @@ test('Should share the event emitter', (t) => { }); const child = client.child(); - client.on('response', (err, meta) => { + client.on('response', (err) => { t.error(err); }); - child.info((err, res) => { + child.info((err) => { t.error(err); }); }); @@ -175,11 +175,11 @@ test('Should share the event emitter', (t) => { const child = client.child(); const grandchild = child.child(); - client.on('response', (err, meta) => { + client.on('response', (err) => { t.error(err); }); - grandchild.info((err, res) => { + grandchild.info((err) => { t.error(err); }); }); @@ -193,11 +193,11 @@ test('Should share the event emitter', (t) => { }); const child = client.child(); - child.on('response', (err, meta) => { + child.on('response', (err) => { t.error(err); }); - child.info((err, res) => { + child.info((err) => { t.error(err); }); }); @@ -212,11 +212,11 @@ test('Should share the event emitter', (t) => { const child = client.child(); const grandchild = child.child(); - child.on('response', (err, meta) => { + child.on('response', (err) => { t.error(err); }); - grandchild.info((err, res) => { + grandchild.info((err) => { t.error(err); }); }); @@ -310,9 +310,9 @@ test('Should create a child client (auth check)', (t) => { }, }); - client.info((err, res) => { + client.info((err) => { t.error(err); - child.info((err, res) => { + child.info((err) => { t.error(err); server.stop(); }); diff --git a/test/unit/client.test.js b/test/unit/client.test.js index e90205d91..d78a071ee 100644 --- a/test/unit/client.test.js +++ b/test/unit/client.test.js @@ -657,7 +657,7 @@ test('Extend client APIs', (t) => { node: 'http://localhost:9200', Transport: MyTransport, }); - client.extend('method', ({ makeRequest, result, ConfigurationError }) => { + client.extend('method', ({ makeRequest }) => { return (params, options) => makeRequest(params, options); }); @@ -668,7 +668,7 @@ test('Extend client APIs', (t) => { t.plan(2); const client = new Client({ node: 'http://localhost:9200' }); - client.extend('method', ({ makeRequest, result, ConfigurationError }) => { + client.extend('method', () => { return (params, options, callback) => { callback(null, { hello: 'world' }); }; @@ -684,9 +684,9 @@ test('Extend client APIs', (t) => { t.plan(1); const client = new Client({ node: 'http://localhost:9200' }); - client.extend('method', ({ makeRequest, result, ConfigurationError }) => { - return (params, options) => { - return new Promise((resolve, reject) => { + client.extend('method', () => { + return () => { + return new Promise((resolve) => { resolve({ hello: 'world' }); }); }; @@ -935,7 +935,7 @@ test('Bad content length', (t) => { buildServer(handler, ({ port }, server) => { const client = new Client({ node: `http://localhost:${port}`, maxRetries: 1 }); - client.info((err, { body }) => { + client.info((err) => { t.ok(err instanceof errors.ConnectionError); t.equal(err.message, 'Response aborted while reading the body'); t.equal(count, 2); @@ -961,7 +961,7 @@ test('Socket destryed while reading the body', (t) => { buildServer(handler, ({ port }, server) => { const client = new Client({ node: `http://localhost:${port}`, maxRetries: 1 }); - client.info((err, { body }) => { + client.info((err) => { t.ok(err instanceof errors.ConnectionError); t.equal(err.message, 'Response aborted while reading the body'); t.equal(count, 2); @@ -1113,7 +1113,7 @@ test('Prototype poisoning protection enabled by default', (t) => { Connection: MockConnection, }); - client.info((err, result) => { + client.info((err) => { t.ok(err instanceof errors.DeserializationError); }); }); @@ -1142,7 +1142,7 @@ test('Disable prototype poisoning protection', (t) => { disablePrototypePoisoningProtection: true, }); - client.info((err, result) => { + client.info((err) => { t.error(err); }); }); @@ -1203,7 +1203,7 @@ test('Issue #253 with promises', async (t) => { const delay = () => new Promise((resolve) => setTimeout(resolve, 10)); const MockConnection = buildMockConnection({ - onRequest(params) { + onRequest() { return { statusCode: 200, headers: {}, @@ -1248,7 +1248,7 @@ test('Issue #253 with callbacks', (t) => { const delay = () => new Promise((resolve) => setTimeout(resolve, 10)); const MockConnection = buildMockConnection({ - onRequest(params) { + onRequest() { return { statusCode: 200, headers: {}, @@ -1279,7 +1279,7 @@ test('Issue #253 with callbacks', (t) => { Connection: MockConnection, }); - client.search({}, (err, result) => { + client.search({}, (err) => { t.error(err); }); }); diff --git a/test/unit/connection.test.js b/test/unit/connection.test.js index 38ad78477..48474dfb8 100644 --- a/test/unit/connection.test.js +++ b/test/unit/connection.test.js @@ -289,7 +289,7 @@ test('Timeout support', (t) => { method: 'GET', timeout: 500, }, - (err, res) => { + (err) => { t.ok(err instanceof TimeoutError); server.stop(); } @@ -316,7 +316,7 @@ test('querystring', (t) => { method: 'GET', querystring: 'hello=world&you_know=for%20search', }, - (err, res) => { + (err) => { t.error(err); server.stop(); } @@ -342,7 +342,7 @@ test('querystring', (t) => { method: 'GET', querystring: null, }, - (err, res) => { + (err) => { t.error(err); server.stop(); } @@ -379,7 +379,7 @@ test('Body request', (t) => { method: 'POST', body: 'hello', }, - (err, res) => { + (err) => { t.error(err); server.stop(); } @@ -413,7 +413,7 @@ test('Send body as buffer', (t) => { method: 'POST', body: Buffer.from('hello'), }, - (err, res) => { + (err) => { t.error(err); server.stop(); } @@ -447,7 +447,7 @@ test('Send body as stream', (t) => { method: 'POST', body: intoStream('hello'), }, - (err, res) => { + (err) => { t.error(err); server.stop(); } @@ -558,7 +558,7 @@ test('Url with auth', (t) => { path: '/hello', method: 'GET', }, - (err, res) => { + (err) => { t.error(err); server.stop(); } @@ -584,7 +584,7 @@ test('Url with querystring', (t) => { method: 'GET', querystring: 'baz=faz', }, - (err, res) => { + (err) => { t.error(err); server.stop(); } @@ -616,7 +616,7 @@ test('Custom headers for connection', (t) => { 'X-Custom-Test': true, }, }, - (err, res) => { + (err) => { t.error(err); // should not update the default t.same(connection.headers, { 'x-foo': 'bar' }); @@ -704,7 +704,7 @@ test('Should disallow two-byte characters in URL path', (t) => { path: '/thisisinvalid\uffe2', method: 'GET', }, - (err, res) => { + (err) => { t.equal(err.message, 'ERR_UNESCAPED_CHARACTERS: /thisisinvalid\uffe2'); } ); @@ -971,7 +971,7 @@ test('Should not add agent and ssl to the serialized connection', (t) => { test('Abort a request syncronously', (t) => { t.plan(1); - function handler(req, res) { + function handler() { t.fail('The server should not be contacted'); } @@ -984,7 +984,7 @@ test('Abort a request syncronously', (t) => { path: '/hello', method: 'GET', }, - (err, res) => { + (err) => { t.ok(err instanceof RequestAbortedError); server.stop(); } @@ -1010,7 +1010,7 @@ test('Abort a request asyncronously', (t) => { path: '/hello', method: 'GET', }, - (err, res) => { + (err) => { t.ok(err instanceof RequestAbortedError); server.stop(); } @@ -1065,7 +1065,7 @@ test('Abort with a slow body', (t) => { }); const slowBody = new Readable({ - read(size) { + read() { setTimeout(() => { this.push('{"size":1, "query":{"match_all":{}}}'); this.push(null); // EOF @@ -1079,7 +1079,7 @@ test('Abort with a slow body', (t) => { path: '/', body: slowBody, }, - (err, response) => { + (err) => { t.ok(err instanceof RequestAbortedError); } ); diff --git a/test/unit/events.test.js b/test/unit/events.test.js index 70ce3e649..566b100b8 100644 --- a/test/unit/events.test.js +++ b/test/unit/events.test.js @@ -80,7 +80,7 @@ test('Should emit a request event when a request is performed', (t) => { index: 'test', q: 'foo:bar', }, - (err, result) => { + (err) => { t.error(err); } ); @@ -128,7 +128,7 @@ test('Should emit a request event once when a request is performed', (t) => { index: 'test', q: 'foo:bar', }, - (err, result) => { + (err) => { t.error(err); } ); @@ -138,7 +138,7 @@ test('Should emit a request event once when a request is performed', (t) => { index: 'test', q: 'foo:bar', }, - (err, result) => { + (err) => { t.error(err); } ); @@ -189,7 +189,7 @@ test('Remove an event', (t) => { index: 'test', q: 'foo:bar', }, - (err, result) => { + (err) => { t.error(err); } ); @@ -199,7 +199,7 @@ test('Remove an event', (t) => { index: 'test', q: 'foo:bar', }, - (err, result) => { + (err) => { t.error(err); } ); @@ -250,7 +250,7 @@ test('Should emit a response event in case of a successful response', (t) => { index: 'test', q: 'foo:bar', }, - (err, result) => { + (err) => { t.error(err); } ); @@ -304,7 +304,7 @@ test('Should emit a response event with the error set', (t) => { { requestTimeout: 500, }, - (err, result) => { + (err) => { t.ok(err instanceof TimeoutError); } ); diff --git a/test/unit/helpers/bulk.test.js b/test/unit/helpers/bulk.test.js index ff5b14d92..1083f6007 100644 --- a/test/unit/helpers/bulk.test.js +++ b/test/unit/helpers/bulk.test.js @@ -73,12 +73,12 @@ test('bulk index', (t) => { datasource: dataset.slice(), flushBytes: 1, concurrency: 1, - onDocument(doc) { + onDocument() { return { index: { _index: 'test' }, }; }, - onDrop(doc) { + onDrop() { t.fail('This should never be called'); }, }); @@ -116,12 +116,12 @@ test('bulk index', (t) => { datasource: dataset.slice(), flushBytes: 1, concurrency: 3, - onDocument(doc) { + onDocument() { return { index: { _index: 'test' }, }; }, - onDrop(doc) { + onDrop() { t.fail('This should never be called'); }, }); @@ -155,12 +155,12 @@ test('bulk index', (t) => { datasource: dataset.slice(), flushBytes: 5000000, concurrency: 1, - onDocument(doc) { + onDocument() { return { index: { _index: 'test' }, }; }, - onDrop(doc) { + onDrop() { t.fail('This should never be called'); }, }); @@ -203,7 +203,7 @@ test('bulk index', (t) => { flushBytes: 1, concurrency: 1, refreshOnCompletion: true, - onDocument(doc) { + onDocument() { return { index: { _index: 'test' }, }; @@ -248,7 +248,7 @@ test('bulk index', (t) => { flushBytes: 1, concurrency: 1, refreshOnCompletion: 'test', - onDocument(doc) { + onDocument() { return { index: { _index: 'test' }, }; @@ -288,7 +288,7 @@ test('bulk index', (t) => { datasource: dataset.slice(), flushBytes: 1, concurrency: 1, - onDocument(doc) { + onDocument() { return { index: { _index: 'test', @@ -296,7 +296,7 @@ test('bulk index', (t) => { }, }; }, - onDrop(doc) { + onDrop() { t.fail('This should never be called'); }, }); @@ -359,7 +359,7 @@ test('bulk index', (t) => { concurrency: 1, wait: 10, retries: 1, - onDocument(doc) { + onDocument() { return { index: { _index: 'test' }, }; @@ -410,7 +410,7 @@ test('bulk index', (t) => { concurrency: 1, wait: 10, retries: 0, - onDocument(doc) { + onDocument() { return { index: { _index: 'test' }, }; @@ -485,7 +485,7 @@ test('bulk index', (t) => { flushBytes: 1, concurrency: 1, wait: 10, - onDocument(doc) { + onDocument() { return { index: { _index: 'test' }, }; @@ -515,7 +515,7 @@ test('bulk index', (t) => { t.test('Server error', async (t) => { const MockConnection = connection.buildMockConnection({ - onRequest(params) { + onRequest() { return { statusCode: 500, body: { somothing: 'went wrong' }, @@ -531,12 +531,12 @@ test('bulk index', (t) => { datasource: dataset.slice(), flushBytes: 1, concurrency: 1, - onDocument(doc) { + onDocument() { return { index: { _index: 'test' }, }; }, - onDrop(doc) { + onDrop() { t.fail('This should never be called'); }, }); @@ -551,7 +551,7 @@ test('bulk index', (t) => { t.test('Server error (high flush size, to trigger the finish error)', async (t) => { const MockConnection = connection.buildMockConnection({ - onRequest(params) { + onRequest() { return { statusCode: 500, body: { somothing: 'went wrong' }, @@ -567,12 +567,12 @@ test('bulk index', (t) => { datasource: dataset.slice(), flushBytes: 5000000, concurrency: 1, - onDocument(doc) { + onDocument() { return { index: { _index: 'test' }, }; }, - onDrop(doc) { + onDrop() { t.fail('This should never be called'); }, }); @@ -632,12 +632,12 @@ test('bulk index', (t) => { flushBytes: 1, concurrency: 1, wait: 10, - onDocument(doc) { + onDocument() { return { index: { _index: 'test' }, }; }, - onDrop(doc) { + onDrop() { b.abort(); }, }); @@ -658,7 +658,7 @@ test('bulk index', (t) => { t.test('Invalid operation', (t) => { t.plan(2); const MockConnection = connection.buildMockConnection({ - onRequest(params) { + onRequest() { return { body: { errors: false, items: [{}] } }; }, }); @@ -672,7 +672,7 @@ test('bulk index', (t) => { datasource: dataset.slice(), flushBytes: 1, concurrency: 1, - onDocument(doc) { + onDocument() { return { foo: { _index: 'test' }, }; @@ -718,7 +718,7 @@ test('bulk index', (t) => { { ...doc, updatedAt }, ]; }, - onDrop(doc) { + onDrop() { t.fail('This should never be called'); }, }); @@ -765,7 +765,7 @@ test('bulk index', (t) => { datasource: stream.pipe(split()), flushBytes: 1, concurrency: 1, - onDocument(doc) { + onDocument() { return { index: { _index: 'test', @@ -773,7 +773,7 @@ test('bulk index', (t) => { }, }; }, - onDrop(doc) { + onDrop() { t.fail('This should never be called'); }, }); @@ -822,12 +822,12 @@ test('bulk index', (t) => { datasource: generator(), flushBytes: 1, concurrency: 1, - onDocument(doc) { + onDocument() { return { index: { _index: 'test' }, }; }, - onDrop(doc) { + onDrop() { t.fail('This should never be called'); }, }); @@ -871,7 +871,7 @@ test('bulk create', (t) => { datasource: dataset.slice(), flushBytes: 1, concurrency: 1, - onDocument(doc) { + onDocument() { return { create: { _index: 'test', @@ -879,7 +879,7 @@ test('bulk create', (t) => { }, }; }, - onDrop(doc) { + onDrop() { t.fail('This should never be called'); }, }); @@ -929,7 +929,7 @@ test('bulk create', (t) => { { ...doc, updatedAt }, ]; }, - onDrop(doc) { + onDrop() { t.fail('This should never be called'); }, }); @@ -971,7 +971,7 @@ test('bulk update', (t) => { datasource: dataset.slice(), flushBytes: 1, concurrency: 1, - onDocument(doc) { + onDocument() { return [ { update: { @@ -984,7 +984,7 @@ test('bulk update', (t) => { }, ]; }, - onDrop(doc) { + onDrop() { t.fail('This should never be called'); }, }); @@ -1022,7 +1022,7 @@ test('bulk update', (t) => { datasource: dataset.map((d) => JSON.stringify(d)), flushBytes: 1, concurrency: 1, - onDocument(doc) { + onDocument() { return [ { update: { @@ -1032,7 +1032,7 @@ test('bulk update', (t) => { }, ]; }, - onDrop(doc) { + onDrop() { t.fail('This should never be called'); }, }); @@ -1070,7 +1070,7 @@ test('bulk update', (t) => { datasource: dataset.slice(), flushBytes: 1, concurrency: 1, - onDocument(doc) { + onDocument() { return [ { update: { @@ -1083,7 +1083,7 @@ test('bulk update', (t) => { }, ]; }, - onDrop(doc) { + onDrop() { t.fail('This should never be called'); }, }); @@ -1124,7 +1124,7 @@ test('bulk delete', (t) => { datasource: dataset.slice(), flushBytes: 1, concurrency: 1, - onDocument(doc) { + onDocument() { return { delete: { _index: 'test', @@ -1132,7 +1132,7 @@ test('bulk delete', (t) => { }, }; }, - onDrop(doc) { + onDrop() { t.fail('This should never be called'); }, }); @@ -1195,7 +1195,7 @@ test('bulk delete', (t) => { flushBytes: 1, concurrency: 1, wait: 10, - onDocument(doc) { + onDocument() { return { delete: { _index: 'test', @@ -1262,10 +1262,10 @@ test('transport options', (t) => { datasource: dataset.slice(), flushBytes: 1, concurrency: 1, - onDocument(doc) { + onDocument() { return { index: { _index: 'test' } }; }, - onDrop(doc) { + onDrop() { t.fail('This should never be called'); }, refreshOnCompletion: true, @@ -1300,7 +1300,7 @@ test('errors', (t) => { try { await client.helpers.bulk({ datasource: 'hello', - onDocument(doc) { + onDocument() { return { index: { _index: 'test' }, }; @@ -1321,7 +1321,7 @@ test('errors', (t) => { }); try { await client.helpers.bulk({ - onDocument(doc) { + onDocument() { return { index: { _index: 'test' }, }; @@ -1381,12 +1381,12 @@ test('Flush interval', (t) => { })(), flushBytes: 5000000, concurrency: 1, - onDocument(doc) { + onDocument() { return { index: { _index: 'test' }, }; }, - onDrop(doc) { + onDrop() { t.fail('This should never be called'); }, }); @@ -1439,12 +1439,12 @@ test('Flush interval', (t) => { })(), flushBytes: 5000000, concurrency: 1, - onDocument(doc) { + onDocument() { return { index: { _index: 'test' }, }; }, - onDrop(doc) { + onDrop() { t.fail('This should never be called'); }, }); @@ -1485,12 +1485,12 @@ test('Flush interval', (t) => { datasource: dataset.slice(), flushBytes: 1, concurrency: 1, - onDocument(doc) { + onDocument() { return { index: { _index: 'test' }, }; }, - onDrop(doc) { + onDrop() { t.fail('This should never be called'); }, }); diff --git a/test/unit/helpers/msearch.test.js b/test/unit/helpers/msearch.test.js index 42bef148f..4945fc080 100644 --- a/test/unit/helpers/msearch.test.js +++ b/test/unit/helpers/msearch.test.js @@ -37,7 +37,7 @@ const FakeTimers = require('@sinonjs/fake-timers'); test('Basic', async (t) => { const MockConnection = connection.buildMockConnection({ - onRequest(params) { + onRequest() { return { body: { responses: [ @@ -86,7 +86,7 @@ test('Multiple searches (inside async iterator)', (t) => { t.plan(6); const MockConnection = connection.buildMockConnection({ - onRequest(params) { + onRequest() { return { body: { responses: [ @@ -162,7 +162,7 @@ test('Multiple searches (async iterator exits)', (t) => { t.plan(6); const MockConnection = connection.buildMockConnection({ - onRequest(params) { + onRequest() { return { body: { responses: [ @@ -236,7 +236,7 @@ test('Multiple searches (async iterator exits)', (t) => { test('Stop a msearch processor (promises)', async (t) => { const MockConnection = connection.buildMockConnection({ - onRequest(params) { + onRequest() { return {}; }, }); @@ -263,7 +263,7 @@ test('Stop a msearch processor (callbacks)', (t) => { t.plan(1); const MockConnection = connection.buildMockConnection({ - onRequest(params) { + onRequest() { return {}; }, }); @@ -277,7 +277,7 @@ test('Stop a msearch processor (callbacks)', (t) => { m.stop(); - m.search({ index: 'test' }, { query: { match: { foo: 'bar' } } }, (err, result) => { + m.search({ index: 'test' }, { query: { match: { foo: 'bar' } } }, (err) => { t.equal(err.message, 'The msearch processor has been stopped'); }); }); @@ -286,7 +286,7 @@ test('Bad header', (t) => { t.plan(2); const MockConnection = connection.buildMockConnection({ - onRequest(params) { + onRequest() { return {}; }, }); @@ -298,7 +298,7 @@ test('Bad header', (t) => { const m = client.helpers.msearch(); - m.search(null, { query: { match: { foo: 'bar' } } }, (err, result) => { + m.search(null, { query: { match: { foo: 'bar' } } }, (err) => { t.equal(err.message, 'The header should be an object'); }); @@ -313,7 +313,7 @@ test('Bad body', (t) => { t.plan(2); const MockConnection = connection.buildMockConnection({ - onRequest(params) { + onRequest() { return {}; }, }); @@ -325,7 +325,7 @@ test('Bad body', (t) => { const m = client.helpers.msearch(); - m.search({ index: 'test' }, null, (err, result) => { + m.search({ index: 'test' }, null, (err) => { t.equal(err.message, 'The body should be an object'); }); @@ -339,7 +339,7 @@ test('Bad body', (t) => { test('Retry on 429', async (t) => { let count = 0; const MockConnection = connection.buildMockConnection({ - onRequest(params) { + onRequest() { if (count++ === 0) { return { body: { @@ -399,7 +399,7 @@ test('Retry on 429', async (t) => { test('Single search errors', async (t) => { const MockConnection = connection.buildMockConnection({ - onRequest(params) { + onRequest() { return { body: { responses: [ @@ -433,7 +433,7 @@ test('Entire msearch fails', (t) => { t.plan(4); const MockConnection = connection.buildMockConnection({ - onRequest(params) { + onRequest() { return { statusCode: 500, body: { @@ -468,7 +468,7 @@ test('Resolves the msearch helper', (t) => { t.plan(1); const MockConnection = connection.buildMockConnection({ - onRequest(params) { + onRequest() { return {}; }, }); @@ -484,17 +484,17 @@ test('Resolves the msearch helper', (t) => { m.then( () => t.pass('called'), - (e) => t.fail('Should not fail') + () => t.fail('Should not fail') ); - m.catch((e) => t.fail('Should not fail')); + m.catch(() => t.fail('Should not fail')); }); test('Stop the msearch helper with an error', (t) => { t.plan(3); const MockConnection = connection.buildMockConnection({ - onRequest(params) { + onRequest() { return {}; }, }); @@ -515,7 +515,7 @@ test('Stop the msearch helper with an error', (t) => { m.catch((err) => t.equal(err.message, 'kaboom')); - m.search({ index: 'test' }, { query: {} }, (err, result) => { + m.search({ index: 'test' }, { query: {} }, (err) => { t.equal(err.message, 'kaboom'); }); }); @@ -524,7 +524,7 @@ test('Multiple searches (concurrency = 1)', (t) => { t.plan(6); const MockConnection = connection.buildMockConnection({ - onRequest(params) { + onRequest() { return { body: { responses: [ @@ -592,7 +592,7 @@ test('Flush interval', (t) => { t.teardown(() => clock.uninstall()); const MockConnection = connection.buildMockConnection({ - onRequest(params) { + onRequest() { return { body: { responses: [ @@ -648,7 +648,7 @@ test('Flush interval - early stop', (t) => { t.plan(3); const MockConnection = connection.buildMockConnection({ - onRequest(params) { + onRequest() { return { body: { responses: [ @@ -681,7 +681,7 @@ test('Flush interval - early stop', (t) => { }); setImmediate(() => { - m.search({ index: 'test' }, { query: { match: { foo: 'bar' } } }, (err, result) => { + m.search({ index: 'test' }, { query: { match: { foo: 'bar' } } }, (err) => { t.ok(err instanceof errors.ConfigurationError); }); }); @@ -693,7 +693,7 @@ test('Stop should resolve the helper', (t) => { t.plan(1); const MockConnection = connection.buildMockConnection({ - onRequest(params) { + onRequest() { return { body: { responses: [], @@ -717,7 +717,7 @@ test('Stop should resolve the helper (error)', (t) => { t.plan(3); const MockConnection = connection.buildMockConnection({ - onRequest(params) { + onRequest() { return { body: { responses: [], diff --git a/test/unit/helpers/scroll.test.js b/test/unit/helpers/scroll.test.js index 13731691f..17c705cad 100644 --- a/test/unit/helpers/scroll.test.js +++ b/test/unit/helpers/scroll.test.js @@ -191,7 +191,7 @@ test('Scroll search (retry throws and maxRetries)', async (t) => { const expectedAttempts = maxRetries + 1; let count = 0; const MockConnection = connection.buildMockConnection({ - onRequest(params) { + onRequest() { count += 1; return { body: {}, statusCode: 429 }; }, @@ -215,8 +215,8 @@ test('Scroll search (retry throws and maxRetries)', async (t) => { ); try { + // eslint-disable-next-line no-unused-vars for await (const result of scrollSearch) { - // eslint-disable-line t.fail('we should not be here'); } } catch (err) { @@ -340,7 +340,7 @@ test('Should not retry if maxRetries = 0', async (t) => { const expectedAttempts = 1; let count = 0; const MockConnection = connection.buildMockConnection({ - onRequest(params) { + onRequest() { count += 1; return { body: {}, statusCode: 429 }; }, @@ -364,8 +364,8 @@ test('Should not retry if maxRetries = 0', async (t) => { ); try { + // eslint-disable-next-line no-unused-vars for await (const result of scrollSearch) { - // eslint-disable-line t.fail('we should not be here'); } } catch (err) { diff --git a/test/unit/lib/aws/awssigv4signer.test.js b/test/unit/lib/aws/awssigv4signer.test.js index c895c4915..1665045a7 100644 --- a/test/unit/lib/aws/awssigv4signer.test.js +++ b/test/unit/lib/aws/awssigv4signer.test.js @@ -390,7 +390,7 @@ test('Basic aws failure to refresh credentials', (t) => { index: 'test', q: 'foo:bar', }) - .then(({ body }) => { + .then(() => { t.same(getCredentialsCalled, 2); t.fail('Should fail'); }) diff --git a/test/unit/transport.test.js b/test/unit/transport.test.js index c60ee5e0e..5a49d989a 100644 --- a/test/unit/transport.test.js +++ b/test/unit/transport.test.js @@ -452,7 +452,7 @@ test('NoLivingConnectionsError (null connection)', (t) => { method: 'GET', path: '/hello', }, - (err, { body }) => { + (err) => { t.ok(err instanceof NoLivingConnectionsError); } ); @@ -484,7 +484,7 @@ test('NoLivingConnectionsError (undefined connection)', (t) => { method: 'GET', path: '/hello', }, - (err, { body }) => { + (err) => { t.ok(err instanceof NoLivingConnectionsError); } ); @@ -514,7 +514,7 @@ test('SerializationError', (t) => { path: '/hello', body, }, - (err, { body }) => { + (err) => { t.ok(err instanceof SerializationError); } ); @@ -544,7 +544,7 @@ test('SerializationError (bulk)', (t) => { path: '/hello', bulkBody, }, - (err, { body }) => { + (err) => { t.ok(err instanceof SerializationError); } ); @@ -577,7 +577,7 @@ test('DeserializationError', (t) => { method: 'GET', path: '/hello', }, - (err, { body }) => { + (err) => { t.ok(err instanceof DeserializationError); server.stop(); } @@ -617,7 +617,7 @@ test('TimeoutError (should call markDead on the failing connection)', (t) => { method: 'GET', path: '/hello', }, - (err, { body }) => { + (err) => { t.ok(err instanceof TimeoutError); } ); @@ -655,7 +655,7 @@ test('ConnectionError (should call markDead on the failing connection)', (t) => method: 'GET', path: '/hello', }, - (err, { body }) => { + (err) => { t.ok(err instanceof ConnectionError); } ); @@ -761,7 +761,7 @@ test('Should not retry if the body is a stream', (t) => { path: '/hello', body: intoStream(JSON.stringify({ hello: 'world' })), }, - (err, { body }) => { + (err) => { t.ok(err instanceof ResponseError); t.equal(count, 1); server.stop(); @@ -814,7 +814,7 @@ test('Should not retry if the bulkBody is a stream', (t) => { path: '/hello', bulkBody: intoStream(JSON.stringify([{ hello: 'world' }])), }, - (err, { body }) => { + (err) => { t.ok(err instanceof ResponseError); t.equal(count, 1); server.stop(); @@ -870,7 +870,7 @@ test('No retry', (t) => { { maxRetries: 0, }, - (err, { body }) => { + (err) => { t.ok(err instanceof ResponseError); t.equal(count, 1); server.stop(); @@ -982,7 +982,7 @@ test('Should not retry on 429', (t) => { method: 'GET', path: '/hello', }, - (err, result) => { + (err) => { t.ok(err); t.equal(err.statusCode, 429); server.stop(); @@ -1096,7 +1096,7 @@ test('Should return a request aborter utility', (t) => { method: 'GET', path: '/hello', }, - (err, result) => { + (err) => { t.ok(err instanceof RequestAbortedError); } ); @@ -1152,7 +1152,7 @@ test('Retry mechanism and abort', (t) => { method: 'GET', path: '/hello', }, - (err, result) => { + (err) => { t.ok(err instanceof RequestAbortedError); server.stop(); } @@ -1225,7 +1225,7 @@ test('ResponseError', (t) => { method: 'GET', path: '/hello', }, - (err, { body }) => { + (err) => { t.ok(err instanceof ResponseError); t.same(err.body, { status: 500 }); t.equal(err.statusCode, 500); @@ -1331,7 +1331,7 @@ test('sniff', (t) => { method: 'GET', path: '/', }, - (err, { body }) => { + (err) => { t.ok(err instanceof TimeoutError); } ); @@ -1397,7 +1397,7 @@ test('sniff', (t) => { }); skipCompatibleCheck(transport); - transport.sniff((err, hosts) => { + transport.sniff((err) => { t.ok(err instanceof ConnectionError); }); }); @@ -1439,7 +1439,7 @@ test(`Should mark as dead connections where the statusCode is 502/3/4 method: 'GET', path: `/${statusCode}`, }, - (err, { body }) => { + (err) => { t.ok(err instanceof ResponseError); t.match(err, { body: { hello: 'world' }, @@ -1472,7 +1472,7 @@ test('Should retry the request if the statusCode is 502/3/4', (t) => { } class CustomConnectionPool extends ConnectionPool { - markDead(connection) { + markDead() { t.ok('called'); } } @@ -1546,7 +1546,7 @@ test('Ignore status code', (t) => { method: 'GET', path: '/404', }, - (err, { body }) => { + (err) => { t.ok(err instanceof ResponseError); } ); @@ -1559,7 +1559,7 @@ test('Ignore status code', (t) => { { ignore: [403, 405], }, - (err, { body }) => { + (err) => { t.ok(err instanceof ResponseError); } ); @@ -1597,7 +1597,7 @@ test('Should serialize the querystring', (t) => { you_know: 'for search', }, }, - (err, { body }) => { + (err) => { t.error(err); server.stop(); } @@ -1640,7 +1640,7 @@ test('timeout option', (t) => { method: 'GET', path: '/hello', }, - (err, { body }) => { + (err) => { t.ok(err instanceof TimeoutError); server.stop(); } @@ -1677,7 +1677,7 @@ test('timeout option', (t) => { { requestTimeout: 500, }, - (err, { body }) => { + (err) => { t.ok(err instanceof TimeoutError); server.stop(); } @@ -1715,7 +1715,7 @@ test('timeout option', (t) => { method: 'GET', path: '/hello', }, - (err, { body }) => { + (err) => { t.ok(err instanceof TimeoutError); server.stop(); } @@ -1752,7 +1752,7 @@ test('timeout option', (t) => { { requestTimeout: '0.5s', }, - (err, { body }) => { + (err) => { t.ok(err instanceof TimeoutError); server.stop(); } @@ -1847,7 +1847,7 @@ test('Should cast to boolean HEAD request', (t) => { method: 'HEAD', path: '/400', }, - (err, { body, statusCode }) => { + (err, { statusCode }) => { t.ok(err instanceof ResponseError); t.notOk(typeof err.body === 'boolean'); t.equal(statusCode, 400); @@ -1876,7 +1876,7 @@ test('Should cast to boolean HEAD request', (t) => { method: 'HEAD', path: '/500', }, - (err, { body, statusCode }) => { + (err, { statusCode }) => { t.ok(err instanceof ResponseError); t.notOk(typeof err.body === 'boolean'); t.equal(statusCode, 500); @@ -1966,7 +1966,7 @@ test('Broken compression', (t) => { method: 'GET', path: '/hello', }, - (err, { body }) => { + (err) => { t.ok(err); server.stop(); } @@ -2362,7 +2362,7 @@ test('Compress request', (t) => { path: '/hello', body: '', }, - (err, { body }) => { + (err) => { t.error(err); transport.request( { @@ -2370,7 +2370,7 @@ test('Compress request', (t) => { path: '/hello', body: null, }, - (err, { body }) => { + (err) => { t.error(err); transport.request( { @@ -2378,7 +2378,7 @@ test('Compress request', (t) => { path: '/hello', body: undefined, }, - (err, { body }) => { + (err) => { t.error(err); server.stop(); } @@ -2443,7 +2443,7 @@ test('Compress request', (t) => { { compression: 'gzip', }, - (err, { body, meta }) => { + (err, { body }) => { t.error(err); t.same(body, { you_know: 'for search' }); t.equal(count, 2); @@ -2748,7 +2748,7 @@ test('Should add an User-Agent header', (t) => { method: 'GET', path: '/hello', }, - (err, { body }) => { + (err) => { t.error(err); server.stop(); } @@ -2812,7 +2812,7 @@ test('Secure json parsing', (t) => { method: 'GET', path: '/hello', }, - (err, { body }) => { + (err) => { t.ok(err instanceof DeserializationError); t.equal(err.message, 'Object contains forbidden prototype property'); server.stop(); @@ -2848,7 +2848,7 @@ test('Secure json parsing', (t) => { method: 'GET', path: '/hello', }, - (err, { body }) => { + (err) => { t.ok(err instanceof DeserializationError); t.equal(err.message, 'Object contains forbidden prototype property'); server.stop(); @@ -2920,7 +2920,7 @@ test('The callback with a sync error should be called in the next tick - json', path: '/hello', body, }, - (err, { body }) => { + (err) => { t.ok(err instanceof SerializationError); } ); @@ -2955,7 +2955,7 @@ test('The callback with a sync error should be called in the next tick - ndjson' path: '/hello', bulkBody: [field], }, - (err, { body }) => { + (err) => { t.ok(err instanceof SerializationError); } ); diff --git a/test/utils/buildProxy.js b/test/utils/buildProxy.js index 06ba00f9f..2ff352862 100644 --- a/test/utils/buildProxy.js +++ b/test/utils/buildProxy.js @@ -27,7 +27,7 @@ const ssl = { }; function createProxy() { - return new Promise((resolve, reject) => { + return new Promise((resolve) => { const server = proxy(http.createServer()); server.listen(0, '127.0.0.1', () => { resolve(server); @@ -36,7 +36,7 @@ function createProxy() { } function createSecureProxy() { - return new Promise((resolve, reject) => { + return new Promise((resolve) => { const server = proxy(https.createServer(ssl)); server.listen(0, '127.0.0.1', () => { resolve(server); @@ -44,8 +44,8 @@ function createSecureProxy() { }); } -function createServer(handler, callback) { - return new Promise((resolve, reject) => { +function createServer() { + return new Promise((resolve) => { const server = http.createServer(); server.listen(0, '127.0.0.1', () => { resolve(server); @@ -53,8 +53,8 @@ function createServer(handler, callback) { }); } -function createSecureServer(handler, callback) { - return new Promise((resolve, reject) => { +function createSecureServer() { + return new Promise((resolve) => { const server = https.createServer(ssl); server.listen(0, '127.0.0.1', () => { resolve(server); diff --git a/test/utils/buildServer.js b/test/utils/buildServer.js index 7021379ed..45b51ed1c 100644 --- a/test/utils/buildServer.js +++ b/test/utils/buildServer.js @@ -65,7 +65,7 @@ function buildServer(handler, opts, cb) { process.exit(1); }); if (cb === undefined) { - return new Promise((resolve, reject) => { + return new Promise((resolve) => { server.listen(0, () => { const port = server.address().port; debug(`Server '${serverId}' booted on port ${port}`);