Remove Node.js v8 support (#1402)

This commit is contained in:
Tomas Della Vedova
2021-02-19 08:27:20 +01:00
committed by delvedor
parent 496b2bb6d1
commit 6c2d4acac6
43 changed files with 247 additions and 291 deletions

View File

@ -63,7 +63,7 @@ test('API', t => {
t.test('markDead', t => {
const pool = new BaseConnectionPool({ Connection, sniffEnabled: true })
const href = 'http://localhost:9200/'
var connection = pool.addConnection(href)
let connection = pool.addConnection(href)
t.same(pool.markDead(connection), pool)
connection = pool.connections.find(c => c.id === href)
t.strictEqual(connection.status, Connection.statuses.ALIVE)
@ -73,7 +73,7 @@ test('API', t => {
t.test('markAlive', t => {
const pool = new BaseConnectionPool({ Connection, sniffEnabled: true })
const href = 'http://localhost:9200/'
var connection = pool.addConnection(href)
let connection = pool.addConnection(href)
t.same(pool.markAlive(connection), pool)
connection = pool.connections.find(c => c.id === href)
t.strictEqual(connection.status, Connection.statuses.ALIVE)
@ -96,7 +96,7 @@ test('API', t => {
t.test('removeConnection', t => {
const pool = new BaseConnectionPool({ Connection })
const href = 'http://localhost:9200/'
var connection = pool.addConnection(href)
const connection = pool.addConnection(href)
pool.removeConnection(connection)
t.strictEqual(pool.size, 0)
t.end()

View File

@ -29,7 +29,7 @@ const {
test('Should create a child client (headers check)', t => {
t.plan(4)
var count = 0
let count = 0
function handler (req, res) {
if (count++ === 0) {
t.match(req.headers, { 'x-foo': 'bar' })
@ -216,12 +216,12 @@ test('Should create a child client (generateRequestId check)', t => {
t.plan(6)
function generateRequestId1 () {
var id = 0
let id = 0
return () => `trace-1-${id++}`
}
function generateRequestId2 () {
var id = 0
let id = 0
return () => `trace-2-${id++}`
}
@ -235,7 +235,7 @@ test('Should create a child client (generateRequestId check)', t => {
generateRequestId: generateRequestId2()
})
var count = 0
let count = 0
client.on('request', (err, { meta }) => {
t.error(err)
t.strictEqual(
@ -266,7 +266,7 @@ test('Should create a child client (name check)', t => {
t.strictEqual(client.name, 'parent')
t.strictEqual(child.name, 'child')
var count = 0
let count = 0
client.on('request', (err, { meta }) => {
t.error(err)
t.strictEqual(
@ -284,7 +284,7 @@ test('Should create a child client (name check)', t => {
test('Should create a child client (auth check)', t => {
t.plan(4)
var count = 0
let count = 0
function handler (req, res) {
if (count++ === 0) {
t.match(req.headers, { authorization: 'Basic Zm9vOmJhcg==' })

View File

@ -287,7 +287,7 @@ test('Authentication', t => {
t.test('Custom basic authentication per request', t => {
t.plan(6)
var first = true
let first = true
function handler (req, res) {
t.match(req.headers, {
authorization: first ? 'hello' : 'Basic Zm9vOmJhcg=='
@ -322,7 +322,7 @@ test('Authentication', t => {
t.test('Override default basic authentication per request', t => {
t.plan(6)
var first = true
let first = true
function handler (req, res) {
t.match(req.headers, {
authorization: first ? 'hello' : 'Basic Zm9vOmJhcg=='
@ -419,7 +419,7 @@ test('Authentication', t => {
t.test('Custom ApiKey authentication per request', t => {
t.plan(6)
var first = true
let first = true
function handler (req, res) {
t.match(req.headers, {
authorization: first ? 'ApiKey Zm9vOmJhcg==' : 'Basic Zm9vOmJhcg=='
@ -454,7 +454,7 @@ test('Authentication', t => {
t.test('Override default ApiKey authentication per request', t => {
t.plan(6)
var first = true
let first = true
function handler (req, res) {
t.match(req.headers, {
authorization: first ? 'hello' : 'ApiKey Zm9vOmJhcg=='

View File

@ -66,7 +66,7 @@ test('API', t => {
t.test('markDead', t => {
const pool = new ConnectionPool({ Connection, sniffEnabled: true })
const href = 'http://localhost:9200/'
var connection = pool.addConnection(href)
let connection = pool.addConnection(href)
pool.markDead(connection)
connection = pool.connections.find(c => c.id === href)
t.strictEqual(connection.deadCount, 1)
@ -100,7 +100,7 @@ test('API', t => {
t.test('markAlive', t => {
const pool = new ConnectionPool({ Connection, sniffEnabled: true })
const href = 'http://localhost:9200/'
var connection = pool.addConnection(href)
let connection = pool.addConnection(href)
pool.markDead(connection)
pool.markAlive(connection)
connection = pool.connections.find(c => c.id === href)
@ -121,7 +121,7 @@ test('API', t => {
sniffEnabled: true
})
const href = 'http://localhost:9200/'
var connection = pool.addConnection(href)
const connection = pool.addConnection(href)
pool.markDead(connection)
const opts = {
now: Date.now() + 1000 * 60 * 3,
@ -147,7 +147,7 @@ test('API', t => {
sniffEnabled: true
})
const href = 'http://localhost:9200/'
var connection = pool.addConnection(href)
const connection = pool.addConnection(href)
pool.markDead(connection)
const opts = {
now: Date.now() + 1000 * 60 * 3,
@ -175,7 +175,7 @@ test('API', t => {
sniffEnabled: true
})
const href = 'http://localhost:9200/'
var connection = pool.addConnection(href)
const connection = pool.addConnection(href)
pool.markDead(connection)
const opts = {
now: Date.now() + 1000 * 60 * 3,
@ -200,7 +200,7 @@ test('API', t => {
sniffEnabled: true
})
const href = 'http://localhost:9200/'
var connection = pool.addConnection(href)
const connection = pool.addConnection(href)
pool.markDead(connection)
const opts = {
now: Date.now() + 1000 * 60 * 3,
@ -292,7 +292,7 @@ test('API', t => {
t.test('removeConnection', t => {
const pool = new ConnectionPool({ Connection })
const href = 'http://localhost:9200/'
var connection = pool.addConnection(href)
const connection = pool.addConnection(href)
t.ok(pool.getConnection() instanceof Connection)
pool.removeConnection(connection)
t.strictEqual(pool.getConnection(), null)

View File

@ -58,7 +58,7 @@ test('Basic (http)', t => {
connection: 'keep-alive'
})
var payload = ''
let payload = ''
res.setEncoding('utf8')
res.on('data', chunk => { payload += chunk })
res.on('error', err => t.fail(err))
@ -98,7 +98,7 @@ test('Basic (https)', t => {
connection: 'keep-alive'
})
var payload = ''
let payload = ''
res.setEncoding('utf8')
res.on('data', chunk => { payload += chunk })
res.on('error', err => t.fail(err))
@ -139,7 +139,7 @@ test('Basic (https with ssl agent)', t => {
connection: 'keep-alive'
})
var payload = ''
let payload = ''
res.setEncoding('utf8')
res.on('data', chunk => { payload += chunk })
res.on('error', err => t.fail(err))
@ -193,7 +193,7 @@ test('Custom http agent', t => {
connection: 'keep-alive'
})
var payload = ''
let payload = ''
res.setEncoding('utf8')
res.on('data', chunk => { payload += chunk })
res.on('error', err => t.fail(err))
@ -317,7 +317,7 @@ test('Body request', t => {
t.plan(2)
function handler (req, res) {
var payload = ''
let payload = ''
req.setEncoding('utf8')
req.on('data', chunk => { payload += chunk })
req.on('error', err => t.fail(err))
@ -346,7 +346,7 @@ test('Send body as buffer', t => {
t.plan(2)
function handler (req, res) {
var payload = ''
let payload = ''
req.setEncoding('utf8')
req.on('data', chunk => { payload += chunk })
req.on('error', err => t.fail(err))
@ -375,7 +375,7 @@ test('Send body as stream', t => {
t.plan(2)
function handler (req, res) {
var payload = ''
let payload = ''
req.setEncoding('utf8')
req.on('data', chunk => { payload += chunk })
req.on('error', err => t.fail(err))
@ -424,7 +424,7 @@ test('Should not close a connection if there are open requests', t => {
t.error(err)
t.strictEqual(connection._openRequests, 0)
var payload = ''
let payload = ''
res.setEncoding('utf8')
res.on('data', chunk => { payload += chunk })
res.on('error', err => t.fail(err))
@ -461,7 +461,7 @@ test('Should not close a connection if there are open requests (with agent disab
t.error(err)
t.strictEqual(connection._openRequests, 0)
var payload = ''
let payload = ''
res.setEncoding('utf8')
res.on('data', chunk => { payload += chunk })
res.on('error', err => t.fail(err))
@ -571,7 +571,7 @@ test('asStream set to true', t => {
}, (err, res) => {
t.error(err)
var payload = ''
let payload = ''
res.setEncoding('utf8')
res.on('data', chunk => { payload += chunk })
res.on('error', err => t.fail(err))

View File

@ -20,7 +20,6 @@
'use strict'
const { test } = require('tap')
const semver = require('semver')
const { Client, events } = require('../../index')
const { TimeoutError } = require('../../lib/errors')
const {
@ -127,7 +126,7 @@ test('Should emit a request event once when a request is performed', t => {
})
})
test('Remove an event', { skip: semver.lt(process.versions.node, '10.0.0') }, t => {
test('Remove an event', t => {
t.plan(4)
const client = new Client({

View File

@ -23,7 +23,6 @@ const { createReadStream } = require('fs')
const { join } = require('path')
const split = require('split2')
const FakeTimers = require('@sinonjs/fake-timers')
const semver = require('semver')
const { test } = require('tap')
const { Client, errors } = require('../../../')
const { buildServer, connection } = require('../../utils')
@ -308,10 +307,6 @@ test('bulk index', t => {
})
t.test('Should perform a bulk request (retry)', async t => {
if (semver.lt(process.versions.node, '10.0.0')) {
t.skip('This test will not pass on Node v8')
return
}
async function handler (req, res) {
t.strictEqual(req.url, '/_bulk')
t.match(req.headers, { 'content-type': 'application/x-ndjson' })
@ -430,10 +425,6 @@ test('bulk index', t => {
})
t.test('Should perform a bulk request (failure)', async t => {
if (semver.lt(process.versions.node, '10.0.0')) {
t.skip('This test will not pass on Node v8')
return
}
async function handler (req, res) {
t.strictEqual(req.url, '/_bulk')
t.match(req.headers, { 'content-type': 'application/x-ndjson' })
@ -575,10 +566,6 @@ test('bulk index', t => {
})
t.test('Should abort a bulk request', async t => {
if (semver.lt(process.versions.node, '10.0.0')) {
t.skip('This test will not pass on Node v8')
return
}
async function handler (req, res) {
t.strictEqual(req.url, '/_bulk')
t.match(req.headers, { 'content-type': 'application/x-ndjson' })

View File

@ -29,7 +29,7 @@ if (clientVersion.includes('-')) {
const nodeVersion = process.versions.node
test('Scroll search', async t => {
var count = 0
let count = 0
const MockConnection = connection.buildMockConnection({
onRequest (params) {
t.match(params.headers, {
@ -52,10 +52,10 @@ test('Scroll search', async t => {
hits: count === 3
? []
: [
{ _source: { one: 'one' } },
{ _source: { two: 'two' } },
{ _source: { three: 'three' } }
]
{ _source: { one: 'one' } },
{ _source: { two: 'two' } },
{ _source: { three: 'three' } }
]
}
}
}
@ -79,7 +79,7 @@ test('Scroll search', async t => {
})
test('Clear a scroll search', async t => {
var count = 0
let count = 0
const MockConnection = connection.buildMockConnection({
onRequest (params) {
t.notMatch(params.headers, {
@ -129,7 +129,7 @@ test('Clear a scroll search', async t => {
})
test('Scroll search (retry)', async t => {
var count = 0
let count = 0
const MockConnection = connection.buildMockConnection({
onRequest (params) {
count += 1
@ -149,10 +149,10 @@ test('Scroll search (retry)', async t => {
hits: count === 4
? []
: [
{ _source: { one: 'one' } },
{ _source: { two: 'two' } },
{ _source: { three: 'three' } }
]
{ _source: { one: 'one' } },
{ _source: { two: 'two' } },
{ _source: { three: 'three' } }
]
}
}
}
@ -181,7 +181,7 @@ test('Scroll search (retry)', async t => {
test('Scroll search (retry throws and maxRetries)', async t => {
const maxRetries = 5
const expectedAttempts = maxRetries + 1
var count = 0
let count = 0
const MockConnection = connection.buildMockConnection({
onRequest (params) {
count += 1
@ -217,7 +217,7 @@ test('Scroll search (retry throws and maxRetries)', async t => {
test('Scroll search (retry throws later)', async t => {
const maxRetries = 5
const expectedAttempts = maxRetries + 2
var count = 0
let count = 0
const MockConnection = connection.buildMockConnection({
onRequest (params) {
count += 1
@ -268,7 +268,7 @@ test('Scroll search (retry throws later)', async t => {
})
test('Scroll search documents', async t => {
var count = 0
let count = 0
const MockConnection = connection.buildMockConnection({
onRequest (params) {
if (count === 0) {
@ -287,10 +287,10 @@ test('Scroll search documents', async t => {
hits: count === 3
? []
: [
{ _source: { val: 1 * count } },
{ _source: { val: 2 * count } },
{ _source: { val: 3 * count } }
]
{ _source: { val: 1 * count } },
{ _source: { val: 2 * count } },
{ _source: { val: 3 * count } }
]
}
}
}
@ -321,7 +321,7 @@ test('Scroll search documents', async t => {
test('Should not retry if maxRetries = 0', async t => {
const maxRetries = 0
const expectedAttempts = 1
var count = 0
let count = 0
const MockConnection = connection.buildMockConnection({
onRequest (params) {
count += 1
@ -355,7 +355,7 @@ test('Should not retry if maxRetries = 0', async t => {
})
test('Fix querystring for scroll search', async t => {
var count = 0
let count = 0
const MockConnection = connection.buildMockConnection({
onRequest (params) {
if (count === 0) {
@ -372,8 +372,8 @@ test('Fix querystring for scroll search', async t => {
hits: count === 3
? []
: [
{ _source: { val: count } }
]
{ _source: { val: count } }
]
}
}
}

View File

@ -27,7 +27,7 @@ test('RoundRobinSelector', t => {
const arr = [0, 1, 2, 3, 4, 5]
t.plan(arr.length + 1)
for (var i = 0; i <= arr.length; i++) {
for (let i = 0; i <= arr.length; i++) {
t.strictEqual(
selector(arr),
i === arr.length ? arr[0] : arr[i]

View File

@ -166,7 +166,7 @@ test('Send POST', t => {
'content-type': 'application/json',
'content-length': '17'
})
var json = ''
let json = ''
req.setEncoding('utf8')
req.on('data', chunk => { json += chunk })
req.on('error', err => t.fail(err))
@ -217,7 +217,7 @@ test('Send POST (ndjson)', t => {
'content-type': 'application/x-ndjson',
'content-length': '67'
})
var json = ''
let json = ''
req.setEncoding('utf8')
req.on('data', chunk => { json += chunk })
req.on('error', err => t.fail(err))
@ -265,7 +265,7 @@ test('Send stream', t => {
t.match(req.headers, {
'content-type': 'application/json'
})
var json = ''
let json = ''
req.setEncoding('utf8')
req.on('data', chunk => { json += chunk })
req.on('error', err => t.fail(err))
@ -308,7 +308,7 @@ test('Send stream (bulkBody)', t => {
t.match(req.headers, {
'content-type': 'application/x-ndjson'
})
var json = ''
let json = ''
req.setEncoding('utf8')
req.on('data', chunk => { json += chunk })
req.on('error', err => t.fail(err))
@ -587,7 +587,7 @@ test('ConnectionError (should call markDead on the failing connection)', t => {
test('Retry mechanism', t => {
t.plan(2)
var count = 0
let count = 0
function handler (req, res) {
res.setHeader('Content-Type', 'application/json;utf=8')
if (count > 0) {
@ -635,7 +635,7 @@ test('Retry mechanism', t => {
test('Should not retry if the body is a stream', t => {
t.plan(2)
var count = 0
let count = 0
function handler (req, res) {
count++
res.setHeader('Content-Type', 'application/json;utf=8')
@ -680,7 +680,7 @@ test('Should not retry if the body is a stream', t => {
test('Should not retry if the bulkBody is a stream', t => {
t.plan(2)
var count = 0
let count = 0
function handler (req, res) {
count++
res.setHeader('Content-Type', 'application/json;utf=8')
@ -725,7 +725,7 @@ test('Should not retry if the bulkBody is a stream', t => {
test('No retry', t => {
t.plan(2)
var count = 0
let count = 0
function handler (req, res) {
count++
res.setHeader('Content-Type', 'application/json;utf=8')
@ -772,7 +772,7 @@ test('No retry', t => {
test('Custom retry mechanism', t => {
t.plan(2)
var count = 0
let count = 0
function handler (req, res) {
res.setHeader('Content-Type', 'application/json;utf=8')
if (count > 0) {
@ -822,7 +822,7 @@ test('Custom retry mechanism', t => {
test('Should not retry on 429', t => {
t.plan(3)
var count = 0
let count = 0
function handler (req, res) {
t.strictEqual(count++, 0)
res.statusCode = 429
@ -988,7 +988,7 @@ test('Retry mechanism and abort', t => {
id: 'node3'
}])
var count = 0
let count = 0
const transport = new Transport({
emit: event => {
if (event === 'request' && count++ > 0) {
@ -1294,7 +1294,7 @@ test('Should retry the request if the statusCode is 502/3/4', t => {
t.test(statusCode, t => {
t.plan(3)
var first = true
let first = true
function handler (req, res) {
if (first) {
first = false
@ -1886,7 +1886,7 @@ test('asStream set to true', t => {
'content-type': 'application/json;utf=8'
})
var payload = ''
let payload = ''
body.setEncoding('utf8')
body.on('data', chunk => { payload += chunk })
body.on('error', err => t.fail(err))
@ -1906,7 +1906,7 @@ test('Compress request', t => {
'content-type': 'application/json',
'content-encoding': 'gzip'
})
var json = ''
let json = ''
req
.pipe(createGunzip())
.on('data', chunk => { json += chunk })
@ -1953,7 +1953,7 @@ test('Compress request', t => {
'content-type': 'application/json',
'content-encoding': 'gzip'
})
var json = ''
let json = ''
req
.pipe(createGunzip())
.on('data', chunk => { json += chunk })
@ -1999,7 +1999,7 @@ test('Compress request', t => {
'content-type': 'application/json',
'content-encoding': 'gzip'
})
var json = ''
let json = ''
req
.pipe(createGunzip())
.on('data', chunk => { json += chunk })
@ -2112,13 +2112,13 @@ test('Compress request', t => {
t.test('Retry a gzipped body', t => {
t.plan(7)
var count = 0
let count = 0
function handler (req, res) {
t.match(req.headers, {
'content-type': 'application/json',
'content-encoding': 'gzip'
})
var json = ''
let json = ''
req
.pipe(createGunzip())
.on('data', chunk => { json += chunk })