use eslint autofix to start fixing violations
This commit is contained in:
16
test/fixtures/keepalive.js
vendored
16
test/fixtures/keepalive.js
vendored
@ -1,10 +1,10 @@
|
||||
var clock = require('sinon').useFakeTimers();
|
||||
var Client = require('../../src/elasticsearch').Client;
|
||||
var _ = require('lodash');
|
||||
var times = require('async').times;
|
||||
const clock = require('sinon').useFakeTimers();
|
||||
const Client = require('../../src/elasticsearch').Client;
|
||||
const _ = require('lodash');
|
||||
const times = require('async').times;
|
||||
|
||||
process.once('message', function (port) {
|
||||
var es = new Client({
|
||||
const es = new Client({
|
||||
host: 'http://127.0.0.1:' + port,
|
||||
log: false
|
||||
});
|
||||
@ -19,8 +19,8 @@ process.once('message', function (port) {
|
||||
}, done);
|
||||
clock.tick(10);
|
||||
}, function (err) {
|
||||
var conns = es.transport.connectionPool._conns;
|
||||
var sockets = _([].concat(conns.dead, conns.alive))
|
||||
const conns = es.transport.connectionPool._conns;
|
||||
const sockets = _([].concat(conns.dead, conns.alive))
|
||||
.transform(function (sockets, conn) {
|
||||
sockets.push(_.values(conn.agent.sockets), _.values(conn.agent.freeSockets));
|
||||
}, [])
|
||||
@ -29,7 +29,7 @@ process.once('message', function (port) {
|
||||
|
||||
es.close();
|
||||
|
||||
var out = {
|
||||
const out = {
|
||||
socketCount: err || sockets.length,
|
||||
remaining: _.filter(sockets, { destroyed: true }).length - sockets.length,
|
||||
timeouts: _.size(clock.timers) && _.map(clock.timers, 'func').map(String)
|
||||
|
||||
8
test/fixtures/keepalive_server.js
vendored
8
test/fixtures/keepalive_server.js
vendored
@ -4,13 +4,13 @@
|
||||
// which prevent sinon from being able to ensure
|
||||
// timeouts aren't being left behind
|
||||
|
||||
var express = require('express');
|
||||
var app = express().post('/_search', function (req, res) {
|
||||
const express = require('express');
|
||||
const app = express().post('/_search', function (req, res) {
|
||||
res.json(200, { hits: { hits: [] } });
|
||||
});
|
||||
|
||||
var server = require('http').createServer(app);
|
||||
const server = require('http').createServer(app);
|
||||
server.listen(function () {
|
||||
var port = server.address().port;
|
||||
const port = server.address().port;
|
||||
process.connected ? process.send(port) : console.log(port);
|
||||
});
|
||||
|
||||
@ -1,22 +1,22 @@
|
||||
var BROWSER = process.env.browser;
|
||||
var VERBOSE = process.env.VERBOSE;
|
||||
var JENKINS = !!process.env.JENKINS_HOME;
|
||||
const BROWSER = process.env.browser;
|
||||
const VERBOSE = process.env.VERBOSE;
|
||||
const JENKINS = !!process.env.JENKINS_HOME;
|
||||
|
||||
var es;
|
||||
let es;
|
||||
if (BROWSER) {
|
||||
es = window.elasticsearch;
|
||||
} else {
|
||||
es = require('../../../src/elasticsearch');
|
||||
}
|
||||
|
||||
var _ = require('../../../src/lib/utils');
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var fromRoot = _.bindKey(path, 'join', require('find-root')(__dirname));
|
||||
var Bluebird = require('bluebird');
|
||||
const _ = require('../../../src/lib/utils');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const fromRoot = _.bindKey(path, 'join', require('find-root')(__dirname));
|
||||
const Bluebird = require('bluebird');
|
||||
|
||||
// current client
|
||||
var client = null;
|
||||
let client = null;
|
||||
|
||||
module.exports = {
|
||||
create: function create(apiVersion, port, host, cb) {
|
||||
@ -24,8 +24,8 @@ module.exports = {
|
||||
doCreateClient({
|
||||
logConfig: null
|
||||
}, function () {
|
||||
var attemptsRemaining = 60;
|
||||
var timeout = 500;
|
||||
let attemptsRemaining = 60;
|
||||
const timeout = 500;
|
||||
|
||||
(function ping() {
|
||||
client.info({
|
||||
@ -59,7 +59,7 @@ module.exports = {
|
||||
options = {};
|
||||
}
|
||||
|
||||
var logConfig = {};
|
||||
let logConfig = {};
|
||||
if (_.has(options, 'logConfig')) {
|
||||
logConfig = options.logConfig;
|
||||
} else {
|
||||
|
||||
@ -1,18 +1,18 @@
|
||||
module.exports = function (branch) {
|
||||
var path = require('path');
|
||||
var jsYaml = require('js-yaml');
|
||||
var YamlFile = require('./yaml_file');
|
||||
var root = require('find-root')(__dirname);
|
||||
var rootReq = function (loc) { return require(path.join(root, loc)); };
|
||||
var _ = rootReq('src/lib/utils');
|
||||
var utils = rootReq('grunt/utils');
|
||||
var es = rootReq('src/elasticsearch');
|
||||
var clientManager = require('./client_manager');
|
||||
const path = require('path');
|
||||
const jsYaml = require('js-yaml');
|
||||
const YamlFile = require('./yaml_file');
|
||||
const root = require('find-root')(__dirname);
|
||||
const rootReq = function (loc) { return require(path.join(root, loc)); };
|
||||
const _ = rootReq('src/lib/utils');
|
||||
const utils = rootReq('grunt/utils');
|
||||
const es = rootReq('src/elasticsearch');
|
||||
const clientManager = require('./client_manager');
|
||||
|
||||
var port = parseInt(process.env.ES_PORT || 9200, 10);
|
||||
var host = process.env.ES_HOST || 'localhost';
|
||||
var _release = branch.match(/^v(\d+\.\d+)\.\d+$/);
|
||||
var apiVersion = _release ? _release[1] : branch;
|
||||
const port = parseInt(process.env.ES_PORT || 9200, 10);
|
||||
const host = process.env.ES_HOST || 'localhost';
|
||||
const _release = branch.match(/^v(\d+\.\d+)\.\d+$/);
|
||||
const apiVersion = _release ? _release[1] : branch;
|
||||
|
||||
console.log(' branch:', branch);
|
||||
console.log(' port:', port);
|
||||
@ -32,7 +32,7 @@ module.exports = function (branch) {
|
||||
return clientManager.get().clearEs();
|
||||
});
|
||||
|
||||
var files = _.map(require('./yaml_tests_' + _.snakeCase(branch) + '.json'), function (docs, filename) {
|
||||
const files = _.map(require('./yaml_tests_' + _.snakeCase(branch) + '.json'), function (docs, filename) {
|
||||
return new YamlFile(filename, docs);
|
||||
});
|
||||
|
||||
|
||||
@ -9,39 +9,39 @@
|
||||
*/
|
||||
module.exports = YamlDoc;
|
||||
|
||||
var _ = require('lodash');
|
||||
var expect = require('expect.js');
|
||||
var clientManager = require('./client_manager');
|
||||
var inspect = require('util').inspect;
|
||||
const _ = require('lodash');
|
||||
const expect = require('expect.js');
|
||||
const clientManager = require('./client_manager');
|
||||
const inspect = require('util').inspect;
|
||||
|
||||
var implementedFeatures = ['gtelte', 'regex', 'benchmark', 'stash_in_path', 'groovy_scripting'];
|
||||
const implementedFeatures = ['gtelte', 'regex', 'benchmark', 'stash_in_path', 'groovy_scripting'];
|
||||
|
||||
/**
|
||||
* The version that ES is running, in comparable string form XXX-XXX-XXX, fetched when needed
|
||||
* @type {String}
|
||||
*/
|
||||
var ES_VERSION = null;
|
||||
let ES_VERSION = null;
|
||||
|
||||
// core expression for finding a version
|
||||
var versionExp = '((?:\\d+\\.){0,2}\\d+)(?:[\\.\\-]\\w+)?|';
|
||||
const versionExp = '((?:\\d+\\.){0,2}\\d+)(?:[\\.\\-]\\w+)?|';
|
||||
|
||||
// match all whitespace within a "regexp" match arg
|
||||
var reWhitespaceRE = /\s+/g;
|
||||
const reWhitespaceRE = /\s+/g;
|
||||
|
||||
// match all comments within a "regexp" match arg
|
||||
var reCommentsRE = /([\S\s]?)#[^\n]*\n/g;
|
||||
const reCommentsRE = /([\S\s]?)#[^\n]*\n/g;
|
||||
|
||||
/**
|
||||
* Regular Expression to extract a version number from a string
|
||||
* @type {RegExp}
|
||||
*/
|
||||
var versionRE = new RegExp('^(?:' + versionExp + ')$');
|
||||
const versionRE = new RegExp('^(?:' + versionExp + ')$');
|
||||
|
||||
/**
|
||||
* Regular Expression to extract a version range from a string
|
||||
* @type {RegExp}
|
||||
*/
|
||||
var versionRangeRE = new RegExp('^(?:' + versionExp + ')\\s*\\-\\s*(?:' + versionExp + ')$');
|
||||
const versionRangeRE = new RegExp('^(?:' + versionExp + ')\\s*\\-\\s*(?:' + versionExp + ')$');
|
||||
|
||||
/**
|
||||
* Fetches the client.info, and parses out the version number to a comparable string
|
||||
@ -70,7 +70,7 @@ function versionToComparableString(version, def) {
|
||||
return def;
|
||||
}
|
||||
|
||||
var parts = _.map(version.split('.'), function (part) {
|
||||
const parts = _.map(version.split('.'), function (part) {
|
||||
part = '' + _.parseInt(part);
|
||||
return (new Array(Math.max(4 - part.length, 0))).join('0') + part;
|
||||
});
|
||||
@ -106,7 +106,7 @@ function rangeMatchesCurrentVersion(rangeString, done) {
|
||||
|
||||
|
||||
function YamlDoc(doc, file) {
|
||||
var self = this;
|
||||
const self = this;
|
||||
|
||||
self.file = file;
|
||||
self.description = _.keys(doc).shift();
|
||||
@ -116,7 +116,7 @@ function YamlDoc(doc, file) {
|
||||
// setup the actions, creating a bound and testable method for each
|
||||
self._actions = _.map(self.flattenTestActions(doc[self.description]), function (action) {
|
||||
// get the method that will do the action
|
||||
var method = self['do_' + action.name];
|
||||
const method = self['do_' + action.name];
|
||||
|
||||
// check that it's a function
|
||||
expect(method || 'YamlDoc#' + action.name).to.be.a('function');
|
||||
@ -175,14 +175,14 @@ function YamlDoc(doc, file) {
|
||||
|
||||
YamlDoc.compareRangeToVersion = function (range, version) {
|
||||
expect(range).to.match(versionRangeRE);
|
||||
var rangeMatch = versionRangeRE.exec(range);
|
||||
const rangeMatch = versionRangeRE.exec(range);
|
||||
|
||||
expect(version).to.match(versionRE);
|
||||
var versionMatch = versionRE.exec(version);
|
||||
const versionMatch = versionRE.exec(version);
|
||||
|
||||
var min = versionToComparableString(rangeMatch[1], -Infinity);
|
||||
var max = versionToComparableString(rangeMatch[2], Infinity);
|
||||
var comp = versionToComparableString(versionMatch[1], Infinity);
|
||||
const min = versionToComparableString(rangeMatch[1], -Infinity);
|
||||
const max = versionToComparableString(rangeMatch[2], Infinity);
|
||||
const comp = versionToComparableString(versionMatch[1], Infinity);
|
||||
|
||||
return (min === -Infinity || min <= comp) && (max === Infinity || max >= comp);
|
||||
};
|
||||
@ -199,7 +199,7 @@ YamlDoc.prototype = {
|
||||
flattenTestActions: function (config) {
|
||||
// creates [ [ {name:"", args:"" }, ... ], ... ]
|
||||
// from [ {name:args, name:args}, {name:args} ]
|
||||
var actionSets = _.map(config, function (set) {
|
||||
const actionSets = _.map(config, function (set) {
|
||||
return _.map(_.toPairs(set), function (pair) {
|
||||
return { name: pair[0], args: pair[1] };
|
||||
});
|
||||
@ -219,7 +219,7 @@ YamlDoc.prototype = {
|
||||
* @return {undefined}
|
||||
*/
|
||||
each: function (ittr) {
|
||||
for (var i = 0; i < this._actions.length; i++) {
|
||||
for (let i = 0; i < this._actions.length; i++) {
|
||||
if (ittr(this._actions[i].testable, this._actions[i].name) === false) {
|
||||
break;
|
||||
}
|
||||
@ -249,9 +249,9 @@ YamlDoc.prototype = {
|
||||
* @return {*} - The value requested, or undefined if it was not found
|
||||
*/
|
||||
get: function (path, from) {
|
||||
var self = this;
|
||||
var log = process.env.LOG_GETS && !from ? console.log.bind(console) : function () {};
|
||||
var i;
|
||||
const self = this;
|
||||
const log = process.env.LOG_GETS && !from ? console.log.bind(console) : function () {};
|
||||
let i;
|
||||
|
||||
if (path === '$body') {
|
||||
// shortcut, the test just wants the whole body
|
||||
@ -273,10 +273,10 @@ YamlDoc.prototype = {
|
||||
|
||||
log('getting', path, 'from', from);
|
||||
|
||||
var steps = _.map(path ? path.replace(/\\\./g, '\uffff').split('.') : [], function (step) {
|
||||
const steps = _.map(path ? path.replace(/\\\./g, '\uffff').split('.') : [], function (step) {
|
||||
return step.replace(/\uffff/g, '.');
|
||||
});
|
||||
var remainingSteps;
|
||||
let remainingSteps;
|
||||
|
||||
for (i = 0; from != null && i < steps.length; i++) {
|
||||
if (from[steps[i]] === void 0) {
|
||||
@ -319,8 +319,8 @@ YamlDoc.prototype = {
|
||||
}
|
||||
|
||||
if (args.features) {
|
||||
var features = Array.isArray(args.features) ? args.features : [args.features];
|
||||
var notImplemented = _.difference(features, implementedFeatures);
|
||||
const features = Array.isArray(args.features) ? args.features : [args.features];
|
||||
const notImplemented = _.difference(features, implementedFeatures);
|
||||
|
||||
if (notImplemented.length) {
|
||||
if (this.description === 'setup') {
|
||||
@ -343,10 +343,10 @@ YamlDoc.prototype = {
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
do_do: function (args, done) {
|
||||
var catcher;
|
||||
let catcher;
|
||||
|
||||
if (process.env.LOG_DO) {
|
||||
var __done = done;
|
||||
const __done = done;
|
||||
done = function (err, resp) {
|
||||
console.log('doing', clientActionName, 'with', params);
|
||||
console.log('got', resp);
|
||||
@ -388,7 +388,7 @@ YamlDoc.prototype = {
|
||||
|
||||
delete args.catch;
|
||||
|
||||
var inputParams = {};
|
||||
const inputParams = {};
|
||||
|
||||
// resolve the headers for a request
|
||||
if (args.headers) {
|
||||
@ -396,25 +396,25 @@ YamlDoc.prototype = {
|
||||
delete args.headers;
|
||||
}
|
||||
|
||||
var otherKeys = _.keys(args);
|
||||
var action = otherKeys.shift();
|
||||
const otherKeys = _.keys(args);
|
||||
const action = otherKeys.shift();
|
||||
if (otherKeys.length) {
|
||||
return done(new TypeError('Unexpected top-level args to "do": ' + otherKeys.join(', ')));
|
||||
}
|
||||
|
||||
var client = clientManager.get();
|
||||
const client = clientManager.get();
|
||||
var clientActionName = _.map(action.split('.'), _.camelCase).join('.');
|
||||
var clientAction = this.get(clientActionName, client);
|
||||
const clientAction = this.get(clientActionName, client);
|
||||
_.assign(inputParams, args[action]);
|
||||
|
||||
var params = _.transform(inputParams, _.bind(function (params, val, name) {
|
||||
var camelName = _.camelCase(name);
|
||||
const camelName = _.camelCase(name);
|
||||
|
||||
// search through the params and url peices to find this param name
|
||||
var paramName = name;
|
||||
var spec = clientAction && clientAction.spec;
|
||||
var knownParam = spec && spec.params && spec.params[camelName];
|
||||
var knownUrlParam = spec && !knownParam && !!_.find(spec.url ? [spec.url] : spec.urls, function (url) {
|
||||
let paramName = name;
|
||||
const spec = clientAction && clientAction.spec;
|
||||
const knownParam = spec && spec.params && spec.params[camelName];
|
||||
const knownUrlParam = spec && !knownParam && !!_.find(spec.url ? [spec.url] : spec.urls, function (url) {
|
||||
if ((url.opt && url.opt[camelName]) || (url.req && url.req[camelName])) {
|
||||
return true;
|
||||
}
|
||||
@ -447,8 +447,8 @@ YamlDoc.prototype = {
|
||||
catcher = null;
|
||||
}
|
||||
|
||||
var timeoutId;
|
||||
var cb = _.bind(function (error, body) {
|
||||
let timeoutId;
|
||||
const cb = _.bind(function (error, body) {
|
||||
this._last_requests_response = body;
|
||||
clearTimeout(timeoutId);
|
||||
|
||||
@ -473,7 +473,7 @@ YamlDoc.prototype = {
|
||||
done(error);
|
||||
}, this);
|
||||
|
||||
var req = clientAction.call(client, params, cb);
|
||||
const req = clientAction.call(client, params, cb);
|
||||
timeoutId = setTimeout(function () {
|
||||
// request timed out, so we will skip the rest of the tests and continue
|
||||
req.abort();
|
||||
@ -507,7 +507,7 @@ YamlDoc.prototype = {
|
||||
* @return {undefined}
|
||||
*/
|
||||
do_is_true: function (path) {
|
||||
var val = this.get(path);
|
||||
const val = this.get(path);
|
||||
try {
|
||||
expect(Boolean(val)).to.be(true, 'path: ' + path);
|
||||
} catch (e) {
|
||||
@ -523,7 +523,7 @@ YamlDoc.prototype = {
|
||||
* @return {undefined}
|
||||
*/
|
||||
do_is_false: function (path) {
|
||||
var val = this.get(path);
|
||||
const val = this.get(path);
|
||||
try {
|
||||
expect(Boolean(val)).to.be(false, 'path: ' + path);
|
||||
} catch (e) {
|
||||
@ -563,7 +563,7 @@ YamlDoc.prototype = {
|
||||
* @return {undefined}
|
||||
*/
|
||||
do_match: function (args) {
|
||||
var self = this;
|
||||
const self = this;
|
||||
|
||||
// recursively replace all $var within args
|
||||
_.forOwn(args, function recurse(val, key, lvl) {
|
||||
@ -579,10 +579,10 @@ YamlDoc.prototype = {
|
||||
});
|
||||
|
||||
_.forOwn(args, _.bind(function (match, path) {
|
||||
var origMatch = match;
|
||||
const origMatch = match;
|
||||
|
||||
var maybeRE = false;
|
||||
var usedRE = false;
|
||||
let maybeRE = false;
|
||||
let usedRE = false;
|
||||
|
||||
if (_.isString(match)) {
|
||||
// convert the matcher into a compatible string for building a regexp
|
||||
@ -599,8 +599,8 @@ YamlDoc.prototype = {
|
||||
// whitespace is represented with \s
|
||||
.replace(reWhitespaceRE, '');
|
||||
|
||||
var startsWithSlash = maybeRE[0] === '/';
|
||||
var endsWithSlash = maybeRE[maybeRE.length - 1] === '/';
|
||||
const startsWithSlash = maybeRE[0] === '/';
|
||||
const endsWithSlash = maybeRE[maybeRE.length - 1] === '/';
|
||||
|
||||
if (startsWithSlash && endsWithSlash) {
|
||||
usedRE = true;
|
||||
@ -608,8 +608,8 @@ YamlDoc.prototype = {
|
||||
}
|
||||
}
|
||||
|
||||
var val = this.get(path);
|
||||
var test = 'eql';
|
||||
let val = this.get(path);
|
||||
let test = 'eql';
|
||||
|
||||
if (match instanceof RegExp) {
|
||||
test = 'match';
|
||||
@ -622,7 +622,7 @@ YamlDoc.prototype = {
|
||||
try {
|
||||
expect(val).to[test](match);
|
||||
} catch (e) {
|
||||
var msg = [
|
||||
const msg = [
|
||||
'\nUnable to match',
|
||||
inspect(match),
|
||||
'with the path',
|
||||
|
||||
@ -6,13 +6,13 @@
|
||||
*/
|
||||
module.exports = YamlFile;
|
||||
|
||||
var YamlDoc = require('./yaml_doc');
|
||||
var clientManager = require('./client_manager');
|
||||
var _ = require('../../../src/lib/utils');
|
||||
var async = require('async');
|
||||
const YamlDoc = require('./yaml_doc');
|
||||
const clientManager = require('./client_manager');
|
||||
const _ = require('../../../src/lib/utils');
|
||||
const async = require('async');
|
||||
|
||||
function YamlFile(filename, docs) {
|
||||
var file = this;
|
||||
const file = this;
|
||||
|
||||
// file level skipping flag
|
||||
file.skipping = false;
|
||||
|
||||
@ -1,22 +1,22 @@
|
||||
var interceptors = [];
|
||||
var complete = [];
|
||||
var MockHttpRequest = require('./browser_http');
|
||||
var XhrServer = MockHttpRequest.MockHttpServer;
|
||||
var parseUrl = MockHttpRequest.prototype.parseUri;
|
||||
var _ = require('lodash');
|
||||
const interceptors = [];
|
||||
const complete = [];
|
||||
const MockHttpRequest = require('./browser_http');
|
||||
const XhrServer = MockHttpRequest.MockHttpServer;
|
||||
const parseUrl = MockHttpRequest.prototype.parseUri;
|
||||
const _ = require('lodash');
|
||||
|
||||
var server = new XhrServer(function (request) {
|
||||
var reqDetails = {
|
||||
const server = new XhrServer(function (request) {
|
||||
const reqDetails = {
|
||||
method: request.method,
|
||||
host: request.urlParts.host,
|
||||
path: request.urlParts.relative
|
||||
};
|
||||
var response = _.find(interceptors, reqDetails);
|
||||
const response = _.find(interceptors, reqDetails);
|
||||
|
||||
if (response) {
|
||||
// remove of tick down the times
|
||||
if (response.times === 1) {
|
||||
var i = interceptors.indexOf(response);
|
||||
const i = interceptors.indexOf(response);
|
||||
complete.push(interceptors.splice(i, 1));
|
||||
} else {
|
||||
response.times--;
|
||||
@ -31,8 +31,8 @@ var server = new XhrServer(function (request) {
|
||||
server.start();
|
||||
|
||||
var mockNock = module.exports = function (url) {
|
||||
var parsedUrl = parseUrl(url);
|
||||
var req = {
|
||||
const parsedUrl = parseUrl(url);
|
||||
const req = {
|
||||
method: 'GET',
|
||||
host: parsedUrl.host,
|
||||
times: 1
|
||||
|
||||
@ -6,9 +6,9 @@
|
||||
*/
|
||||
module.exports = MockIncommingMessage;
|
||||
|
||||
var sinon = require('sinon');
|
||||
var util = require('util');
|
||||
var Readable = require('stream').Readable;
|
||||
const sinon = require('sinon');
|
||||
const util = require('util');
|
||||
let Readable = require('stream').Readable;
|
||||
|
||||
if (!Readable) {
|
||||
Readable = require('events').EventEmitter;
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
*/
|
||||
module.exports = MockRequest;
|
||||
|
||||
var sinon = require('sinon');
|
||||
var util = require('util');
|
||||
var http = require('http');
|
||||
const sinon = require('sinon');
|
||||
const util = require('util');
|
||||
const http = require('http');
|
||||
|
||||
function MockRequest() {
|
||||
sinon.stub(this, 'end');
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
var nock = require('nock');
|
||||
const nock = require('nock');
|
||||
nock.disableNetConnect();
|
||||
module.exports = nock;
|
||||
|
||||
@ -3,9 +3,9 @@
|
||||
* @type {Constuctor}
|
||||
*/
|
||||
|
||||
var util = require('util');
|
||||
var MockWritableStream; // defined simply for 0.10+, in detail for older versions
|
||||
var Writable = require('stream').Writable;
|
||||
const util = require('util');
|
||||
let MockWritableStream; // defined simply for 0.10+, in detail for older versions
|
||||
const Writable = require('stream').Writable;
|
||||
|
||||
|
||||
if (Writable) {
|
||||
@ -18,7 +18,7 @@ if (Writable) {
|
||||
util.inherits(MockWritableStream, Writable);
|
||||
} else {
|
||||
// Node < 0.10 did not provide a usefull stream abstract
|
||||
var Stream = require('stream').Stream;
|
||||
const Stream = require('stream').Stream;
|
||||
module.exports = MockWritableStream = function (opts) {
|
||||
Stream.call(this);
|
||||
this.writable = true;
|
||||
@ -31,8 +31,8 @@ if (Writable) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var cb;
|
||||
if (typeof(arguments[arguments.length - 1]) === 'function') {
|
||||
let cb;
|
||||
if (typeof (arguments[arguments.length - 1]) === 'function') {
|
||||
cb = arguments[arguments.length - 1];
|
||||
}
|
||||
|
||||
@ -42,9 +42,9 @@ if (Writable) {
|
||||
};
|
||||
|
||||
MockWritableStream.prototype.end = function (data, encoding, cb) {
|
||||
if (typeof(data) === 'function') {
|
||||
if (typeof (data) === 'function') {
|
||||
cb = data;
|
||||
} else if (typeof(encoding) === 'function') {
|
||||
} else if (typeof (encoding) === 'function') {
|
||||
cb = encoding;
|
||||
this.write(data);
|
||||
} else if (arguments.length > 0) {
|
||||
@ -54,7 +54,7 @@ if (Writable) {
|
||||
};
|
||||
|
||||
MockWritableStream.prototype.destroy = function (cb) {
|
||||
var self = this;
|
||||
const self = this;
|
||||
|
||||
if (!this.writable) {
|
||||
if (cb) {
|
||||
|
||||
28
test/unit/browser_builds/angular.js
vendored
28
test/unit/browser_builds/angular.js
vendored
@ -1,23 +1,23 @@
|
||||
/* global angular */
|
||||
var _ = require('lodash');
|
||||
var expect = require('expect.js');
|
||||
var Promise = require('bluebird');
|
||||
var sinon = require('sinon');
|
||||
const _ = require('lodash');
|
||||
const expect = require('expect.js');
|
||||
const Promise = require('bluebird');
|
||||
const sinon = require('sinon');
|
||||
|
||||
describe('Angular esFactory', function () {
|
||||
before(function () {
|
||||
require('../../../src/elasticsearch.angular.js');
|
||||
});
|
||||
|
||||
var uuid = (function () { var i = 0; return function () { return ++i; }; }());
|
||||
var esFactory;
|
||||
var $http;
|
||||
var $rootScope;
|
||||
var $httpBackend;
|
||||
const uuid = (function () { let i = 0; return function () { return ++i; }; }());
|
||||
let esFactory;
|
||||
let $http;
|
||||
let $rootScope;
|
||||
let $httpBackend;
|
||||
|
||||
function bootstrap(env) {
|
||||
beforeEach(function () {
|
||||
var promiseProvider = _.noop;
|
||||
let promiseProvider = _.noop;
|
||||
if (env.bluebirdPromises) {
|
||||
promiseProvider = function ($provide) {
|
||||
$provide.service('$q', function () {
|
||||
@ -59,7 +59,7 @@ describe('Angular esFactory', function () {
|
||||
});
|
||||
|
||||
it('returns a new client when it is called', function () {
|
||||
var client = esFactory({
|
||||
const client = esFactory({
|
||||
hosts: null
|
||||
});
|
||||
|
||||
@ -69,10 +69,10 @@ describe('Angular esFactory', function () {
|
||||
});
|
||||
|
||||
it('returns an error created by calling a method incorrectly', function () {
|
||||
var client = esFactory({ hosts: null });
|
||||
var err;
|
||||
const client = esFactory({ hosts: null });
|
||||
let err;
|
||||
|
||||
var prom = client.get().then(function () {
|
||||
const prom = client.get().then(function () {
|
||||
throw new Error('expected request to fail');
|
||||
}, function (err) {
|
||||
expect(err).to.have.property('message');
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
var expect = require('expect.js');
|
||||
var Transport = require('../../../src/lib/transport');
|
||||
const expect = require('expect.js');
|
||||
const Transport = require('../../../src/lib/transport');
|
||||
|
||||
describe('elasticsearch namespace', function () {
|
||||
var es = window.elasticsearch;
|
||||
const es = window.elasticsearch;
|
||||
it('is defined on the window', function () {
|
||||
expect(es).to.be.ok();
|
||||
});
|
||||
@ -12,7 +12,7 @@ describe('elasticsearch namespace', function () {
|
||||
});
|
||||
|
||||
it('can create a client', function () {
|
||||
var client = new es.Client({ hosts: null });
|
||||
const client = new es.Client({ hosts: null });
|
||||
expect(client).to.have.keys('transport');
|
||||
expect(client.transport).to.be.a(es.Transport);
|
||||
client.close();
|
||||
|
||||
6
test/unit/browser_builds/jquery.js
vendored
6
test/unit/browser_builds/jquery.js
vendored
@ -1,6 +1,6 @@
|
||||
/* global $ */
|
||||
var expect = require('expect.js');
|
||||
var Transport = require('../../../src/lib/transport');
|
||||
const expect = require('expect.js');
|
||||
const Transport = require('../../../src/lib/transport');
|
||||
|
||||
describe('jQuery.es namespace', function () {
|
||||
it('is defined on the global jQuery', function () {
|
||||
@ -12,7 +12,7 @@ describe('jQuery.es namespace', function () {
|
||||
});
|
||||
|
||||
it('can create a client', function () {
|
||||
var client = new $.es.Client({ hosts: null });
|
||||
const client = new $.es.Client({ hosts: null });
|
||||
expect(client).to.have.keys('transport');
|
||||
expect(client.transport).to.be.a($.es.Transport);
|
||||
client.close();
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
module.exports = function (makeLogger) {
|
||||
var expect = require('expect.js');
|
||||
var stub = require('../utils/auto_release_stub').make();
|
||||
var fs = require('fs');
|
||||
var once = require('events').EventEmitter.prototype.once;
|
||||
var _ = require('lodash');
|
||||
const expect = require('expect.js');
|
||||
const stub = require('../utils/auto_release_stub').make();
|
||||
const fs = require('fs');
|
||||
const once = require('events').EventEmitter.prototype.once;
|
||||
const _ = require('lodash');
|
||||
|
||||
describe('buffer flush', function () {
|
||||
if (require('stream').Writable) {
|
||||
it('writes everything in the buffer to console.error', function () {
|
||||
var line = 'This string is written 10 times to create buffered output\n';
|
||||
const line = 'This string is written 10 times to create buffered output\n';
|
||||
|
||||
var exitHandler;
|
||||
let exitHandler;
|
||||
stub(process, 'once', function (event, handler) {
|
||||
if (event === 'exit') {
|
||||
exitHandler = handler;
|
||||
@ -18,7 +18,7 @@ module.exports = function (makeLogger) {
|
||||
once.call(process, event, handler);
|
||||
});
|
||||
|
||||
var logger = makeLogger();
|
||||
const logger = makeLogger();
|
||||
|
||||
// write the line 10 times
|
||||
_.times(10, function () {
|
||||
@ -26,7 +26,7 @@ module.exports = function (makeLogger) {
|
||||
});
|
||||
|
||||
// collect everything that is written to fs.appendFileSync
|
||||
var flushedOutput = '';
|
||||
let flushedOutput = '';
|
||||
stub(fs, 'appendFileSync', function (path, str) {
|
||||
flushedOutput += str;
|
||||
});
|
||||
@ -40,7 +40,7 @@ module.exports = function (makeLogger) {
|
||||
});
|
||||
} else {
|
||||
it('does not fall apart with non streams2 streams', function () {
|
||||
var exitHandler;
|
||||
let exitHandler;
|
||||
stub(process, 'once', function (event, handler) {
|
||||
if (event === 'exit') {
|
||||
exitHandler = handler;
|
||||
@ -48,7 +48,7 @@ module.exports = function (makeLogger) {
|
||||
once.call(process, event, handler);
|
||||
});
|
||||
|
||||
var logger = makeLogger();
|
||||
const logger = makeLogger();
|
||||
|
||||
expect(function () {
|
||||
// call the event handler
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
var blanket = require('blanket')({
|
||||
const blanket = require('blanket')({
|
||||
pattern: require('path').join(__dirname, '../../src')
|
||||
});
|
||||
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
var expect = require('expect.js');
|
||||
var Log = require('../../src/lib/log');
|
||||
var LoggerAbstract = require('../../src/lib/logger');
|
||||
var TracerLogger = require('../../src/lib/loggers/tracer');
|
||||
var now = new Date('2013-03-01T00:00:00Z');
|
||||
var sinon = require('sinon');
|
||||
const expect = require('expect.js');
|
||||
const Log = require('../../src/lib/log');
|
||||
const LoggerAbstract = require('../../src/lib/logger');
|
||||
const TracerLogger = require('../../src/lib/loggers/tracer');
|
||||
const now = new Date('2013-03-01T00:00:00Z');
|
||||
const sinon = require('sinon');
|
||||
|
||||
module.exports = function (makeLogger) {
|
||||
var stub = require('../utils/auto_release_stub').make();
|
||||
var parent = new Log();
|
||||
const stub = require('../utils/auto_release_stub').make();
|
||||
const parent = new Log();
|
||||
|
||||
afterEach(function () {
|
||||
parent.close();
|
||||
@ -15,7 +15,7 @@ module.exports = function (makeLogger) {
|
||||
|
||||
describe('Constuctor', function () {
|
||||
it('calls setupListeners, passes its new levels', function () {
|
||||
var logger = makeLogger(parent);
|
||||
let logger = makeLogger(parent);
|
||||
stub(logger.constructor.prototype, 'setupListeners');
|
||||
parent.close();
|
||||
|
||||
@ -24,21 +24,21 @@ module.exports = function (makeLogger) {
|
||||
});
|
||||
|
||||
it('listens for the loggers\' "closing" event', function () {
|
||||
var logger = makeLogger(parent);
|
||||
const logger = makeLogger(parent);
|
||||
expect(parent.listenerCount('closing')).to.eql(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('listening levels', function () {
|
||||
it('calls cleanUpListeners when the listeners are being setup', function () {
|
||||
var logger = makeLogger();
|
||||
const logger = makeLogger();
|
||||
stub(logger, 'cleanUpListeners');
|
||||
logger.setupListeners([]);
|
||||
expect(logger.cleanUpListeners).to.have.property('callCount', 1);
|
||||
});
|
||||
|
||||
it('listens to just error when log is explicitly error', function () {
|
||||
var logger = makeLogger(parent, 'error');
|
||||
const logger = makeLogger(parent, 'error');
|
||||
expect(parent.listenerCount('error')).to.eql(1);
|
||||
expect(parent.listenerCount('warning')).to.eql(0);
|
||||
expect(parent.listenerCount('info')).to.eql(0);
|
||||
@ -47,7 +47,7 @@ module.exports = function (makeLogger) {
|
||||
});
|
||||
|
||||
it('listens for all the events when level is "trace"', function () {
|
||||
var logger = makeLogger(parent, 'trace');
|
||||
const logger = makeLogger(parent, 'trace');
|
||||
expect(parent.listenerCount('error')).to.eql(1);
|
||||
expect(parent.listenerCount('warning')).to.eql(1);
|
||||
expect(parent.listenerCount('info')).to.eql(1);
|
||||
@ -56,7 +56,7 @@ module.exports = function (makeLogger) {
|
||||
});
|
||||
|
||||
it('listens for specific events when level is an array', function () {
|
||||
var logger = makeLogger(parent, ['error', 'trace']);
|
||||
const logger = makeLogger(parent, ['error', 'trace']);
|
||||
expect(parent.listenerCount('error')).to.eql(1);
|
||||
expect(parent.listenerCount('warning')).to.eql(0);
|
||||
expect(parent.listenerCount('info')).to.eql(0);
|
||||
@ -65,8 +65,8 @@ module.exports = function (makeLogger) {
|
||||
});
|
||||
|
||||
it('sets the logLevel property to the new levels', function () {
|
||||
var logger = makeLogger();
|
||||
var levels = ['error'];
|
||||
const logger = makeLogger();
|
||||
let levels = ['error'];
|
||||
logger.setupListeners(levels);
|
||||
expect(logger.listeningLevels).to.eql(levels).and.not.be(levels);
|
||||
|
||||
@ -80,14 +80,14 @@ module.exports = function (makeLogger) {
|
||||
});
|
||||
|
||||
it('rejects listening levels it can not listen to', function () {
|
||||
var logger = makeLogger();
|
||||
const logger = makeLogger();
|
||||
expect(function () {
|
||||
logger.setupListeners(['scream']);
|
||||
}).to.throwError(/unable to listen/i);
|
||||
});
|
||||
|
||||
it('emits events because something is listening', function () {
|
||||
var logger = makeLogger(parent, 'trace');
|
||||
const logger = makeLogger(parent, 'trace');
|
||||
stub(parent, 'emit');
|
||||
|
||||
parent.error(new Error('error message'));
|
||||
@ -110,7 +110,7 @@ module.exports = function (makeLogger) {
|
||||
describe('#timestamp', function () {
|
||||
it('returns in the right format', function () {
|
||||
stub.autoRelease(sinon.useFakeTimers(now.getTime()));
|
||||
var logger = makeLogger();
|
||||
const logger = makeLogger();
|
||||
expect(logger.timestamp()).to.eql('2013-03-01T00:00:00Z');
|
||||
});
|
||||
});
|
||||
@ -118,7 +118,7 @@ module.exports = function (makeLogger) {
|
||||
describe('#format', function () {
|
||||
it('returns a single string with the message indented', function () {
|
||||
stub.autoRelease(sinon.useFakeTimers(now.getTime()));
|
||||
var logger = makeLogger();
|
||||
const logger = makeLogger();
|
||||
expect(logger.format('LABEL', 'MSG')).to.eql(
|
||||
'LABEL: 2013-03-01T00:00:00Z\n' +
|
||||
' MSG\n' +
|
||||
@ -128,7 +128,7 @@ module.exports = function (makeLogger) {
|
||||
|
||||
it('properly indents multi-line messages', function () {
|
||||
stub.autoRelease(sinon.useFakeTimers(now.getTime()));
|
||||
var logger = makeLogger();
|
||||
const logger = makeLogger();
|
||||
expect(logger.format('LABEL', 'MSG\nwith\nseveral lines')).to.eql(
|
||||
'LABEL: 2013-03-01T00:00:00Z\n' +
|
||||
' MSG\n' +
|
||||
@ -141,7 +141,7 @@ module.exports = function (makeLogger) {
|
||||
|
||||
describe('#onError', function () {
|
||||
it('uses the Error name when it is not just "Error"', function () {
|
||||
var logger = makeLogger();
|
||||
const logger = makeLogger();
|
||||
stub(logger, 'write', function (label, msg) {
|
||||
expect(label).to.eql('TypeError');
|
||||
});
|
||||
@ -151,7 +151,7 @@ module.exports = function (makeLogger) {
|
||||
});
|
||||
|
||||
it('uses "ERROR" when the error name is "Error"', function () {
|
||||
var logger = makeLogger();
|
||||
const logger = makeLogger();
|
||||
stub(logger, 'write', function (label, msg) {
|
||||
expect(label).to.eql('ERROR');
|
||||
});
|
||||
@ -163,7 +163,7 @@ module.exports = function (makeLogger) {
|
||||
|
||||
describe('#onWarning', function () {
|
||||
it('uses the "WARNING" label', function () {
|
||||
var logger = makeLogger();
|
||||
const logger = makeLogger();
|
||||
stub(logger, 'write', function (label, msg) {
|
||||
expect(label).to.eql('WARNING');
|
||||
});
|
||||
@ -172,7 +172,7 @@ module.exports = function (makeLogger) {
|
||||
});
|
||||
|
||||
it('echos the message', function () {
|
||||
var logger = makeLogger();
|
||||
const logger = makeLogger();
|
||||
stub(logger, 'write', function (label, msg) {
|
||||
expect(msg).to.eql('message');
|
||||
});
|
||||
@ -184,7 +184,7 @@ module.exports = function (makeLogger) {
|
||||
|
||||
describe('#onInfo', function () {
|
||||
it('uses the "INFO" label', function () {
|
||||
var logger = makeLogger();
|
||||
const logger = makeLogger();
|
||||
stub(logger, 'write', function (label, msg) {
|
||||
expect(label).to.eql('INFO');
|
||||
});
|
||||
@ -193,7 +193,7 @@ module.exports = function (makeLogger) {
|
||||
});
|
||||
|
||||
it('echos the message', function () {
|
||||
var logger = makeLogger();
|
||||
const logger = makeLogger();
|
||||
stub(logger, 'write', function (label, msg) {
|
||||
expect(msg).to.eql('message');
|
||||
});
|
||||
@ -205,7 +205,7 @@ module.exports = function (makeLogger) {
|
||||
|
||||
describe('#onDebug', function () {
|
||||
it('uses the "DEBUG" label', function () {
|
||||
var logger = makeLogger();
|
||||
const logger = makeLogger();
|
||||
stub(logger, 'write', function (label, msg) {
|
||||
expect(label).to.eql('DEBUG');
|
||||
});
|
||||
@ -214,7 +214,7 @@ module.exports = function (makeLogger) {
|
||||
});
|
||||
|
||||
it('echos the message', function () {
|
||||
var logger = makeLogger();
|
||||
const logger = makeLogger();
|
||||
stub(logger, 'write', function (label, msg) {
|
||||
expect(msg).to.eql('message');
|
||||
});
|
||||
@ -226,7 +226,7 @@ module.exports = function (makeLogger) {
|
||||
|
||||
describe('#onTrace', function () {
|
||||
it('uses the "TRACE" label', function () {
|
||||
var logger = makeLogger();
|
||||
const logger = makeLogger();
|
||||
stub(logger, 'write', function (label, msg) {
|
||||
expect(label).to.eql('TRACE');
|
||||
});
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
require('bluebird').longStackTraces();
|
||||
|
||||
var specDir = __dirname + '/specs';
|
||||
const specDir = __dirname + '/specs';
|
||||
require('fs').readdirSync(specDir).forEach(function (file) {
|
||||
require(specDir + '/' + file);
|
||||
});
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
describe('Logger Abstract', function () {
|
||||
var expect = require('expect.js');
|
||||
var sinon = require('sinon');
|
||||
var Log = require('../../../src/lib/log');
|
||||
var LoggerAbstract = require('../../../src/lib/logger');
|
||||
const expect = require('expect.js');
|
||||
const sinon = require('sinon');
|
||||
const Log = require('../../../src/lib/log');
|
||||
const LoggerAbstract = require('../../../src/lib/logger');
|
||||
|
||||
var parentLog;
|
||||
var stub = require('../../utils/auto_release_stub').make();
|
||||
let parentLog;
|
||||
const stub = require('../../utils/auto_release_stub').make();
|
||||
|
||||
function makeLogger(parent, levels) {
|
||||
return new LoggerAbstract(parent || parentLog, {
|
||||
@ -24,7 +24,7 @@ describe('Logger Abstract', function () {
|
||||
describe('#write', function () {
|
||||
it('requires that it is overwritten', function () {
|
||||
expect(function () {
|
||||
var logger = makeLogger();
|
||||
const logger = makeLogger();
|
||||
logger.write();
|
||||
}).to.throwError(/overwritten/);
|
||||
});
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
describe('Client instances creation', function () {
|
||||
var stream = require('stream');
|
||||
var util = require('util');
|
||||
const stream = require('stream');
|
||||
const util = require('util');
|
||||
|
||||
var es = require('../../../src/elasticsearch');
|
||||
var apis = require('../../../src/lib/apis');
|
||||
var expect = require('expect.js');
|
||||
var stub = require('../../utils/auto_release_stub').make();
|
||||
var client;
|
||||
const es = require('../../../src/elasticsearch');
|
||||
const apis = require('../../../src/lib/apis');
|
||||
const expect = require('expect.js');
|
||||
const stub = require('../../utils/auto_release_stub').make();
|
||||
let client;
|
||||
|
||||
describe('', function () {
|
||||
beforeEach(function () {
|
||||
@ -18,16 +18,16 @@ describe('Client instances creation', function () {
|
||||
});
|
||||
|
||||
it('throws an error linking to the es module when you try to instanciate the exports', function () {
|
||||
var Es = es;
|
||||
const Es = es;
|
||||
expect(function () {
|
||||
var c = new Es();
|
||||
return c
|
||||
const c = new Es();
|
||||
return c;
|
||||
}).to.throwError(/previous "elasticsearch" module/);
|
||||
});
|
||||
|
||||
var pkg = require('../../../package.json');
|
||||
var def = pkg.config.default_api_branch;
|
||||
var prev = pkg.config.supported_es_branches[pkg.config.supported_es_branches.indexOf(def) + 1];
|
||||
const pkg = require('../../../package.json');
|
||||
const def = pkg.config.default_api_branch;
|
||||
const prev = pkg.config.supported_es_branches[pkg.config.supported_es_branches.indexOf(def) + 1];
|
||||
|
||||
it('inherits the ' + def + ' API by default', function () {
|
||||
expect(client.bulk).to.be(apis[def].bulk);
|
||||
@ -44,7 +44,7 @@ describe('Client instances creation', function () {
|
||||
});
|
||||
|
||||
it('closing the client causes it\'s transport to be closed', function () {
|
||||
var called = false;
|
||||
let called = false;
|
||||
client.transport.close = function () {
|
||||
called = true;
|
||||
};
|
||||
@ -72,7 +72,7 @@ describe('Client instances creation', function () {
|
||||
done();
|
||||
};
|
||||
|
||||
var client = new es.Client({
|
||||
const client = new es.Client({
|
||||
log: [
|
||||
{ type: 'stream', stream: new NullStream() }
|
||||
]
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
var ca = require('../../../src/lib/client_action').factory;
|
||||
var proxy = require('../../../src/lib/client_action').proxyFactory;
|
||||
var expect = require('expect.js');
|
||||
var _ = require('lodash');
|
||||
var Promise = require('bluebird');
|
||||
const ca = require('../../../src/lib/client_action').factory;
|
||||
const proxy = require('../../../src/lib/client_action').proxyFactory;
|
||||
const expect = require('expect.js');
|
||||
const _ = require('lodash');
|
||||
const Promise = require('bluebird');
|
||||
|
||||
/**
|
||||
* Creates a simple mock of the client, whose "transport" has a request
|
||||
@ -60,13 +60,13 @@ function makeClientActionProxy(fn, spec) {
|
||||
|
||||
|
||||
describe('Client Action runner', function () {
|
||||
var action;
|
||||
let action;
|
||||
|
||||
// used to check that params are not clobbered
|
||||
var params = (function () {
|
||||
var _stash = {};
|
||||
const params = (function () {
|
||||
let _stash = {};
|
||||
afterEach(function () { _stash = {}; });
|
||||
var make = function (params) {
|
||||
const make = function (params) {
|
||||
_stash.orig = params;
|
||||
_stash.copy = _.clone(params);
|
||||
return params;
|
||||
@ -92,7 +92,7 @@ describe('Client Action runner', function () {
|
||||
|
||||
describe('clientAction::proxy', function () {
|
||||
it('proxies to the passed function', function () {
|
||||
var action = makeClientActionProxy(function (params, cb) {
|
||||
const action = makeClientActionProxy(function (params, cb) {
|
||||
throw new Error('proxy function called');
|
||||
});
|
||||
|
||||
@ -102,8 +102,8 @@ describe('Client Action runner', function () {
|
||||
});
|
||||
|
||||
it('provides the proper context', function (done) {
|
||||
var client;
|
||||
var action = makeClientActionProxy(function (params, cb) {
|
||||
let client;
|
||||
const action = makeClientActionProxy(function (params, cb) {
|
||||
client = this;
|
||||
process.nextTick(function () {
|
||||
cb(void 0, params);
|
||||
@ -117,7 +117,7 @@ describe('Client Action runner', function () {
|
||||
});
|
||||
|
||||
it('handles passing just the callback', function () {
|
||||
var action = makeClientActionProxy(function (params, cb) {
|
||||
const action = makeClientActionProxy(function (params, cb) {
|
||||
expect(_.isObject(params)).to.be.ok();
|
||||
expect(cb).to.be.a('function');
|
||||
});
|
||||
@ -126,7 +126,7 @@ describe('Client Action runner', function () {
|
||||
});
|
||||
|
||||
it('supports a param transformation function', function () {
|
||||
var action = makeClientActionProxy(function (params, cb) {
|
||||
const action = makeClientActionProxy(function (params, cb) {
|
||||
expect(params).to.have.property('transformed');
|
||||
}, {
|
||||
transform: function (params) {
|
||||
@ -138,8 +138,8 @@ describe('Client Action runner', function () {
|
||||
});
|
||||
|
||||
it('returns the proxied function\'s return value', function () {
|
||||
var football = {};
|
||||
var action = makeClientActionProxy(function (params, cb) {
|
||||
const football = {};
|
||||
const action = makeClientActionProxy(function (params, cb) {
|
||||
return football;
|
||||
});
|
||||
|
||||
@ -537,7 +537,7 @@ describe('Client Action runner', function () {
|
||||
});
|
||||
|
||||
it('accepts numbers, strings, and dates', function (done) {
|
||||
var now = new Date();
|
||||
const now = new Date();
|
||||
|
||||
action({
|
||||
one: '42',
|
||||
@ -587,7 +587,7 @@ describe('Client Action runner', function () {
|
||||
|
||||
describe('passing of control params from spec', function () {
|
||||
it('passes bulkBody', function (done) {
|
||||
var action = makeClientAction({
|
||||
const action = makeClientAction({
|
||||
bulkBody: true
|
||||
});
|
||||
|
||||
@ -598,7 +598,7 @@ describe('Client Action runner', function () {
|
||||
});
|
||||
|
||||
it('sets castExists when the method in the spec is HEAD', function (done) {
|
||||
var action = makeClientAction({
|
||||
const action = makeClientAction({
|
||||
method: 'HEAD'
|
||||
});
|
||||
|
||||
@ -610,12 +610,12 @@ describe('Client Action runner', function () {
|
||||
});
|
||||
|
||||
describe('body handling', function () {
|
||||
var action = makeClientAction({
|
||||
const action = makeClientAction({
|
||||
needsBody: true
|
||||
});
|
||||
|
||||
it('passed the body when it is set', function (done) {
|
||||
var body = '{"JSON":"PLEASE"}';
|
||||
const body = '{"JSON":"PLEASE"}';
|
||||
|
||||
action({ body: body }, function (err, params) {
|
||||
expect(params.body).to.be(body);
|
||||
@ -635,7 +635,7 @@ describe('Client Action runner', function () {
|
||||
|
||||
describe('passing of http method', function () {
|
||||
it('uppercases and passed the default method', function (done) {
|
||||
var action = makeClientAction({
|
||||
const action = makeClientAction({
|
||||
method: 'POST'
|
||||
});
|
||||
|
||||
@ -646,7 +646,7 @@ describe('Client Action runner', function () {
|
||||
});
|
||||
|
||||
it('uppercases and passed the default method', function (done) {
|
||||
var action = makeClientAction({
|
||||
const action = makeClientAction({
|
||||
method: 'POST'
|
||||
});
|
||||
|
||||
@ -659,7 +659,7 @@ describe('Client Action runner', function () {
|
||||
|
||||
describe('passing of ignore param', function () {
|
||||
it('passes ignore as an array', function (done) {
|
||||
var action = makeClientAction({});
|
||||
const action = makeClientAction({});
|
||||
action({ ignore: 404 }, function (err, params) {
|
||||
expect(params.ignore).to.eql([404]);
|
||||
done();
|
||||
@ -669,7 +669,7 @@ describe('Client Action runner', function () {
|
||||
|
||||
describe('passing requestTimeout', function () {
|
||||
it('passes passes the spec value by default', function (done) {
|
||||
var action = makeClientAction({
|
||||
const action = makeClientAction({
|
||||
requestTimeout: 100
|
||||
});
|
||||
|
||||
@ -680,7 +680,7 @@ describe('Client Action runner', function () {
|
||||
});
|
||||
|
||||
it('passes the provided value', function (done) {
|
||||
var action = makeClientAction({
|
||||
const action = makeClientAction({
|
||||
requestTimeout: 100
|
||||
});
|
||||
|
||||
@ -691,7 +691,7 @@ describe('Client Action runner', function () {
|
||||
});
|
||||
|
||||
it('passes nothing be default', function (done) {
|
||||
var action = makeClientAction({});
|
||||
const action = makeClientAction({});
|
||||
|
||||
action({}, function (err, params) {
|
||||
expect(params.requestTimeout).be(void 0);
|
||||
@ -702,7 +702,7 @@ describe('Client Action runner', function () {
|
||||
|
||||
describe('url resolver', function () {
|
||||
|
||||
var action = makeClientAction({
|
||||
const action = makeClientAction({
|
||||
urls: [
|
||||
{
|
||||
fmt: '/<%=index%>/<%=type%>/<%=id%>/<%=thing%>',
|
||||
@ -767,7 +767,7 @@ describe('Client Action runner', function () {
|
||||
});
|
||||
|
||||
describe('param collection', function () {
|
||||
var action = makeClientAction({
|
||||
const action = makeClientAction({
|
||||
params: {
|
||||
a: { type: 'list', required: true },
|
||||
b: { type: 'duration', 'default': '15m' },
|
||||
@ -853,7 +853,7 @@ describe('Client Action runner', function () {
|
||||
});
|
||||
|
||||
it('does not modify the incoming params object', function () {
|
||||
var action = makeClientAction({
|
||||
const action = makeClientAction({
|
||||
url: {
|
||||
req: {
|
||||
index: { type: 'string' }
|
||||
|
||||
@ -1,42 +1,42 @@
|
||||
var ConnectionAbstract = require('../../../src/lib/connection');
|
||||
var Host = require('../../../src/lib/host');
|
||||
var sinon = require('sinon');
|
||||
var expect = require('expect.js');
|
||||
var _ = require('lodash');
|
||||
var errors = require('../../../src/lib/errors');
|
||||
const ConnectionAbstract = require('../../../src/lib/connection');
|
||||
const Host = require('../../../src/lib/host');
|
||||
const sinon = require('sinon');
|
||||
const expect = require('expect.js');
|
||||
const _ = require('lodash');
|
||||
const errors = require('../../../src/lib/errors');
|
||||
|
||||
var stub = require('../../utils/auto_release_stub').make();
|
||||
const stub = require('../../utils/auto_release_stub').make();
|
||||
|
||||
describe('Connection Abstract', function () {
|
||||
var host = new Host('localhost:9200');
|
||||
const host = new Host('localhost:9200');
|
||||
|
||||
it('constructs with defaults for host, and bound', function () {
|
||||
var conn = new ConnectionAbstract(host);
|
||||
const conn = new ConnectionAbstract(host);
|
||||
expect(conn.host).to.be(host);
|
||||
});
|
||||
|
||||
it('requires a valid host', function () {
|
||||
expect(function () {
|
||||
var conn = new ConnectionAbstract();
|
||||
const conn = new ConnectionAbstract();
|
||||
}).to.throwError(TypeError);
|
||||
|
||||
expect(function () {
|
||||
var conn = new ConnectionAbstract({});
|
||||
const conn = new ConnectionAbstract({});
|
||||
}).to.throwError(TypeError);
|
||||
});
|
||||
|
||||
it('required that the request method is overridden', function () {
|
||||
expect(function () {
|
||||
var conn = new ConnectionAbstract(host);
|
||||
const conn = new ConnectionAbstract(host);
|
||||
conn.request();
|
||||
}).to.throwError(/overwrit/);
|
||||
});
|
||||
|
||||
describe('#ping', function () {
|
||||
it('accpets just a callback', function () {
|
||||
var conn = new ConnectionAbstract(host);
|
||||
const conn = new ConnectionAbstract(host);
|
||||
stub(conn, 'request');
|
||||
var cb = function () {};
|
||||
const cb = function () {};
|
||||
conn.ping(cb);
|
||||
expect(conn.request.callCount).to.eql(1);
|
||||
expect(conn.request.lastCall.args[0]).to.be.a('object');
|
||||
@ -44,7 +44,7 @@ describe('Connection Abstract', function () {
|
||||
});
|
||||
|
||||
it('accpets just params', function () {
|
||||
var conn = new ConnectionAbstract(host);
|
||||
const conn = new ConnectionAbstract(host);
|
||||
stub(conn, 'request');
|
||||
conn.ping({});
|
||||
expect(conn.request.callCount).to.eql(1);
|
||||
@ -53,9 +53,9 @@ describe('Connection Abstract', function () {
|
||||
});
|
||||
|
||||
it('allows overriding the requestTimeout, method, and path', function () {
|
||||
var conn = new ConnectionAbstract(host);
|
||||
const conn = new ConnectionAbstract(host);
|
||||
stub(conn, 'request');
|
||||
var params = {
|
||||
const params = {
|
||||
method: 'HEAD',
|
||||
path: '/',
|
||||
requestTimeout: 10000
|
||||
@ -67,8 +67,8 @@ describe('Connection Abstract', function () {
|
||||
});
|
||||
|
||||
it('defaults to the pingTimeout in the config', function () {
|
||||
var conn = new ConnectionAbstract(host, { pingTimeout: 5000 });
|
||||
var clock = sinon.useFakeTimers('setTimeout', 'clearTimeout');
|
||||
const conn = new ConnectionAbstract(host, { pingTimeout: 5000 });
|
||||
const clock = sinon.useFakeTimers('setTimeout', 'clearTimeout');
|
||||
stub.autoRelease(clock);
|
||||
|
||||
stub(conn, 'request');
|
||||
@ -80,17 +80,17 @@ describe('Connection Abstract', function () {
|
||||
});
|
||||
|
||||
it('calls it\'s own request method', function () {
|
||||
var conn = new ConnectionAbstract(host);
|
||||
const conn = new ConnectionAbstract(host);
|
||||
stub(conn, 'request');
|
||||
conn.ping();
|
||||
expect(conn.request.callCount).to.eql(1);
|
||||
});
|
||||
|
||||
it('sets a timer for the request', function (done) {
|
||||
var conn = new ConnectionAbstract(host);
|
||||
var clock = sinon.useFakeTimers('setTimeout', 'clearTimeout');
|
||||
const conn = new ConnectionAbstract(host);
|
||||
const clock = sinon.useFakeTimers('setTimeout', 'clearTimeout');
|
||||
stub.autoRelease(clock);
|
||||
var order = 0;
|
||||
let order = 0;
|
||||
|
||||
stub(conn, 'request', function (params, cb) {
|
||||
setTimeout(function () {
|
||||
@ -113,10 +113,10 @@ describe('Connection Abstract', function () {
|
||||
});
|
||||
});
|
||||
it('calls the requestAborter if req takes too long', function (done) {
|
||||
var conn = new ConnectionAbstract(host);
|
||||
var clock = sinon.useFakeTimers('setTimeout', 'clearTimeout');
|
||||
const conn = new ConnectionAbstract(host);
|
||||
const clock = sinon.useFakeTimers('setTimeout', 'clearTimeout');
|
||||
stub.autoRelease(clock);
|
||||
var order = 0;
|
||||
let order = 0;
|
||||
|
||||
stub(conn, 'request', function (params, cb) {
|
||||
setTimeout(function () {
|
||||
@ -148,8 +148,8 @@ describe('Connection Abstract', function () {
|
||||
|
||||
describe('#setStatus', function () {
|
||||
it('emits the "status set" event with `new`, `old` & `conn` args', function () {
|
||||
var conn = new ConnectionAbstract(host);
|
||||
var emitted = false;
|
||||
const conn = new ConnectionAbstract(host);
|
||||
let emitted = false;
|
||||
|
||||
conn.emit = function (eventName) {
|
||||
emitted = {
|
||||
@ -164,7 +164,7 @@ describe('Connection Abstract', function () {
|
||||
});
|
||||
|
||||
it('stores the status in this.status', function () {
|
||||
var conn = new ConnectionAbstract(host);
|
||||
const conn = new ConnectionAbstract(host);
|
||||
|
||||
conn.setStatus('closed');
|
||||
expect(conn.status).to.eql('closed');
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
var ConnectionPool = require('../../../src/lib/connection_pool');
|
||||
var Host = require('../../../src/lib/host');
|
||||
var ConnectionAbstract = require('../../../src/lib/connection');
|
||||
var _ = require('lodash');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var expect = require('expect.js');
|
||||
var sinon = require('sinon');
|
||||
var stub = require('../../utils/auto_release_stub').make();
|
||||
const ConnectionPool = require('../../../src/lib/connection_pool');
|
||||
const Host = require('../../../src/lib/host');
|
||||
const ConnectionAbstract = require('../../../src/lib/connection');
|
||||
const _ = require('lodash');
|
||||
const EventEmitter = require('events').EventEmitter;
|
||||
const expect = require('expect.js');
|
||||
const sinon = require('sinon');
|
||||
const stub = require('../../utils/auto_release_stub').make();
|
||||
|
||||
function listenerCount(emitter, event) {
|
||||
if (EventEmitter.listenerCount) {
|
||||
@ -19,7 +19,7 @@ function listenerCount(emitter, event) {
|
||||
|
||||
describe('Connection Pool', function () {
|
||||
describe('Adding/Removing/Syncing Connections', function () {
|
||||
var pool, host, connection, host2, connection2;
|
||||
let pool, host, connection, host2, connection2;
|
||||
|
||||
beforeEach(function () {
|
||||
pool = new ConnectionPool({});
|
||||
@ -93,7 +93,7 @@ describe('Connection Pool', function () {
|
||||
});
|
||||
|
||||
describe('Connection selection', function () {
|
||||
var pool, host, host2;
|
||||
let pool, host, host2;
|
||||
|
||||
beforeEach(function () {
|
||||
pool = new ConnectionPool({});
|
||||
@ -135,7 +135,7 @@ describe('Connection Pool', function () {
|
||||
return list[0];
|
||||
};
|
||||
|
||||
var selected = null;
|
||||
let selected = null;
|
||||
|
||||
pool.select(function (err, selection) {
|
||||
if (err) { throw err; }
|
||||
@ -163,20 +163,20 @@ describe('Connection Pool', function () {
|
||||
describe('Connection selection with no living nodes', function () {
|
||||
it('should ping all of the dead nodes, in order of oldest timeout, and return the first that\'s okay',
|
||||
function (done) {
|
||||
var clock = sinon.useFakeTimers('setTimeout', 'clearTimeout');
|
||||
const clock = sinon.useFakeTimers('setTimeout', 'clearTimeout');
|
||||
stub.autoRelease(clock);
|
||||
var pool = new ConnectionPool({
|
||||
const pool = new ConnectionPool({
|
||||
deadTimeout: 10000
|
||||
});
|
||||
|
||||
var connections = [
|
||||
const connections = [
|
||||
new ConnectionAbstract(new Host('http://localhost:9200')),
|
||||
new ConnectionAbstract(new Host('http://localhost:9201')),
|
||||
new ConnectionAbstract(new Host('http://localhost:9202')),
|
||||
new ConnectionAbstract(new Host('http://localhost:9203'))
|
||||
];
|
||||
var pingQueue = _.shuffle(connections);
|
||||
var expectedSelection = pingQueue[pingQueue.length - 1];
|
||||
const pingQueue = _.shuffle(connections);
|
||||
const expectedSelection = pingQueue[pingQueue.length - 1];
|
||||
|
||||
_.each(pingQueue, function (conn) {
|
||||
pool.addConnection(conn);
|
||||
@ -184,7 +184,7 @@ describe('Connection Pool', function () {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
}
|
||||
var expectedConn = pingQueue.shift();
|
||||
const expectedConn = pingQueue.shift();
|
||||
expect(conn).to.be(expectedConn);
|
||||
if (pingQueue.length) {
|
||||
process.nextTick(function () {
|
||||
@ -211,7 +211,7 @@ describe('Connection Pool', function () {
|
||||
});
|
||||
|
||||
describe('Connection state management', function () {
|
||||
var pool, host, host2, connection, connection2;
|
||||
let pool, host, host2, connection, connection2;
|
||||
|
||||
beforeEach(function () {
|
||||
pool = new ConnectionPool({});
|
||||
@ -243,12 +243,12 @@ describe('Connection Pool', function () {
|
||||
});
|
||||
|
||||
it('clears and resets the timeout when a connection redies', function () {
|
||||
var clock = sinon.useFakeTimers();
|
||||
const clock = sinon.useFakeTimers();
|
||||
stub.autoRelease(clock);
|
||||
|
||||
connection.setStatus('dead');
|
||||
expect(_.size(clock.timers)).to.eql(1);
|
||||
var id = _(clock.timers).keys().first();
|
||||
const id = _(clock.timers).keys().first();
|
||||
|
||||
// it re-dies
|
||||
connection.setStatus('dead');
|
||||
@ -257,8 +257,8 @@ describe('Connection Pool', function () {
|
||||
});
|
||||
|
||||
it('does nothing when a connection is re-alive', function () {
|
||||
var last = pool._conns.alive[pool._conns.alive.length - 1];
|
||||
var first = pool._conns.alive[0];
|
||||
const last = pool._conns.alive[pool._conns.alive.length - 1];
|
||||
const first = pool._conns.alive[0];
|
||||
|
||||
expect(last).to.not.be(first);
|
||||
|
||||
@ -286,17 +286,17 @@ describe('Connection Pool', function () {
|
||||
|
||||
describe('#getConnections', function () {
|
||||
it('will return all values from the alive list by default', function () {
|
||||
var pool = new ConnectionPool({});
|
||||
const pool = new ConnectionPool({});
|
||||
pool._conns.alive = new Array(1000);
|
||||
var length = pool._conns.alive.length;
|
||||
let length = pool._conns.alive.length;
|
||||
while (length--) {
|
||||
pool._conns.alive[length] = length;
|
||||
}
|
||||
|
||||
var result = pool.getConnections();
|
||||
const result = pool.getConnections();
|
||||
expect(result.length).to.be(1000);
|
||||
expect(_.reduce(result, function (sum, num) {
|
||||
sum += num
|
||||
sum += num;
|
||||
return sum;
|
||||
}, 0)).to.eql(499500);
|
||||
});
|
||||
@ -304,14 +304,14 @@ describe('Connection Pool', function () {
|
||||
|
||||
describe('#calcDeadTimeout', function () {
|
||||
it('should be configurable via config.calcDeadTimeout', function () {
|
||||
var pool = new ConnectionPool({
|
||||
const pool = new ConnectionPool({
|
||||
calcDeadTimeout: 'flat'
|
||||
});
|
||||
expect(pool.calcDeadTimeout).to.be(ConnectionPool.calcDeadTimeoutOptions.flat);
|
||||
pool.close();
|
||||
});
|
||||
it('"flat" always returns the base timeout', function () {
|
||||
var pool = new ConnectionPool({
|
||||
const pool = new ConnectionPool({
|
||||
calcDeadTimeout: 'flat'
|
||||
});
|
||||
expect(pool.calcDeadTimeout(0, 1000)).to.eql(1000);
|
||||
@ -319,7 +319,7 @@ describe('Connection Pool', function () {
|
||||
expect(pool.calcDeadTimeout(25, 10000)).to.eql(10000);
|
||||
});
|
||||
it('"exponential" always increases the timeout based on the attempts', function () {
|
||||
var pool = new ConnectionPool({
|
||||
const pool = new ConnectionPool({
|
||||
calcDeadTimeout: 'exponential'
|
||||
});
|
||||
expect(pool.calcDeadTimeout(0, 1000)).to.eql(1000);
|
||||
@ -327,7 +327,7 @@ describe('Connection Pool', function () {
|
||||
expect(pool.calcDeadTimeout(25, 10000)).to.be.greaterThan(10000);
|
||||
});
|
||||
it('"exponential" produces predicatable results', function () {
|
||||
var pool = new ConnectionPool({
|
||||
const pool = new ConnectionPool({
|
||||
calcDeadTimeout: 'exponential'
|
||||
});
|
||||
expect(pool.calcDeadTimeout(0, 1000)).to.eql(1000);
|
||||
@ -336,7 +336,7 @@ describe('Connection Pool', function () {
|
||||
expect(pool.calcDeadTimeout(25, 30000)).to.eql(18e5);
|
||||
});
|
||||
it('"exponential" repects config.maxDeadtimeout', function () {
|
||||
var pool = new ConnectionPool({
|
||||
const pool = new ConnectionPool({
|
||||
calcDeadTimeout: 'exponential',
|
||||
maxDeadTimeout: 10000
|
||||
});
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
var Log = require('../../../src/lib/log');
|
||||
var ConsoleLogger = require('../../../src/lib/loggers/console');
|
||||
var sinon = require('sinon');
|
||||
var expect = require('expect.js');
|
||||
var parentLog;
|
||||
const Log = require('../../../src/lib/log');
|
||||
const ConsoleLogger = require('../../../src/lib/loggers/console');
|
||||
const sinon = require('sinon');
|
||||
const expect = require('expect.js');
|
||||
let parentLog;
|
||||
|
||||
beforeEach(function () {
|
||||
parentLog = new Log();
|
||||
@ -14,24 +14,24 @@ afterEach(function () {
|
||||
|
||||
function makeLogger(parent, levels) {
|
||||
parent = parent || parentLog;
|
||||
var config = {
|
||||
const config = {
|
||||
levels: Log.parseLevels(levels || 'trace')
|
||||
};
|
||||
return new ConsoleLogger(parent, config);
|
||||
}
|
||||
|
||||
var stub = require('../../utils/auto_release_stub').make();
|
||||
const stub = require('../../utils/auto_release_stub').make();
|
||||
|
||||
describe('Console Logger', function () {
|
||||
|
||||
require('../generic_logger_tests')(makeLogger);
|
||||
|
||||
it('checks before using unique logging functions, falls back to #log()', function () {
|
||||
var _warning = console.warn;
|
||||
const _warning = console.warn;
|
||||
console.warn = null;
|
||||
sinon.stub(console, 'log');
|
||||
|
||||
var logger = makeLogger();
|
||||
const logger = makeLogger();
|
||||
|
||||
logger.onWarning('message');
|
||||
expect(console.log.callCount).to.be(1);
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
var errors = require('../../../src/lib/errors');
|
||||
var expect = require('expect.js');
|
||||
var _ = require('lodash');
|
||||
const errors = require('../../../src/lib/errors');
|
||||
const expect = require('expect.js');
|
||||
const _ = require('lodash');
|
||||
|
||||
_.each(errors, function (CustomError, name) {
|
||||
if (name.charAt(0) !== '_') {
|
||||
describe(name, function () {
|
||||
it('extend the ErrorAbstract and Error classes', function () {
|
||||
var err = new CustomError();
|
||||
const err = new CustomError();
|
||||
expect(err).to.be.an(Error);
|
||||
expect(err).to.be.an(errors._Abstract);
|
||||
});
|
||||
@ -16,9 +16,9 @@ _.each(errors, function (CustomError, name) {
|
||||
|
||||
describe('Error Abstract', function () {
|
||||
it('provides a stack property in the browser', function () {
|
||||
var isBrowser = process.browser;
|
||||
const isBrowser = process.browser;
|
||||
process.browser = true;
|
||||
var err = new errors._Abstract();
|
||||
const err = new errors._Abstract();
|
||||
process.browser = isBrowser;
|
||||
|
||||
expect(err.stack).to.be.a('string');
|
||||
@ -27,7 +27,7 @@ describe('Error Abstract', function () {
|
||||
|
||||
describe('StatusCodeError', function () {
|
||||
it('exposes status code as a number', function () {
|
||||
var err = new errors['404']();
|
||||
const err = new errors['404']();
|
||||
expect(err.status).to.be(404);
|
||||
expect(err.status).to.not.be('404');
|
||||
});
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
describe('File Logger', function () {
|
||||
var Log = require('../../../src/lib/log');
|
||||
var FileLogger = require('../../../src/lib/loggers/file');
|
||||
var once = require('events').EventEmitter.prototype.once;
|
||||
var _ = require('../../../src/lib/utils');
|
||||
var parentLog;
|
||||
var logger;
|
||||
var expect = require('expect.js');
|
||||
var fs = require('fs');
|
||||
var stub = require('../../utils/auto_release_stub').make();
|
||||
const Log = require('../../../src/lib/log');
|
||||
const FileLogger = require('../../../src/lib/loggers/file');
|
||||
const once = require('events').EventEmitter.prototype.once;
|
||||
const _ = require('../../../src/lib/utils');
|
||||
let parentLog;
|
||||
let logger;
|
||||
const expect = require('expect.js');
|
||||
const fs = require('fs');
|
||||
const stub = require('../../utils/auto_release_stub').make();
|
||||
|
||||
beforeEach(function () {
|
||||
parentLog = new Log();
|
||||
@ -36,9 +36,9 @@ describe('File Logger', function () {
|
||||
describe('buffer flush', function () {
|
||||
if (require('stream').Writable) {
|
||||
it('writes everything in the buffer to console.error', function () {
|
||||
var line = 'This string is written 10 times to create buffered output\n';
|
||||
const line = 'This string is written 10 times to create buffered output\n';
|
||||
|
||||
var exitHandler;
|
||||
let exitHandler;
|
||||
stub(process, 'once', function (event, handler) {
|
||||
if (event === 'exit') {
|
||||
exitHandler = handler;
|
||||
@ -46,7 +46,7 @@ describe('File Logger', function () {
|
||||
once.call(process, event, handler);
|
||||
});
|
||||
|
||||
var logger = makeLogger();
|
||||
const logger = makeLogger();
|
||||
|
||||
// write the line 10 times
|
||||
_.times(10, function () {
|
||||
@ -54,7 +54,7 @@ describe('File Logger', function () {
|
||||
});
|
||||
|
||||
// collect everything that is written to fs.appendFileSync
|
||||
var flushedOutput = '';
|
||||
let flushedOutput = '';
|
||||
stub(fs, 'appendFileSync', function (path, str) {
|
||||
flushedOutput += str;
|
||||
});
|
||||
@ -68,7 +68,7 @@ describe('File Logger', function () {
|
||||
});
|
||||
} else {
|
||||
it('does not fall apart with non streams2 streams', function () {
|
||||
var exitHandler;
|
||||
let exitHandler;
|
||||
stub(process, 'once', function (event, handler) {
|
||||
if (event === 'exit') {
|
||||
exitHandler = handler;
|
||||
@ -76,7 +76,7 @@ describe('File Logger', function () {
|
||||
once.call(process, event, handler);
|
||||
});
|
||||
|
||||
var logger = makeLogger();
|
||||
const logger = makeLogger();
|
||||
|
||||
expect(function () {
|
||||
// call the event handler
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
var Host = require('../../../src/lib/host');
|
||||
var _ = require('lodash');
|
||||
var expect = require('expect.js');
|
||||
var url = require('url');
|
||||
var expectSubObject = require('../../utils/expect_sub_object');
|
||||
const Host = require('../../../src/lib/host');
|
||||
const _ = require('lodash');
|
||||
const expect = require('expect.js');
|
||||
const url = require('url');
|
||||
const expectSubObject = require('../../utils/expect_sub_object');
|
||||
|
||||
var hostDefaults = {
|
||||
const hostDefaults = {
|
||||
protocol: 'http',
|
||||
host: 'localhost',
|
||||
port: 9200,
|
||||
@ -24,20 +24,20 @@ var hostDefaults = {
|
||||
}
|
||||
};
|
||||
|
||||
var base64 = function (str) {
|
||||
var buffer = Buffer.from ? Buffer.from(str, 'utf8') : new Buffer(str, 'utf8')
|
||||
return buffer.toString('base64')
|
||||
}
|
||||
const base64 = function (str) {
|
||||
const buffer = Buffer.from ? Buffer.from(str, 'utf8') : new Buffer(str, 'utf8');
|
||||
return buffer.toString('base64');
|
||||
};
|
||||
|
||||
describe('Host class', function () {
|
||||
describe('construction', function () {
|
||||
it('properly sets the defaults', function () {
|
||||
var host = new Host();
|
||||
const host = new Host();
|
||||
expect(host).to.eql(hostDefaults);
|
||||
});
|
||||
|
||||
it('accepts a string for query', function () {
|
||||
var host = new Host({ query: 'beep=boop' });
|
||||
const host = new Host({ query: 'beep=boop' });
|
||||
|
||||
expect(host.query).to.eql({
|
||||
beep: 'boop'
|
||||
@ -45,15 +45,15 @@ describe('Host class', function () {
|
||||
});
|
||||
|
||||
it('accepts other generic params', function () {
|
||||
var headers = { 'X-Special-Routing-Header': 'pie' };
|
||||
var host = new Host({ headers: headers });
|
||||
const headers = { 'X-Special-Routing-Header': 'pie' };
|
||||
const host = new Host({ headers: headers });
|
||||
|
||||
expect(host.headers).to.eql(headers);
|
||||
});
|
||||
|
||||
describe('from a string', function () {
|
||||
it('accepts a string for the entire url', function () {
|
||||
var host = new Host('john:dude@pizza.com:420/pizza/cheese?shrooms=true');
|
||||
const host = new Host('john:dude@pizza.com:420/pizza/cheese?shrooms=true');
|
||||
|
||||
expectSubObject(host, {
|
||||
protocol: 'http',
|
||||
@ -67,7 +67,7 @@ describe('Host class', function () {
|
||||
});
|
||||
|
||||
it('uses the default port based on the protocol', function () {
|
||||
var host;
|
||||
let host;
|
||||
|
||||
host = new Host('https://google.com');
|
||||
expect(host.port).to.be(443);
|
||||
@ -82,7 +82,7 @@ describe('Host class', function () {
|
||||
});
|
||||
|
||||
it('parses simple urls properly', function () {
|
||||
var host;
|
||||
let host;
|
||||
|
||||
host = new Host('localhost');
|
||||
expect(host.host).to.be('localhost');
|
||||
@ -108,19 +108,19 @@ describe('Host class', function () {
|
||||
|
||||
describe('based on the output from url.parse', function () {
|
||||
it('might cause weird things to happen', function () {
|
||||
var parsedUrl = url.parse('pizza.com:888');
|
||||
const parsedUrl = url.parse('pizza.com:888');
|
||||
|
||||
// I imagine most people don't expect
|
||||
expect(parsedUrl.protocol).to.eql('pizza.com:');
|
||||
expect(parsedUrl.host).to.eql('888');
|
||||
|
||||
var host = new Host(parsedUrl);
|
||||
const host = new Host(parsedUrl);
|
||||
expect(host.protocol).to.eql('pizza.com');
|
||||
expect(host.host).to.eql('888');
|
||||
});
|
||||
|
||||
it('will cause extra properties', function () {
|
||||
var host = new Host(url.parse('https://joe:diner@pizza.com:888/path?query=yes#section'));
|
||||
const host = new Host(url.parse('https://joe:diner@pizza.com:888/path?query=yes#section'));
|
||||
expect(host.protocol).to.eql('https');
|
||||
expect(host.host).to.eql('pizza.com');
|
||||
expect(host.port).to.eql(888);
|
||||
@ -135,13 +135,13 @@ describe('Host class', function () {
|
||||
});
|
||||
|
||||
it('ignores anything that\'s not a string or object-y', function () {
|
||||
var host = new Host(1234);
|
||||
const host = new Host(1234);
|
||||
|
||||
expect(host).to.eql(hostDefaults);
|
||||
});
|
||||
|
||||
it('defaults auth values from the `httpAuth` setting', function () {
|
||||
var host = new Host('http://localhost:9200', {
|
||||
const host = new Host('http://localhost:9200', {
|
||||
httpAuth: 'username:password'
|
||||
});
|
||||
|
||||
@ -151,7 +151,7 @@ describe('Host class', function () {
|
||||
|
||||
describe('#makeUrl', function () {
|
||||
it('merges parameters', function () {
|
||||
var host = new Host({
|
||||
const host = new Host({
|
||||
path: '/prefix',
|
||||
query: {
|
||||
user_id: 123
|
||||
@ -167,7 +167,7 @@ describe('Host class', function () {
|
||||
});
|
||||
|
||||
it('ensures that path starts with a forward-slash', function () {
|
||||
var host = new Host();
|
||||
const host = new Host();
|
||||
host.path = 'prefix';
|
||||
|
||||
expect(host.makeUrl({ path: '/this and that' }))
|
||||
@ -175,14 +175,14 @@ describe('Host class', function () {
|
||||
});
|
||||
|
||||
it('does not try to prevent double forward-slashes', function () {
|
||||
var host = new Host({ path: 'prefix/' });
|
||||
const host = new Host({ path: 'prefix/' });
|
||||
|
||||
expect(host.makeUrl({ path: '/this and that' }))
|
||||
.to.be('http://localhost:9200/prefix//this and that');
|
||||
});
|
||||
|
||||
it('creates proper url without any params', function () {
|
||||
var host = new Host({});
|
||||
let host = new Host({});
|
||||
expect(host.makeUrl()).to.be('http://localhost:9200/');
|
||||
|
||||
host = new Host({ host: 'john', port: 80 });
|
||||
@ -193,7 +193,7 @@ describe('Host class', function () {
|
||||
});
|
||||
|
||||
it('outputs valid relative urls when the host is empty', function () {
|
||||
var host = new Host({
|
||||
const host = new Host({
|
||||
host: false,
|
||||
path: '/path',
|
||||
query: { this: 'that' }
|
||||
@ -205,7 +205,7 @@ describe('Host class', function () {
|
||||
|
||||
describe('#toString', function () {
|
||||
it('produces the same output as makeUrl when it is called without params', function () {
|
||||
var host = new Host({
|
||||
const host = new Host({
|
||||
path: '/pasta',
|
||||
host: 'google.com'
|
||||
});
|
||||
@ -216,7 +216,7 @@ describe('Host class', function () {
|
||||
|
||||
describe('#getHeaders', function () {
|
||||
it('merges the passed in headers with the default headers', function () {
|
||||
var host = new Host({ headers: { 'Joe-Smith': 'present' } });
|
||||
const host = new Host({ headers: { 'Joe-Smith': 'present' } });
|
||||
|
||||
expect(host.getHeaders({
|
||||
'John-Smith': 'present'
|
||||
@ -227,7 +227,7 @@ describe('Host class', function () {
|
||||
});
|
||||
|
||||
it('overrides the default headers with the passed in headers', function () {
|
||||
var host = new Host({ headers: { 'Joe-Smith': 'present' } });
|
||||
const host = new Host({ headers: { 'Joe-Smith': 'present' } });
|
||||
|
||||
expect(host.getHeaders({
|
||||
'John-Smith': 'present',
|
||||
@ -239,7 +239,7 @@ describe('Host class', function () {
|
||||
});
|
||||
|
||||
it('adds Accept-Encoding header when the suggestCompression setting is true', function () {
|
||||
var host = new Host({ suggestCompression: true });
|
||||
const host = new Host({ suggestCompression: true });
|
||||
expect(host.getHeaders()).to.eql({
|
||||
'Accept-Encoding': 'gzip,deflate'
|
||||
});
|
||||
|
||||
@ -1,32 +1,32 @@
|
||||
describe('Http Connector', function () {
|
||||
|
||||
var _ = require('lodash');
|
||||
var expect = require('expect.js');
|
||||
var nock = require('nock');
|
||||
var sinon = require('sinon');
|
||||
var util = require('util');
|
||||
var parseUrl = require('url').parse;
|
||||
var http = require('http');
|
||||
var https = require('https');
|
||||
var AgentKeepAlive = require('agentkeepalive');
|
||||
const _ = require('lodash');
|
||||
const expect = require('expect.js');
|
||||
const nock = require('nock');
|
||||
const sinon = require('sinon');
|
||||
const util = require('util');
|
||||
const parseUrl = require('url').parse;
|
||||
const http = require('http');
|
||||
const https = require('https');
|
||||
const AgentKeepAlive = require('agentkeepalive');
|
||||
|
||||
var Host = require('../../../src/lib/host');
|
||||
var errors = require('../../../src/lib/errors');
|
||||
var HttpConnection = require('../../../src/lib/connectors/http');
|
||||
var ConnectionAbstract = require('../../../src/lib/connection');
|
||||
const Host = require('../../../src/lib/host');
|
||||
const errors = require('../../../src/lib/errors');
|
||||
const HttpConnection = require('../../../src/lib/connectors/http');
|
||||
const ConnectionAbstract = require('../../../src/lib/connection');
|
||||
|
||||
var expectSubObject = require('../../utils/expect_sub_object');
|
||||
var MockRequest = require('../../mocks/request');
|
||||
var MockIncommingMessage = require('../../mocks/incomming_message');
|
||||
var zlib = require('zlib');
|
||||
const expectSubObject = require('../../utils/expect_sub_object');
|
||||
const MockRequest = require('../../mocks/request');
|
||||
const MockIncommingMessage = require('../../mocks/incomming_message');
|
||||
const zlib = require('zlib');
|
||||
|
||||
nock.disableNetConnect();
|
||||
|
||||
var stub = require('../../utils/auto_release_stub').make();
|
||||
const stub = require('../../utils/auto_release_stub').make();
|
||||
|
||||
function makeStubReqMethod(prep) {
|
||||
return function (params, cb) {
|
||||
var req = new MockRequest();
|
||||
const req = new MockRequest();
|
||||
if (prep) {
|
||||
prep(req, params, cb);
|
||||
}
|
||||
@ -45,12 +45,12 @@ describe('Http Connector', function () {
|
||||
|
||||
describe('Constructor', function () {
|
||||
it('creates an object that extends ConnectionAbstract', function () {
|
||||
var con = new HttpConnection(new Host());
|
||||
const con = new HttpConnection(new Host());
|
||||
expect(con).to.be.a(ConnectionAbstract);
|
||||
});
|
||||
|
||||
it('sets certain defaults', function () {
|
||||
var con = new HttpConnection(new Host());
|
||||
const con = new HttpConnection(new Host());
|
||||
|
||||
expect(con.hand).to.be(require('http'));
|
||||
// con.requestTimeout
|
||||
@ -62,27 +62,27 @@ describe('Http Connector', function () {
|
||||
|
||||
it('expects the host to have a protocol of http or https', function () {
|
||||
expect(function () {
|
||||
var con = new HttpConnection(new Host('thrifty://es.com/stuff'));
|
||||
const con = new HttpConnection(new Host('thrifty://es.com/stuff'));
|
||||
}).to.throwError(/invalid protocol/i);
|
||||
});
|
||||
|
||||
it('allows defining a custom agent', function () {
|
||||
var football = {};
|
||||
var con = new HttpConnection(new Host(), { createNodeAgent: _.constant(football) });
|
||||
const football = {};
|
||||
const con = new HttpConnection(new Host(), { createNodeAgent: _.constant(football) });
|
||||
expect(con.agent).to.be(football);
|
||||
});
|
||||
|
||||
it('allows setting agent to false', function () {
|
||||
var con = new HttpConnection(new Host(), { createNodeAgent: _.constant(false) });
|
||||
const con = new HttpConnection(new Host(), { createNodeAgent: _.constant(false) });
|
||||
expect(con.agent).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#makeReqParams', function () {
|
||||
it('properly reads the host object', function () {
|
||||
var host = new Host('john:dude@pizza.com:9200/pizza/cheese?shrooms=true');
|
||||
var con = new HttpConnection(host, {});
|
||||
var reqParams = con.makeReqParams();
|
||||
const host = new Host('john:dude@pizza.com:9200/pizza/cheese?shrooms=true');
|
||||
const con = new HttpConnection(host, {});
|
||||
const reqParams = con.makeReqParams();
|
||||
|
||||
expect(reqParams).to.not.have.property('auth');
|
||||
expect(reqParams).to.eql({
|
||||
@ -97,13 +97,13 @@ describe('Http Connector', function () {
|
||||
});
|
||||
|
||||
it('merges a query object with the hosts\'', function () {
|
||||
var con = new HttpConnection(new Host({
|
||||
const con = new HttpConnection(new Host({
|
||||
query: {
|
||||
user_id: 123
|
||||
}
|
||||
}));
|
||||
|
||||
var reqParams = con.makeReqParams({
|
||||
const reqParams = con.makeReqParams({
|
||||
query: {
|
||||
jvm: 'yes'
|
||||
}
|
||||
@ -113,8 +113,8 @@ describe('Http Connector', function () {
|
||||
});
|
||||
|
||||
it('merges the path prefix', function () {
|
||||
var con = new HttpConnection(new Host('https://google.com/path/prefix/for/user/1'));
|
||||
var reqParams = con.makeReqParams({
|
||||
const con = new HttpConnection(new Host('https://google.com/path/prefix/for/user/1'));
|
||||
const reqParams = con.makeReqParams({
|
||||
method: 'GET',
|
||||
path: '/items',
|
||||
query: {
|
||||
@ -128,9 +128,9 @@ describe('Http Connector', function () {
|
||||
});
|
||||
|
||||
it('merges the query', function () {
|
||||
var con = new HttpConnection(new Host('http://google.com/pref-x?userId=12345&token=42069'));
|
||||
const con = new HttpConnection(new Host('http://google.com/pref-x?userId=12345&token=42069'));
|
||||
|
||||
var reqParams = con.makeReqParams({
|
||||
const reqParams = con.makeReqParams({
|
||||
method: 'PUT',
|
||||
path: '/stuff',
|
||||
query: {
|
||||
@ -144,9 +144,9 @@ describe('Http Connector', function () {
|
||||
});
|
||||
|
||||
it('Works well with minimum params', function () {
|
||||
var con = new HttpConnection(new Host('http://google.com'));
|
||||
const con = new HttpConnection(new Host('http://google.com'));
|
||||
|
||||
var reqParams = con.makeReqParams({
|
||||
const reqParams = con.makeReqParams({
|
||||
method: 'PUT',
|
||||
path: '/stuff'
|
||||
});
|
||||
@ -170,7 +170,7 @@ describe('Http Connector', function () {
|
||||
});
|
||||
|
||||
it('calls http based on the host', function (done) {
|
||||
var con = new HttpConnection(new Host('http://google.com'));
|
||||
const con = new HttpConnection(new Host('http://google.com'));
|
||||
con.request({}, function () {
|
||||
expect(http.request.callCount).to.be(1);
|
||||
expect(https.request.callCount).to.be(0);
|
||||
@ -180,7 +180,7 @@ describe('Http Connector', function () {
|
||||
});
|
||||
|
||||
it('calls https based on the host', function (done) {
|
||||
var con = new HttpConnection(new Host('https://google.com'));
|
||||
const con = new HttpConnection(new Host('https://google.com'));
|
||||
con.request({}, function () {
|
||||
expect(http.request.callCount).to.be(0);
|
||||
expect(https.request.callCount).to.be(1);
|
||||
@ -190,7 +190,7 @@ describe('Http Connector', function () {
|
||||
});
|
||||
|
||||
it('does not log error events', function (done) {
|
||||
var con = new HttpConnection(new Host('http://google.com'));
|
||||
const con = new HttpConnection(new Host('http://google.com'));
|
||||
|
||||
stub(con.log, 'error');
|
||||
stub(con.log, 'trace');
|
||||
@ -217,7 +217,7 @@ describe('Http Connector', function () {
|
||||
});
|
||||
|
||||
it('logs error events', function (done) {
|
||||
var con = new HttpConnection(new Host('http://google.com'));
|
||||
const con = new HttpConnection(new Host('http://google.com'));
|
||||
|
||||
stub(con.log, 'error');
|
||||
|
||||
@ -238,7 +238,7 @@ describe('Http Connector', function () {
|
||||
function makeStubReqWithMsgWhichErrorsMidBody(err) {
|
||||
return makeStubReqMethod(function (req, params, cb) {
|
||||
process.nextTick(function () {
|
||||
var incom = new MockIncommingMessage();
|
||||
const incom = new MockIncommingMessage();
|
||||
incom.statusCode = 200;
|
||||
setTimeout(function () {
|
||||
incom.emit('data', '{ "not json"');
|
||||
@ -250,7 +250,7 @@ describe('Http Connector', function () {
|
||||
}
|
||||
|
||||
it('does not log errors', function (done) {
|
||||
var con = new HttpConnection(new Host('https://google.com'));
|
||||
const con = new HttpConnection(new Host('https://google.com'));
|
||||
stub(con.log, 'error');
|
||||
stub(https, 'request', makeStubReqWithMsgWhichErrorsMidBody());
|
||||
|
||||
@ -261,7 +261,7 @@ describe('Http Connector', function () {
|
||||
});
|
||||
|
||||
it('passes the original error on', function (done) {
|
||||
var con = new HttpConnection(new Host('https://google.com'));
|
||||
const con = new HttpConnection(new Host('https://google.com'));
|
||||
stub(https, 'request', makeStubReqWithMsgWhichErrorsMidBody(new Error('no more message :(')));
|
||||
|
||||
con.request({}, function (err, resp, status) {
|
||||
@ -272,7 +272,7 @@ describe('Http Connector', function () {
|
||||
});
|
||||
|
||||
it('does not pass the partial body along', function (done) {
|
||||
var con = new HttpConnection(new Host('https://google.com'));
|
||||
const con = new HttpConnection(new Host('https://google.com'));
|
||||
stub(https, 'request', makeStubReqWithMsgWhichErrorsMidBody());
|
||||
|
||||
con.request({}, function (err, resp, status) {
|
||||
@ -282,7 +282,7 @@ describe('Http Connector', function () {
|
||||
});
|
||||
|
||||
it('does not pass the status code along', function (done) {
|
||||
var con = new HttpConnection(new Host('https://google.com'));
|
||||
const con = new HttpConnection(new Host('https://google.com'));
|
||||
stub(https, 'request', makeStubReqWithMsgWhichErrorsMidBody());
|
||||
|
||||
con.request({}, function (err, resp, status) {
|
||||
@ -294,9 +294,9 @@ describe('Http Connector', function () {
|
||||
|
||||
describe('#request\'s responder', function () {
|
||||
it('collects the whole request body', function (done) {
|
||||
var server = nock('http://esjs.com:9200');
|
||||
var con = new HttpConnection(new Host('http://esjs.com:9200'));
|
||||
var body = '{ "USER": "doc" }';
|
||||
const server = nock('http://esjs.com:9200');
|
||||
const con = new HttpConnection(new Host('http://esjs.com:9200'));
|
||||
const body = '{ "USER": "doc" }';
|
||||
|
||||
server
|
||||
.get('/users/1')
|
||||
@ -315,13 +315,13 @@ describe('Http Connector', function () {
|
||||
});
|
||||
|
||||
it('collects the whole request body (gzip compressed)', function (done) {
|
||||
var server = nock('http://esjs.com:9200');
|
||||
var con = new HttpConnection(new Host('http://esjs.com:9200'));
|
||||
var elements = [];
|
||||
for (var i = 0; i < 500; i++) {
|
||||
const server = nock('http://esjs.com:9200');
|
||||
const con = new HttpConnection(new Host('http://esjs.com:9200'));
|
||||
const elements = [];
|
||||
for (let i = 0; i < 500; i++) {
|
||||
elements.push({ USER: 'doc' });
|
||||
}
|
||||
var body = JSON.stringify(elements);
|
||||
const body = JSON.stringify(elements);
|
||||
zlib.gzip(body, function (err, compressedBody) {
|
||||
server
|
||||
.get('/users/1')
|
||||
@ -341,13 +341,13 @@ describe('Http Connector', function () {
|
||||
});
|
||||
|
||||
it('collects the whole request body (deflate compressed)', function (done) {
|
||||
var server = nock('http://esjs.com:9200');
|
||||
var con = new HttpConnection(new Host('http://esjs.com:9200'));
|
||||
var elements = [];
|
||||
for (var i = 0; i < 500; i++) {
|
||||
const server = nock('http://esjs.com:9200');
|
||||
const con = new HttpConnection(new Host('http://esjs.com:9200'));
|
||||
const elements = [];
|
||||
for (let i = 0; i < 500; i++) {
|
||||
elements.push({ USER: 'doc' });
|
||||
}
|
||||
var body = JSON.stringify(elements);
|
||||
const body = JSON.stringify(elements);
|
||||
zlib.deflate(body, function (err, compressedBody) {
|
||||
server
|
||||
.get('/users/1')
|
||||
@ -367,9 +367,9 @@ describe('Http Connector', function () {
|
||||
});
|
||||
|
||||
it('Can handle decompression errors', function (done) {
|
||||
var server = nock('http://esjs.com:9200');
|
||||
var con = new HttpConnection(new Host('http://esjs.com:9200'));
|
||||
var body = 'blah';
|
||||
const server = nock('http://esjs.com:9200');
|
||||
const con = new HttpConnection(new Host('http://esjs.com:9200'));
|
||||
const body = 'blah';
|
||||
server
|
||||
.get('/users/1')
|
||||
.reply(200, body, { 'Content-Encoding': 'gzip' });
|
||||
@ -387,9 +387,9 @@ describe('Http Connector', function () {
|
||||
});
|
||||
|
||||
it('Ignores serialization errors', function (done) {
|
||||
var server = nock('http://esjs.com:9200');
|
||||
var con = new HttpConnection(new Host('http://esjs.com:9200'));
|
||||
var body = '{ "USER":';
|
||||
const server = nock('http://esjs.com:9200');
|
||||
const con = new HttpConnection(new Host('http://esjs.com:9200'));
|
||||
const body = '{ "USER":';
|
||||
|
||||
// partial body
|
||||
server
|
||||
@ -410,9 +410,9 @@ describe('Http Connector', function () {
|
||||
|
||||
describe('HTTP specifics', function () {
|
||||
it('uses TCP no delay', function (done) {
|
||||
var con = new HttpConnection(new Host('localhost'));
|
||||
const con = new HttpConnection(new Host('localhost'));
|
||||
stub(http.ClientRequest.prototype, 'setNoDelay');
|
||||
var server = nock('http://localhost').get('/').reply(200);
|
||||
const server = nock('http://localhost').get('/').reply(200);
|
||||
|
||||
con.request({}, function (err, resp, status) {
|
||||
expect(http.ClientRequest.prototype.setNoDelay.callCount).to.eql(1);
|
||||
@ -423,11 +423,11 @@ describe('Http Connector', function () {
|
||||
});
|
||||
|
||||
it('sets the Content-Length header properly', function (done) {
|
||||
var con = new HttpConnection(new Host('localhost'));
|
||||
const con = new HttpConnection(new Host('localhost'));
|
||||
stub(http.ClientRequest.prototype, 'setHeader');
|
||||
var server = nock('http://localhost').get('/').reply(200);
|
||||
const server = nock('http://localhost').get('/').reply(200);
|
||||
|
||||
var body = 'pasta and 𝄞';
|
||||
const body = 'pasta and 𝄞';
|
||||
expect(body.length).to.eql(12); // nope
|
||||
expect(Buffer.byteLength(body, 'utf8')).to.eql(14); // yep
|
||||
|
||||
@ -441,9 +441,9 @@ describe('Http Connector', function () {
|
||||
});
|
||||
|
||||
it('does not set the Accept-Encoding header by default', function (done) {
|
||||
var con = new HttpConnection(new Host());
|
||||
var respBody = 'i should not be encoded';
|
||||
var server = nock('http://localhost:9200')
|
||||
const con = new HttpConnection(new Host());
|
||||
const respBody = 'i should not be encoded';
|
||||
const server = nock('http://localhost:9200')
|
||||
.matchHeader('accept-encoding', undefined)
|
||||
.get('/')
|
||||
.once()
|
||||
@ -457,9 +457,9 @@ describe('Http Connector', function () {
|
||||
});
|
||||
|
||||
it('sets the Accept-Encoding header when specified', function (done) {
|
||||
var con = new HttpConnection(new Host({ suggestCompression: true }));
|
||||
var respBody = 'i should be encoded';
|
||||
var server = nock('http://localhost:9200')
|
||||
const con = new HttpConnection(new Host({ suggestCompression: true }));
|
||||
const respBody = 'i should be encoded';
|
||||
const server = nock('http://localhost:9200')
|
||||
.matchHeader('accept-encoding', 'gzip,deflate')
|
||||
.get('/')
|
||||
.once()
|
||||
@ -476,12 +476,12 @@ describe('Http Connector', function () {
|
||||
describe('Connection cleanup', function () {
|
||||
it('destroys any connections created', function (done) {
|
||||
this.timeout(5 * 60 * 1000);
|
||||
var cp = require('child_process');
|
||||
var path = require('path');
|
||||
var fixture = _.partial(path.join, __dirname, '../../fixtures');
|
||||
var timeout; // start the timeout once we hear back from the client
|
||||
const cp = require('child_process');
|
||||
const path = require('path');
|
||||
const fixture = _.partial(path.join, __dirname, '../../fixtures');
|
||||
let timeout; // start the timeout once we hear back from the client
|
||||
|
||||
var server = cp.fork(fixture('keepalive_server.js'))
|
||||
const server = cp.fork(fixture('keepalive_server.js'))
|
||||
.on('message', function (port) {
|
||||
client.send(port);
|
||||
});
|
||||
@ -507,8 +507,8 @@ describe('Http Connector', function () {
|
||||
});
|
||||
|
||||
it('properly removes all elements from the socket', function () {
|
||||
var con = new HttpConnection(new Host('localhost'));
|
||||
var sockets = [
|
||||
const con = new HttpConnection(new Host('localhost'));
|
||||
const sockets = [
|
||||
{ destroy: function () {} },
|
||||
{ destroy: function () {} },
|
||||
{ destroy: function () {} },
|
||||
@ -520,7 +520,7 @@ describe('Http Connector', function () {
|
||||
{ destroy: function () {} },
|
||||
{ destroy: function () {} }
|
||||
];
|
||||
var name = con.agent.getName(parseUrl('http://localhost/'));
|
||||
const name = con.agent.getName(parseUrl('http://localhost/'));
|
||||
con.agent.sockets[name] = sockets;
|
||||
con.setStatus('closed');
|
||||
expect(sockets).to.eql([]);
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
describe('JSON serializer', function () {
|
||||
var JsonSerializer = require('../../../src/lib/serializers/json');
|
||||
var expect = require('expect.js');
|
||||
var sinon = require('sinon');
|
||||
var stub = require('../../utils/auto_release_stub').make();
|
||||
const JsonSerializer = require('../../../src/lib/serializers/json');
|
||||
const expect = require('expect.js');
|
||||
const sinon = require('sinon');
|
||||
const stub = require('../../utils/auto_release_stub').make();
|
||||
|
||||
function makeSerializer() {
|
||||
return new JsonSerializer();
|
||||
@ -10,29 +10,29 @@ describe('JSON serializer', function () {
|
||||
|
||||
describe('#serialize', function () {
|
||||
it('defers to JSON.stringify', function () {
|
||||
var stub = sinon.stub(JSON, 'stringify');
|
||||
var ser = makeSerializer();
|
||||
const stub = sinon.stub(JSON, 'stringify');
|
||||
const ser = makeSerializer();
|
||||
ser.serialize({ some: 'object' });
|
||||
expect(stub.callCount).to.eql(1);
|
||||
stub.restore();
|
||||
});
|
||||
|
||||
it('does not modify strings', function () {
|
||||
var ser = makeSerializer();
|
||||
var thing = 'pretend that I am serialized';
|
||||
const ser = makeSerializer();
|
||||
const thing = 'pretend that I am serialized';
|
||||
expect(ser.serialize(thing)).to.be(thing);
|
||||
});
|
||||
|
||||
it('returns nothing for invalid values', function () {
|
||||
var ser = makeSerializer();
|
||||
const ser = makeSerializer();
|
||||
|
||||
expect(ser.serialize(null)).to.be(undefined);
|
||||
expect(ser.serialize(false)).to.be(undefined);
|
||||
});
|
||||
|
||||
it('throws serialization errors', function () {
|
||||
var ser = makeSerializer();
|
||||
var thing = { name: 'thing' };
|
||||
const ser = makeSerializer();
|
||||
const thing = { name: 'thing' };
|
||||
thing.self = thing;
|
||||
|
||||
expect(function () {
|
||||
@ -44,46 +44,46 @@ describe('JSON serializer', function () {
|
||||
describe('#deserialize', function () {
|
||||
it('defers to JSON.parse', function () {
|
||||
stub(JSON, 'parse');
|
||||
var ser = makeSerializer();
|
||||
const ser = makeSerializer();
|
||||
ser.deserialize('{ "some": "JSON" }');
|
||||
expect(JSON.parse.callCount).to.eql(1);
|
||||
});
|
||||
|
||||
it('ignores non string values', function () {
|
||||
var ser = makeSerializer();
|
||||
var thing = ['pretend that I am not here'];
|
||||
const ser = makeSerializer();
|
||||
const thing = ['pretend that I am not here'];
|
||||
expect(ser.deserialize(thing)).to.be(undefined);
|
||||
expect(ser.deserialize(null)).to.be(undefined);
|
||||
expect(ser.deserialize(false)).to.be(undefined);
|
||||
});
|
||||
|
||||
it('catches serialization errors, returns nothing', function () {
|
||||
var ser = makeSerializer();
|
||||
var thing = '{ name: \'thing\' }';
|
||||
const ser = makeSerializer();
|
||||
const thing = '{ name: \'thing\' }';
|
||||
|
||||
expect(ser.deserialize(thing)).to.be(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#bulkBody', function () {
|
||||
var body = [
|
||||
const body = [
|
||||
{ index: 'thing' },
|
||||
{ document: 'hi' }
|
||||
];
|
||||
var bulk = '{"index":"thing"}\n{"document":"hi"}\n';
|
||||
const bulk = '{"index":"thing"}\n{"document":"hi"}\n';
|
||||
|
||||
it('creates a string out of an array of obejcts', function () {
|
||||
var ser = makeSerializer();
|
||||
const ser = makeSerializer();
|
||||
expect(ser.bulkBody(body)).to.eql(bulk);
|
||||
});
|
||||
|
||||
it('adds a newline to the end of strings', function () {
|
||||
var ser = makeSerializer();
|
||||
const ser = makeSerializer();
|
||||
expect(ser.bulkBody(bulk.substr(0, bulk.length - 1))).to.eql(bulk);
|
||||
});
|
||||
|
||||
it('throws an error for anything else', function () {
|
||||
var ser = makeSerializer();
|
||||
const ser = makeSerializer();
|
||||
expect(function () {
|
||||
ser.bulkBody({});
|
||||
}).to.throwError();
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
var Log = require('../../../src/lib/log');
|
||||
var _ = require('lodash');
|
||||
var expect = require('expect.js');
|
||||
const Log = require('../../../src/lib/log');
|
||||
const _ = require('lodash');
|
||||
const expect = require('expect.js');
|
||||
|
||||
describe('Log class', function () {
|
||||
describe('::parseLevels', function () {
|
||||
@ -32,7 +32,7 @@ describe('Log class', function () {
|
||||
});
|
||||
|
||||
describe('#addOutput', function () {
|
||||
var log;
|
||||
let log;
|
||||
|
||||
Log.loggers.stub = function (log, config) {
|
||||
this.config = config;
|
||||
@ -47,7 +47,7 @@ describe('Log class', function () {
|
||||
});
|
||||
|
||||
it('Accepts a config object with `level: "{{level}}"`', function () {
|
||||
var logger = log.addOutput({
|
||||
const logger = log.addOutput({
|
||||
type: 'stub',
|
||||
level: 'warning'
|
||||
});
|
||||
@ -58,7 +58,7 @@ describe('Log class', function () {
|
||||
});
|
||||
|
||||
it('Accepts a config object with `level: ["{{level}}"]`', function () {
|
||||
var logger = log.addOutput({
|
||||
const logger = log.addOutput({
|
||||
type: 'stub',
|
||||
level: ['warning']
|
||||
});
|
||||
@ -70,7 +70,7 @@ describe('Log class', function () {
|
||||
|
||||
|
||||
it('Accepts a config object with `levels: "{{level}}"`', function () {
|
||||
var logger = log.addOutput({
|
||||
const logger = log.addOutput({
|
||||
type: 'stub',
|
||||
levels: 'warning'
|
||||
});
|
||||
@ -81,7 +81,7 @@ describe('Log class', function () {
|
||||
});
|
||||
|
||||
it('Accepts a config object with `levels: ["{{level}}"]`', function () {
|
||||
var logger = log.addOutput({
|
||||
const logger = log.addOutput({
|
||||
type: 'stub',
|
||||
level: ['warning']
|
||||
});
|
||||
@ -100,15 +100,15 @@ describe('Log class', function () {
|
||||
expect(Log.join([{ foo: 'bar' }])).to.eql('{\n "foo": "bar"\n}\n');
|
||||
});
|
||||
|
||||
it('fully stringifies deeply nested objects', function() {
|
||||
var object = { foo: { bar: { baz: 'value' } } };
|
||||
var expected = '{\n "bar": {\n "baz": "value"\n }\n}\n';
|
||||
it('fully stringifies deeply nested objects', function () {
|
||||
const object = { foo: { bar: { baz: 'value' } } };
|
||||
const expected = '{\n "bar": {\n "baz": "value"\n }\n}\n';
|
||||
expect(Log.join(object)).to.eql(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('instance without any outputs', function () {
|
||||
var log;
|
||||
let log;
|
||||
beforeEach(function () {
|
||||
log = new Log();
|
||||
});
|
||||
@ -128,7 +128,7 @@ describe('Log class', function () {
|
||||
});
|
||||
|
||||
describe('instance without one output listening to all events', function () {
|
||||
var log, call;
|
||||
let log, call;
|
||||
beforeEach(function () {
|
||||
call = void 0;
|
||||
log = new Log({
|
||||
@ -154,7 +154,7 @@ describe('Log class', function () {
|
||||
});
|
||||
|
||||
it('should emit an "error" event with an Error object arg', function () {
|
||||
var err = new Error('error');
|
||||
const err = new Error('error');
|
||||
log.error(err);
|
||||
expect(call.event).to.eql('error');
|
||||
expect(call.args[0]).to.be(err);
|
||||
@ -200,7 +200,7 @@ describe('Log class', function () {
|
||||
|
||||
describe('constructor', function () {
|
||||
it('looks for output config options at config.log', function () {
|
||||
var log = new Log({ log: { type: process.browser ? 'console' : 'stdio', level: 'error' } });
|
||||
const log = new Log({ log: { type: process.browser ? 'console' : 'stdio', level: 'error' } });
|
||||
expect(log.listenerCount('error')).to.eql(1);
|
||||
expect(log.listenerCount('warning')).to.eql(0);
|
||||
expect(log.listenerCount('info')).to.eql(0);
|
||||
@ -209,7 +209,7 @@ describe('Log class', function () {
|
||||
});
|
||||
|
||||
it('accepts a string and treat it as a log level', function () {
|
||||
var log = new Log({ log: 'error' });
|
||||
const log = new Log({ log: 'error' });
|
||||
expect(log.listenerCount('error')).to.eql(1);
|
||||
expect(log.listenerCount('warning')).to.eql(0);
|
||||
expect(log.listenerCount('info')).to.eql(0);
|
||||
@ -218,7 +218,7 @@ describe('Log class', function () {
|
||||
});
|
||||
|
||||
it('accepts an array of strings and treat it as a log level config', function () {
|
||||
var log = new Log({ log: ['error', 'trace'] });
|
||||
const log = new Log({ log: ['error', 'trace'] });
|
||||
expect(log.listenerCount('error')).to.eql(1);
|
||||
expect(log.listenerCount('warning')).to.eql(0);
|
||||
expect(log.listenerCount('info')).to.eql(0);
|
||||
@ -227,7 +227,7 @@ describe('Log class', function () {
|
||||
});
|
||||
|
||||
it('accepts an array of output config objects', function () {
|
||||
var log = new Log({ log: [{ level: 'error' }, { level: 'trace' }] });
|
||||
const log = new Log({ log: [{ level: 'error' }, { level: 'trace' }] });
|
||||
expect(log.listenerCount('error')).to.eql(2);
|
||||
expect(log.listenerCount('warning')).to.eql(1);
|
||||
expect(log.listenerCount('info')).to.eql(1);
|
||||
@ -237,22 +237,22 @@ describe('Log class', function () {
|
||||
|
||||
it('rejects numbers and other truthy data-types', function () {
|
||||
expect(function () {
|
||||
var log = new Log({ log: 1515 });
|
||||
const log = new Log({ log: 1515 });
|
||||
}).to.throwError(/invalid logging output config/i);
|
||||
expect(function () {
|
||||
var log = new Log({ log: /regexp/ });
|
||||
const log = new Log({ log: /regexp/ });
|
||||
}).to.throwError(/invalid logging output config/i);
|
||||
expect(function () {
|
||||
var log = new Log({ log: new Date() });
|
||||
const log = new Log({ log: new Date() });
|
||||
}).to.throwError(/invalid logging output config/i);
|
||||
expect(function () {
|
||||
var log = new Log({ log: [1515] });
|
||||
const log = new Log({ log: [1515] });
|
||||
}).to.throwError(/invalid logging output config/i);
|
||||
expect(function () {
|
||||
var log = new Log({ log: [/regexp/] });
|
||||
const log = new Log({ log: [/regexp/] });
|
||||
}).to.throwError(/invalid logging output config/i);
|
||||
expect(function () {
|
||||
var log = new Log({ log: [new Date()] });
|
||||
const log = new Log({ log: [new Date()] });
|
||||
}).to.throwError(/invalid logging output config/i);
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
describe('Nodes to host callback', function () {
|
||||
var callback = require('../../../src/lib/nodes_to_host');
|
||||
var expect = require('expect.js');
|
||||
const callback = require('../../../src/lib/nodes_to_host');
|
||||
const expect = require('expect.js');
|
||||
|
||||
var nodes90 = require('../../fixtures/short_node_list.0.90.json');
|
||||
var nodes10 = require('../../fixtures/short_node_list.1.0.json');
|
||||
var nodes20 = require('../../fixtures/short_node_list.2.0.json');
|
||||
var nodes50 = require('../../fixtures/short_node_list.5.0.json');
|
||||
const nodes90 = require('../../fixtures/short_node_list.0.90.json');
|
||||
const nodes10 = require('../../fixtures/short_node_list.1.0.json');
|
||||
const nodes20 = require('../../fixtures/short_node_list.2.0.json');
|
||||
const nodes50 = require('../../fixtures/short_node_list.5.0.json');
|
||||
|
||||
context('0.x style', function () {
|
||||
it('properly creates host objects', function () {
|
||||
@ -109,7 +109,7 @@ describe('Nodes to host callback', function () {
|
||||
|
||||
|
||||
it('ignores hosts that don\'t have an http_host property', function () {
|
||||
var hosts = callback({
|
||||
const hosts = callback({
|
||||
node_id: {
|
||||
not: 'much of a node'
|
||||
}
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
describe('Random Selector', function () {
|
||||
var randomSelector = require('../../../src/lib/selectors/random');
|
||||
var _ = require('lodash');
|
||||
var expect = require('expect.js');
|
||||
const randomSelector = require('../../../src/lib/selectors/random');
|
||||
const _ = require('lodash');
|
||||
const expect = require('expect.js');
|
||||
|
||||
it('chooses a selection by random', function () {
|
||||
var log = { a: 0, b: 0, c: 0 };
|
||||
var choices = _.keys(log);
|
||||
const log = { a: 0, b: 0, c: 0 };
|
||||
const choices = _.keys(log);
|
||||
|
||||
_.times(1000, function () {
|
||||
var choice = randomSelector(choices);
|
||||
const choice = randomSelector(choices);
|
||||
log[choice]++;
|
||||
});
|
||||
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
describe('Round Robin Selector', function () {
|
||||
var selector = require('../../../src/lib/selectors/round_robin');
|
||||
var _ = require('lodash');
|
||||
var expect = require('expect.js');
|
||||
const selector = require('../../../src/lib/selectors/round_robin');
|
||||
const _ = require('lodash');
|
||||
const expect = require('expect.js');
|
||||
|
||||
it('chooses options in order', function () {
|
||||
var options = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
|
||||
var expected = _.clone(options);
|
||||
var selections = [];
|
||||
const options = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
|
||||
const expected = _.clone(options);
|
||||
const selections = [];
|
||||
|
||||
_.times(options.length, function () {
|
||||
selections.push(selector(options));
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
describe('Stdio Logger', function () {
|
||||
|
||||
var Log = require('../../../src/lib/log');
|
||||
var StdioLogger = require('../../../src/lib/loggers/stdio');
|
||||
var expect = require('expect.js');
|
||||
var sinon = require('sinon');
|
||||
var parentLog;
|
||||
const Log = require('../../../src/lib/log');
|
||||
const StdioLogger = require('../../../src/lib/loggers/stdio');
|
||||
const expect = require('expect.js');
|
||||
const sinon = require('sinon');
|
||||
let parentLog;
|
||||
|
||||
beforeEach(function () {
|
||||
parentLog = new Log();
|
||||
@ -16,37 +16,37 @@ describe('Stdio Logger', function () {
|
||||
|
||||
function makeLogger(parent, levels) {
|
||||
parent = parent || parentLog;
|
||||
var config = {
|
||||
const config = {
|
||||
levels: Log.parseLevels(levels || 'trace')
|
||||
};
|
||||
return new StdioLogger(parent, config);
|
||||
}
|
||||
|
||||
var stub = require('../../utils/auto_release_stub').make();
|
||||
const stub = require('../../utils/auto_release_stub').make();
|
||||
|
||||
require('../generic_logger_tests')(makeLogger);
|
||||
|
||||
describe('colorizing', function () {
|
||||
var chalk = require('chalk');
|
||||
var now = '2013-01-01T00:00:00Z';
|
||||
var nowDate = new Date(now);
|
||||
var nowTime = nowDate.getTime();
|
||||
var clock;
|
||||
const chalk = require('chalk');
|
||||
const now = '2013-01-01T00:00:00Z';
|
||||
const nowDate = new Date(now);
|
||||
const nowTime = nowDate.getTime();
|
||||
let clock;
|
||||
|
||||
beforeEach(function () {
|
||||
stub.autoRelease(sinon.useFakeTimers(nowTime));
|
||||
});
|
||||
|
||||
it('uses colors when it\'s supported', function () {
|
||||
var logger = makeLogger();
|
||||
var hasColor = require('chalk').supportsColor;
|
||||
const logger = makeLogger();
|
||||
const hasColor = require('chalk').supportsColor;
|
||||
expect(logger.color).to.be(hasColor);
|
||||
});
|
||||
|
||||
it('obeys the logger.color === false', function () {
|
||||
var logger = makeLogger();
|
||||
const logger = makeLogger();
|
||||
stub(process.stdout, 'write');
|
||||
var withoutColor = 'Elasticsearch INFO: ' + now + '\n something\n\n';
|
||||
const withoutColor = 'Elasticsearch INFO: ' + now + '\n something\n\n';
|
||||
|
||||
logger.color = false;
|
||||
logger.onInfo('something');
|
||||
@ -54,10 +54,10 @@ describe('Stdio Logger', function () {
|
||||
});
|
||||
|
||||
it('obeys the logger.color === true', function () {
|
||||
var logger = makeLogger();
|
||||
const logger = makeLogger();
|
||||
|
||||
stub(process.stdout, 'write');
|
||||
var withoutColor = 'Elasticsearch DEBUG: ' + now + '\n be weary\n\n';
|
||||
const withoutColor = 'Elasticsearch DEBUG: ' + now + '\n be weary\n\n';
|
||||
|
||||
logger.color = true;
|
||||
logger.onDebug('be weary');
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
describe('Stream Logger', function () {
|
||||
var Log = require('../../../src/lib/log');
|
||||
var StreamLogger = require('../../../src/lib/loggers/stream');
|
||||
var MockWritableStream = require('../../mocks/writable_stream');
|
||||
var once = require('events').EventEmitter.prototype.once;
|
||||
var stream = new MockWritableStream();
|
||||
var _ = require('../../../src/lib/utils');
|
||||
var expect = require('expect.js');
|
||||
var parentLog;
|
||||
const Log = require('../../../src/lib/log');
|
||||
const StreamLogger = require('../../../src/lib/loggers/stream');
|
||||
const MockWritableStream = require('../../mocks/writable_stream');
|
||||
const once = require('events').EventEmitter.prototype.once;
|
||||
const stream = new MockWritableStream();
|
||||
const _ = require('../../../src/lib/utils');
|
||||
const expect = require('expect.js');
|
||||
let parentLog;
|
||||
|
||||
var stub = require('../../utils/auto_release_stub').make();
|
||||
const stub = require('../../utils/auto_release_stub').make();
|
||||
|
||||
beforeEach(function () {
|
||||
stub(stream, 'write');
|
||||
@ -24,7 +24,7 @@ describe('Stream Logger', function () {
|
||||
|
||||
function makeLogger(parent, levels) {
|
||||
parent = parent || parentLog;
|
||||
var config = {
|
||||
const config = {
|
||||
levels: Log.parseLevels(levels || 'trace'),
|
||||
stream: stream
|
||||
};
|
||||
@ -36,12 +36,12 @@ describe('Stream Logger', function () {
|
||||
describe('buffer flush', function () {
|
||||
if (require('stream').Writable) {
|
||||
it('writes everything in the buffer to console.error', function () {
|
||||
var logger = makeLogger();
|
||||
var line = 'This string is written 10 times to create buffered output\n';
|
||||
const logger = makeLogger();
|
||||
const line = 'This string is written 10 times to create buffered output\n';
|
||||
|
||||
// get the last handler for process's "exit" event
|
||||
var exitHandlers = process._events.exit;
|
||||
var exitHandler = _.isArray(exitHandlers) ? _.last(exitHandlers) : exitHandlers;
|
||||
const exitHandlers = process._events.exit;
|
||||
const exitHandler = _.isArray(exitHandlers) ? _.last(exitHandlers) : exitHandlers;
|
||||
|
||||
// allow the logger to acctually write to the stream
|
||||
stream.write.restore();
|
||||
@ -52,7 +52,7 @@ describe('Stream Logger', function () {
|
||||
});
|
||||
|
||||
// collect everything that is written to console.error
|
||||
var flushedOutput = '';
|
||||
let flushedOutput = '';
|
||||
stub(console, 'error', function (str) {
|
||||
flushedOutput += str;
|
||||
});
|
||||
@ -69,7 +69,7 @@ describe('Stream Logger', function () {
|
||||
});
|
||||
} else {
|
||||
it('does not fall apart with non streams2 streams', function () {
|
||||
var exitHandler;
|
||||
let exitHandler;
|
||||
stub(process, 'once', function (event, handler) {
|
||||
if (event === 'exit') {
|
||||
exitHandler = handler;
|
||||
@ -77,7 +77,7 @@ describe('Stream Logger', function () {
|
||||
once.call(process, event, handler);
|
||||
});
|
||||
|
||||
var logger = makeLogger();
|
||||
const logger = makeLogger();
|
||||
|
||||
expect(function () {
|
||||
// call the event handler
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
describe('Tracer Logger', function () {
|
||||
|
||||
var Log = require('../../../src/lib/log');
|
||||
var TracerLogger = require('../../../src/lib/loggers/tracer');
|
||||
var sinon = require('sinon');
|
||||
var expect = require('expect.js');
|
||||
var parentLog;
|
||||
const Log = require('../../../src/lib/log');
|
||||
const TracerLogger = require('../../../src/lib/loggers/tracer');
|
||||
const sinon = require('sinon');
|
||||
const expect = require('expect.js');
|
||||
let parentLog;
|
||||
|
||||
beforeEach(function () {
|
||||
parentLog = new Log();
|
||||
@ -16,21 +16,21 @@ describe('Tracer Logger', function () {
|
||||
|
||||
function makeLogger(parent, levels) {
|
||||
parent = parent || parentLog;
|
||||
var config = {
|
||||
const config = {
|
||||
levels: Log.parseLevels(levels || 'trace')
|
||||
};
|
||||
return new TracerLogger(parent, config);
|
||||
}
|
||||
|
||||
var stub = require('../../utils/auto_release_stub').make();
|
||||
const stub = require('../../utils/auto_release_stub').make();
|
||||
|
||||
// require('../generic_logger_tests')(makeLogger);
|
||||
|
||||
describe('#formatTraceMessage', function () {
|
||||
it('includes the original host', function () {
|
||||
var logger = makeLogger();
|
||||
const logger = makeLogger();
|
||||
|
||||
var formatted = logger._formatTraceMessage({
|
||||
const formatted = logger._formatTraceMessage({
|
||||
method: 'DELETE',
|
||||
url: 'https://originalHost.com:9522/path/to/thing?qs=100',
|
||||
body: '{ "yes": true }',
|
||||
@ -45,7 +45,7 @@ describe('Tracer Logger', function () {
|
||||
});
|
||||
|
||||
describe('#write', function () {
|
||||
var logger;
|
||||
let logger;
|
||||
beforeEach(function () {
|
||||
logger = makeLogger();
|
||||
stub(logger.stream, 'write');
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
var Transport = require('../../../src/lib/transport');
|
||||
var Host = require('../../../src/lib/host');
|
||||
var errors = require('../../../src/lib/errors');
|
||||
const Transport = require('../../../src/lib/transport');
|
||||
const Host = require('../../../src/lib/host');
|
||||
const errors = require('../../../src/lib/errors');
|
||||
|
||||
var sinon = require('sinon');
|
||||
var expect = require('expect.js');
|
||||
var _ = require('lodash');
|
||||
var nodeList = require('../../fixtures/short_node_list.5.0.json');
|
||||
var stub = require('../../utils/auto_release_stub').make();
|
||||
const sinon = require('sinon');
|
||||
const expect = require('expect.js');
|
||||
const _ = require('lodash');
|
||||
const nodeList = require('../../fixtures/short_node_list.5.0.json');
|
||||
const stub = require('../../utils/auto_release_stub').make();
|
||||
|
||||
/**
|
||||
* Allows the tests call #request() without it doing anything past trying to select
|
||||
@ -31,7 +31,7 @@ describe('Transport Class', function () {
|
||||
describe('Constructor', function () {
|
||||
it('Accepts a log class and intanciates it at this.log', function () {
|
||||
function CustomLogClass() {}
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
log: CustomLogClass
|
||||
});
|
||||
|
||||
@ -39,7 +39,7 @@ describe('Transport Class', function () {
|
||||
});
|
||||
|
||||
it('Accepts a connection pool class and intanciates it at this.connectionPool', function () {
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
connectionPool: CustomConnectionPool
|
||||
});
|
||||
|
||||
@ -49,7 +49,7 @@ describe('Transport Class', function () {
|
||||
it('Accepts the name of a connectionPool class that is defined on Transport.connectionPools', function () {
|
||||
Transport.connectionPools.custom = CustomConnectionPool;
|
||||
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
connectionPool: 'custom'
|
||||
});
|
||||
|
||||
@ -59,7 +59,7 @@ describe('Transport Class', function () {
|
||||
|
||||
it('Throws an error when connectionPool config is set wrong', function () {
|
||||
expect(function () {
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
connectionPool: 'pasta'
|
||||
});
|
||||
}).to.throwError(/invalid connectionpool/i);
|
||||
@ -67,7 +67,7 @@ describe('Transport Class', function () {
|
||||
|
||||
it('calls sniff immediately if sniffOnStart is true', function () {
|
||||
stub(Transport.prototype, 'sniff');
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
sniffOnStart: true
|
||||
});
|
||||
|
||||
@ -75,16 +75,16 @@ describe('Transport Class', function () {
|
||||
});
|
||||
|
||||
it('schedules a sniff when sniffInterval is set', function () {
|
||||
var clock = sinon.useFakeTimers('setTimeout');
|
||||
const clock = sinon.useFakeTimers('setTimeout');
|
||||
stub.autoRelease(clock);
|
||||
stub(Transport.prototype, 'sniff');
|
||||
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
sniffInterval: 25000
|
||||
});
|
||||
|
||||
expect(_.size(clock.timers)).to.eql(1);
|
||||
var id = _.keys(clock.timers).pop();
|
||||
const id = _.keys(clock.timers).pop();
|
||||
clock.tick(25000);
|
||||
expect(trans.sniff.callCount).to.eql(1);
|
||||
expect(_.size(clock.timers)).to.eql(1);
|
||||
@ -94,15 +94,15 @@ describe('Transport Class', function () {
|
||||
|
||||
describe('config.sniffedNodesProtocol', function () {
|
||||
it('Assigns to itself', function () {
|
||||
var football = {};
|
||||
var trans = new Transport({
|
||||
const football = {};
|
||||
const trans = new Transport({
|
||||
sniffedNodesProtocol: football
|
||||
});
|
||||
expect(trans).to.have.property('sniffedNodesProtocol', football);
|
||||
});
|
||||
|
||||
it('Defaults to null when no hosts given', function () {
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
hosts: []
|
||||
});
|
||||
|
||||
@ -110,7 +110,7 @@ describe('Transport Class', function () {
|
||||
});
|
||||
|
||||
it('Defaults to "http" when a single http host given', function () {
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
hosts: [
|
||||
new Host({
|
||||
protocol: 'http'
|
||||
@ -122,7 +122,7 @@ describe('Transport Class', function () {
|
||||
});
|
||||
|
||||
it('Defaults to "http" when multiple http host given', function () {
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
hosts: [
|
||||
new Host(),
|
||||
'http://google.com',
|
||||
@ -137,7 +137,7 @@ describe('Transport Class', function () {
|
||||
});
|
||||
|
||||
it('Defaults to "https" when a single https host given', function () {
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
host: {
|
||||
protocol: 'https'
|
||||
}
|
||||
@ -147,7 +147,7 @@ describe('Transport Class', function () {
|
||||
});
|
||||
|
||||
it('Defaults to "https" when every seed host uses https', function () {
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
hosts: [
|
||||
'https://localhost:9200',
|
||||
new Host({
|
||||
@ -166,7 +166,7 @@ describe('Transport Class', function () {
|
||||
describe('host config', function () {
|
||||
it('rejects non-strings/objects', function () {
|
||||
expect(function () {
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
host: [
|
||||
'localhost',
|
||||
9393
|
||||
@ -175,7 +175,7 @@ describe('Transport Class', function () {
|
||||
}).to.throwError(TypeError);
|
||||
|
||||
expect(function () {
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
host: [
|
||||
[9292]
|
||||
]
|
||||
@ -185,7 +185,7 @@ describe('Transport Class', function () {
|
||||
|
||||
it('accepts the config value on the host: key', function () {
|
||||
stub(Transport.connectionPools.main.prototype, 'setHosts');
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
host: 'localhost'
|
||||
});
|
||||
|
||||
@ -197,7 +197,7 @@ describe('Transport Class', function () {
|
||||
|
||||
it('accepts the config value on the hosts: key', function () {
|
||||
stub(Transport.connectionPools.main.prototype, 'setHosts');
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
hosts: 'localhost'
|
||||
});
|
||||
|
||||
@ -209,8 +209,8 @@ describe('Transport Class', function () {
|
||||
|
||||
it('accepts A host object as the config', function () {
|
||||
stub(Transport.connectionPools.main.prototype, 'setHosts');
|
||||
var h = new Host('localhost');
|
||||
var trans = new Transport({
|
||||
const h = new Host('localhost');
|
||||
const trans = new Transport({
|
||||
host: h
|
||||
});
|
||||
|
||||
@ -220,7 +220,7 @@ describe('Transport Class', function () {
|
||||
|
||||
it('accepts strings as the config', function () {
|
||||
stub(Transport.connectionPools.main.prototype, 'setHosts');
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
hosts: [
|
||||
'localhost:8888',
|
||||
]
|
||||
@ -237,7 +237,7 @@ describe('Transport Class', function () {
|
||||
|
||||
it('accepts objects as the config', function () {
|
||||
stub(Transport.connectionPools.main.prototype, 'setHosts');
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
hosts: [
|
||||
{
|
||||
protocol: 'https',
|
||||
@ -262,13 +262,13 @@ describe('Transport Class', function () {
|
||||
// check that it's getting the suggestCompression setting
|
||||
stub(Transport.connectionPools.main.prototype, 'setHosts');
|
||||
|
||||
var trans = new Transport({
|
||||
let trans = new Transport({
|
||||
suggestCompression: true,
|
||||
hosts: ['localhost:9200']
|
||||
});
|
||||
|
||||
expect(trans.connectionPool.setHosts).to.have.property('callCount', 1);
|
||||
var hosts = trans.connectionPool.setHosts.firstCall.args[0];
|
||||
let hosts = trans.connectionPool.setHosts.firstCall.args[0];
|
||||
expect(hosts).to.have.length(1);
|
||||
expect(hosts[0]).to.have.property('suggestCompression', true);
|
||||
|
||||
@ -285,20 +285,20 @@ describe('Transport Class', function () {
|
||||
|
||||
describe('randomizeHosts options', function () {
|
||||
it('calls _.shuffle be default', function () {
|
||||
var _ = require('../../../src/lib/utils');
|
||||
const _ = require('../../../src/lib/utils');
|
||||
stub(Transport.connectionPools.main.prototype, 'setHosts');
|
||||
stub(_, 'shuffle');
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
hosts: 'localhost'
|
||||
});
|
||||
|
||||
expect(_.shuffle.callCount).to.eql(1);
|
||||
});
|
||||
it('skips the call to _.shuffle when false', function () {
|
||||
var _ = require('../../../src/lib/utils');
|
||||
const _ = require('../../../src/lib/utils');
|
||||
stub(Transport.connectionPools.main.prototype, 'setHosts');
|
||||
stub(_, 'shuffle');
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
hosts: 'localhost',
|
||||
randomizeHosts: false
|
||||
});
|
||||
@ -310,7 +310,7 @@ describe('Transport Class', function () {
|
||||
|
||||
describe('#defer', function () {
|
||||
it('returns a custom defer object', function () {
|
||||
var defer = Transport.prototype.defer();
|
||||
const defer = Transport.prototype.defer();
|
||||
expect(defer).to.have.property('promise');
|
||||
expect(defer).to.have.property('resolve');
|
||||
expect(defer).to.have.property('reject');
|
||||
@ -319,7 +319,7 @@ describe('Transport Class', function () {
|
||||
|
||||
|
||||
describe('#sniff', function () {
|
||||
var trans;
|
||||
let trans;
|
||||
|
||||
beforeEach(function () {
|
||||
trans = new Transport({ suggestCompression: true });
|
||||
@ -366,7 +366,7 @@ describe('Transport Class', function () {
|
||||
function (done) {
|
||||
trans.sniff(function () {
|
||||
expect(trans.connectionPool.setHosts.callCount).to.eql(1);
|
||||
var hosts = trans.connectionPool.setHosts.lastCall.args[0];
|
||||
const hosts = trans.connectionPool.setHosts.lastCall.args[0];
|
||||
|
||||
expect(hosts).to.have.length(2);
|
||||
|
||||
@ -386,7 +386,7 @@ describe('Transport Class', function () {
|
||||
// check that it's getting the suggestCompression setting
|
||||
trans.sniff(function () {
|
||||
expect(trans.connectionPool.setHosts).to.have.property('callCount', 1);
|
||||
var hosts = trans.connectionPool.setHosts.lastCall.args[0];
|
||||
const hosts = trans.connectionPool.setHosts.lastCall.args[0];
|
||||
expect(hosts).to.have.length(2);
|
||||
expect(hosts[0]).to.have.property('suggestCompression', true);
|
||||
expect(hosts[1]).to.have.property('suggestCompression', true);
|
||||
@ -423,7 +423,7 @@ describe('Transport Class', function () {
|
||||
|
||||
describe('#request', function () {
|
||||
it('logs when it begins', function (done) {
|
||||
var trans = new Transport();
|
||||
const trans = new Transport();
|
||||
stub(trans.log, 'debug');
|
||||
stub(trans.connectionPool, 'select', function (cb) {
|
||||
// simulate "no connections"
|
||||
@ -437,7 +437,7 @@ describe('Transport Class', function () {
|
||||
});
|
||||
|
||||
it('rejects GET requests with a body (callback)', function (done) {
|
||||
var trans = new Transport();
|
||||
const trans = new Transport();
|
||||
stub(trans.log, 'debug');
|
||||
stub(trans.connectionPool, 'select', function (cb) {
|
||||
// simulate "no connections"
|
||||
@ -454,7 +454,7 @@ describe('Transport Class', function () {
|
||||
});
|
||||
|
||||
it('rejects GET requests with a body (promise)', function (done) {
|
||||
var trans = new Transport();
|
||||
const trans = new Transport();
|
||||
stub(trans.log, 'debug');
|
||||
stub(trans.connectionPool, 'select', function (cb) {
|
||||
// simulate "no connections"
|
||||
@ -475,11 +475,11 @@ describe('Transport Class', function () {
|
||||
|
||||
describe('gets a body', function () {
|
||||
it('serializes it', function (done) {
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
hosts: 'localhost'
|
||||
});
|
||||
var conn = getConnection(trans);
|
||||
var body = {
|
||||
const conn = getConnection(trans);
|
||||
const body = {
|
||||
_id: 'simple body',
|
||||
name: 'ഢധയമബ'
|
||||
};
|
||||
@ -495,11 +495,11 @@ describe('Transport Class', function () {
|
||||
});
|
||||
});
|
||||
it('serializes bulk bodies', function (done) {
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
hosts: 'localhost'
|
||||
});
|
||||
var conn = getConnection(trans);
|
||||
var body = [
|
||||
const conn = getConnection(trans);
|
||||
const body = [
|
||||
{ _id: 'simple body' },
|
||||
{ name: 'ഢധയമബ' }
|
||||
];
|
||||
@ -522,11 +522,11 @@ describe('Transport Class', function () {
|
||||
|
||||
describe('gets a body it cant serialize', function () {
|
||||
it('throws an error', function () {
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
hosts: 'localhost'
|
||||
});
|
||||
getConnection(trans);
|
||||
var body = {
|
||||
const body = {
|
||||
_id: 'circular body'
|
||||
};
|
||||
body.body = body;
|
||||
@ -541,7 +541,7 @@ describe('Transport Class', function () {
|
||||
|
||||
describe('when selecting a connection', function () {
|
||||
it('logs a warning, and responds with NoConnection when it receives nothing', function (done) {
|
||||
var trans = new Transport();
|
||||
const trans = new Transport();
|
||||
stub(trans.log, 'warning');
|
||||
trans.request({}, function (err, body, status) {
|
||||
expect(trans.log.warning.callCount).to.eql(1);
|
||||
@ -552,7 +552,7 @@ describe('Transport Class', function () {
|
||||
});
|
||||
});
|
||||
it('quits if a sync selector throws an error', function () {
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
hosts: 'localhost',
|
||||
selector: function () {
|
||||
throw new Error('I am broken');
|
||||
@ -564,7 +564,7 @@ describe('Transport Class', function () {
|
||||
});
|
||||
});
|
||||
it('quits if gets an error from an async selector', function () {
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
hosts: 'localhost',
|
||||
selector: function (connections, cb) {
|
||||
process.nextTick(function () {
|
||||
@ -578,10 +578,10 @@ describe('Transport Class', function () {
|
||||
});
|
||||
});
|
||||
it('calls connection#request once it gets one', function (done) {
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
hosts: 'localhost'
|
||||
});
|
||||
var conn = getConnection(trans);
|
||||
const conn = getConnection(trans);
|
||||
|
||||
stub(conn, 'request', function () {
|
||||
done();
|
||||
@ -595,9 +595,9 @@ describe('Transport Class', function () {
|
||||
// create a test that checks N retries
|
||||
function testRetries(retries) {
|
||||
return function (done) {
|
||||
var randomSelector = require('../../../src/lib/selectors/random');
|
||||
var connections;
|
||||
var attempts = 0;
|
||||
const randomSelector = require('../../../src/lib/selectors/random');
|
||||
let connections;
|
||||
let attempts = 0;
|
||||
function failRequest(params, cb) {
|
||||
attempts++;
|
||||
process.nextTick(function () {
|
||||
@ -605,7 +605,7 @@ describe('Transport Class', function () {
|
||||
});
|
||||
}
|
||||
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
hosts: _.map(new Array(retries + 1), function (val, i) {
|
||||
return 'localhost/' + i;
|
||||
}),
|
||||
@ -639,24 +639,24 @@ describe('Transport Class', function () {
|
||||
|
||||
describe('return value', function () {
|
||||
it('returns an object with an abort() method when a callback is sent', function () {
|
||||
var tran = new Transport();
|
||||
const tran = new Transport();
|
||||
shortCircuitRequest(tran);
|
||||
var ret = tran.request({}, _.noop);
|
||||
const ret = tran.request({}, _.noop);
|
||||
expect(ret).to.be.a('object');
|
||||
expect(ret.abort).to.be.a('function');
|
||||
});
|
||||
it('the object is a promise when a callback is not suplied', function () {
|
||||
var tran = new Transport();
|
||||
const tran = new Transport();
|
||||
shortCircuitRequest(tran);
|
||||
var ret = tran.request({});
|
||||
const ret = tran.request({});
|
||||
expect(ret.then).to.be.a('function');
|
||||
expect(ret.abort).to.be.a('function');
|
||||
ret.then(_.noop, _.noop); // prevent complaining from bluebird
|
||||
});
|
||||
it('promise is always pulled from the defer created by this.defer()', function () {
|
||||
var fakePromise = {};
|
||||
var origDefer = Transport.prototype.defer;
|
||||
var tran = new Transport({
|
||||
const fakePromise = {};
|
||||
const origDefer = Transport.prototype.defer;
|
||||
const tran = new Transport({
|
||||
defer: function () {
|
||||
return {
|
||||
resolve: _.noop,
|
||||
@ -666,7 +666,7 @@ describe('Transport Class', function () {
|
||||
}
|
||||
});
|
||||
shortCircuitRequest(tran);
|
||||
var ret = tran.request({});
|
||||
const ret = tran.request({});
|
||||
Transport.prototype.defer = origDefer;
|
||||
expect(ret).to.be(fakePromise);
|
||||
expect(ret.abort).to.be.a('function');
|
||||
@ -677,7 +677,7 @@ describe('Transport Class', function () {
|
||||
if (process && process.hasOwnProperty('domain')) {
|
||||
it('works without a domain', function () {
|
||||
expect(process.domain).to.be(null);
|
||||
var tran = new Transport();
|
||||
const tran = new Transport();
|
||||
shortCircuitRequest(tran);
|
||||
tran.request({}, function () {
|
||||
expect(process.domain).to.be(null);
|
||||
@ -686,12 +686,12 @@ describe('Transport Class', function () {
|
||||
|
||||
it('binds the callback to the correct domain', function () {
|
||||
expect(process.domain).to.be(null);
|
||||
var domain = require('domain').create();
|
||||
const domain = require('domain').create();
|
||||
domain.run(function () {
|
||||
var tran = new Transport();
|
||||
const tran = new Transport();
|
||||
shortCircuitRequest(tran);
|
||||
expect(process.domain).not.to.be(null);
|
||||
var startingDomain = process.domain
|
||||
const startingDomain = process.domain;
|
||||
tran.request({}, function () {
|
||||
expect(process.domain).not.to.be(null);
|
||||
expect(process.domain).to.be(startingDomain);
|
||||
@ -704,24 +704,24 @@ describe('Transport Class', function () {
|
||||
|
||||
describe('aborting', function () {
|
||||
it('prevents the request from starting if called in the same tick', function () {
|
||||
var tran = new Transport({
|
||||
const tran = new Transport({
|
||||
host: 'localhost'
|
||||
});
|
||||
|
||||
var con = getConnection(tran);
|
||||
const con = getConnection(tran);
|
||||
stub(con, 'request', function () {
|
||||
throw new Error('Request should not have been called.');
|
||||
});
|
||||
|
||||
var ret = tran.request({});
|
||||
const ret = tran.request({});
|
||||
ret.abort();
|
||||
});
|
||||
it('calls the function returned by the connector if it has been called', function (done) {
|
||||
var tran = new Transport({
|
||||
const tran = new Transport({
|
||||
host: 'localhost'
|
||||
});
|
||||
|
||||
var con = getConnection(tran);
|
||||
const con = getConnection(tran);
|
||||
stub(con, 'request', function () {
|
||||
process.nextTick(function () {
|
||||
ret.abort();
|
||||
@ -734,16 +734,16 @@ describe('Transport Class', function () {
|
||||
var ret = tran.request({});
|
||||
});
|
||||
it('ignores the response from the connection when the connector does not support aborting', function (done) {
|
||||
var tran = new Transport({
|
||||
const tran = new Transport({
|
||||
host: 'localhost'
|
||||
});
|
||||
|
||||
var con = getConnection(tran);
|
||||
const con = getConnection(tran);
|
||||
stub(con, 'request', function (params, cb) {
|
||||
cb();
|
||||
});
|
||||
|
||||
var ret = tran.request({}, function () {
|
||||
const ret = tran.request({}, function () {
|
||||
throw new Error('Callback should not have been called.');
|
||||
});
|
||||
ret.abort();
|
||||
@ -753,11 +753,11 @@ describe('Transport Class', function () {
|
||||
|
||||
describe('timeout', function () {
|
||||
it('uses 30 seconds for the default', function () {
|
||||
var clock = sinon.useFakeTimers('setTimeout', 'clearTimeout');
|
||||
const clock = sinon.useFakeTimers('setTimeout', 'clearTimeout');
|
||||
stub.autoRelease(clock);
|
||||
var tran = new Transport({});
|
||||
const tran = new Transport({});
|
||||
|
||||
var prom = tran.request({});
|
||||
const prom = tran.request({});
|
||||
// disregard promise, prevent bluebird's warnings
|
||||
prom.then(_.noop, _.noop);
|
||||
|
||||
@ -768,13 +768,13 @@ describe('Transport Class', function () {
|
||||
});
|
||||
});
|
||||
it('inherits the requestTimeout from the transport', function () {
|
||||
var clock = sinon.useFakeTimers('setTimeout', 'clearTimeout');
|
||||
const clock = sinon.useFakeTimers('setTimeout', 'clearTimeout');
|
||||
stub.autoRelease(clock);
|
||||
var tran = new Transport({
|
||||
const tran = new Transport({
|
||||
requestTimeout: 5000
|
||||
});
|
||||
|
||||
var prom = tran.request({});
|
||||
const prom = tran.request({});
|
||||
// disregard promise, prevent bluebird's warnings
|
||||
prom.then(_.noop, _.noop);
|
||||
|
||||
@ -788,9 +788,9 @@ describe('Transport Class', function () {
|
||||
|
||||
_.each([false, 0, null], function (falsy) {
|
||||
it('skips the timeout when it is ' + falsy, function () {
|
||||
var clock = sinon.useFakeTimers();
|
||||
const clock = sinon.useFakeTimers();
|
||||
stub.autoRelease(clock);
|
||||
var tran = new Transport({});
|
||||
const tran = new Transport({});
|
||||
stub(tran.connectionPool, 'select', function () {});
|
||||
|
||||
tran.request({
|
||||
@ -806,7 +806,7 @@ describe('Transport Class', function () {
|
||||
describe('#setHosts', function () {
|
||||
it('accepts strings, host objects, and host configs', function () {
|
||||
|
||||
var trans = new Transport({ suggestCompression: true });
|
||||
const trans = new Transport({ suggestCompression: true });
|
||||
stub(trans.connectionPool, 'setHosts');
|
||||
|
||||
trans.setHosts([
|
||||
@ -816,7 +816,7 @@ describe('Transport Class', function () {
|
||||
]);
|
||||
|
||||
sinon.assert.calledOnce(trans.connectionPool.setHosts);
|
||||
var host, hosts = trans.connectionPool.setHosts.firstCall.args[0];
|
||||
let host, hosts = trans.connectionPool.setHosts.firstCall.args[0];
|
||||
|
||||
expect(hosts).to.have.length(3);
|
||||
|
||||
@ -842,7 +842,7 @@ describe('Transport Class', function () {
|
||||
|
||||
describe('#close', function () {
|
||||
it('proxies the call to it\'s log and connection pool', function () {
|
||||
var tran = new Transport();
|
||||
const tran = new Transport();
|
||||
stub(tran.connectionPool, 'close');
|
||||
stub(tran.log, 'close');
|
||||
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
var Transport = require('../../../src/lib/transport');
|
||||
var ConnectionPool = require('../../../src/lib/connection_pool');
|
||||
var Host = require('../../../src/lib/host');
|
||||
var errors = require('../../../src/lib/errors');
|
||||
var expect = require('expect.js');
|
||||
const Transport = require('../../../src/lib/transport');
|
||||
const ConnectionPool = require('../../../src/lib/connection_pool');
|
||||
const Host = require('../../../src/lib/host');
|
||||
const errors = require('../../../src/lib/errors');
|
||||
const expect = require('expect.js');
|
||||
|
||||
var sinon = require('sinon');
|
||||
var nock = require('../../mocks/server.js');
|
||||
var through2 = require('through2');
|
||||
var _ = require('lodash');
|
||||
var stub = require('../../utils/auto_release_stub').make();
|
||||
const sinon = require('sinon');
|
||||
const nock = require('../../mocks/server.js');
|
||||
const through2 = require('through2');
|
||||
const _ = require('lodash');
|
||||
const stub = require('../../utils/auto_release_stub').make();
|
||||
|
||||
/**
|
||||
* Allows the tests call #request() without it doing anything past trying to select
|
||||
@ -28,7 +28,7 @@ function getConnection(transport, status) {
|
||||
describe('Transport + Mock server', function () {
|
||||
describe('#request', function () {
|
||||
describe('server responds', function () {
|
||||
var serverMock;
|
||||
let serverMock;
|
||||
|
||||
before(function () {
|
||||
serverMock = nock('http://localhost')
|
||||
@ -79,7 +79,7 @@ describe('Transport + Mock server', function () {
|
||||
|
||||
describe('with a 400 status code', function () {
|
||||
it('passes back a 400/BadRequest error', function (done) {
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
hosts: 'localhost'
|
||||
});
|
||||
|
||||
@ -98,7 +98,7 @@ describe('Transport + Mock server', function () {
|
||||
describe('with a 404 status code', function () {
|
||||
describe('and castExists is set', function () {
|
||||
it('sends back false', function (done) {
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
hosts: 'localhost'
|
||||
});
|
||||
|
||||
@ -115,7 +115,7 @@ describe('Transport + Mock server', function () {
|
||||
});
|
||||
describe('and the castExists param is not set', function () {
|
||||
it('sends back a 404/NotFound error', function (done) {
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
hosts: 'localhost'
|
||||
});
|
||||
|
||||
@ -134,7 +134,7 @@ describe('Transport + Mock server', function () {
|
||||
|
||||
describe('with a 500 status code', function () {
|
||||
it('passes back a 500/InternalServerError error', function (done) {
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
hosts: 'localhost'
|
||||
});
|
||||
|
||||
@ -152,7 +152,7 @@ describe('Transport + Mock server', function () {
|
||||
|
||||
describe('with a 530 status code', function () {
|
||||
it('passes back a Generic error', function (done) {
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
hosts: 'localhost'
|
||||
});
|
||||
|
||||
@ -170,7 +170,7 @@ describe('Transport + Mock server', function () {
|
||||
describe('with a 200 status code', function () {
|
||||
describe('and the castExists param is set', function () {
|
||||
it('sends back true', function (done) {
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
hosts: 'localhost'
|
||||
});
|
||||
|
||||
@ -187,7 +187,7 @@ describe('Transport + Mock server', function () {
|
||||
});
|
||||
describe('with a partial response body', function () {
|
||||
it('sends back a serialization error', function (done) {
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
hosts: 'localhost'
|
||||
});
|
||||
|
||||
@ -203,7 +203,7 @@ describe('Transport + Mock server', function () {
|
||||
});
|
||||
describe('with a valid response body', function () {
|
||||
it('sends back the body and status code with no error', function (done) {
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
hosts: 'localhost'
|
||||
});
|
||||
|
||||
@ -222,7 +222,7 @@ describe('Transport + Mock server', function () {
|
||||
|
||||
describe('with plain text', function () {
|
||||
it('notices the content-type header and returns the text', function (done) {
|
||||
var trans = new Transport({
|
||||
const trans = new Transport({
|
||||
hosts: 'localhost'
|
||||
});
|
||||
|
||||
@ -239,13 +239,13 @@ describe('Transport + Mock server', function () {
|
||||
|
||||
describe('return value', function () {
|
||||
it('resolves the promise it with the response body', function (done) {
|
||||
var serverMock = nock('http://esbox.1.com')
|
||||
const serverMock = nock('http://esbox.1.com')
|
||||
.get('/')
|
||||
.reply(200, {
|
||||
good: 'day'
|
||||
});
|
||||
|
||||
var tran = new Transport({
|
||||
const tran = new Transport({
|
||||
hosts: 'http://esbox.1.com'
|
||||
});
|
||||
|
||||
@ -260,13 +260,13 @@ describe('Transport + Mock server', function () {
|
||||
|
||||
describe('timeout', function () {
|
||||
it('clears the timeout when the request is complete', function () {
|
||||
var clock = sinon.useFakeTimers('setTimeout', 'clearTimeout');
|
||||
const clock = sinon.useFakeTimers('setTimeout', 'clearTimeout');
|
||||
stub.autoRelease(clock);
|
||||
var tran = new Transport({
|
||||
const tran = new Transport({
|
||||
host: 'http://localhost:9200'
|
||||
});
|
||||
|
||||
var server = nock('http://localhost:9200')
|
||||
const server = nock('http://localhost:9200')
|
||||
.get('/')
|
||||
.reply(200, {
|
||||
i: 'am here'
|
||||
@ -282,11 +282,11 @@ describe('Transport + Mock server', function () {
|
||||
});
|
||||
|
||||
it('timeout responds with a requestTimeout error', function (done) {
|
||||
var tran = new Transport({
|
||||
const tran = new Transport({
|
||||
host: 'http://localhost:9200'
|
||||
});
|
||||
|
||||
var server = nock('http://localhost:9200')
|
||||
const server = nock('http://localhost:9200')
|
||||
.get('/')
|
||||
.delay(1000)
|
||||
.reply(200, {
|
||||
@ -304,13 +304,13 @@ describe('Transport + Mock server', function () {
|
||||
|
||||
describe('sniffOnConnectionFault', function () {
|
||||
it('schedules a sniff when sniffOnConnectionFault is set and a connection failes', function () {
|
||||
var clock = sinon.useFakeTimers('setTimeout');
|
||||
const clock = sinon.useFakeTimers('setTimeout');
|
||||
stub.autoRelease(clock);
|
||||
|
||||
var serverMock = nock('http://esbox.1.com')
|
||||
const serverMock = nock('http://esbox.1.com')
|
||||
.get('/')
|
||||
.reply(200, function () {
|
||||
var str = through2(function (chunk, enc, cb) {
|
||||
const str = through2(function (chunk, enc, cb) {
|
||||
cb(new Error('force error'));
|
||||
});
|
||||
|
||||
@ -324,7 +324,7 @@ describe('Transport + Mock server', function () {
|
||||
|
||||
stub(ConnectionPool.prototype, '_onConnectionDied');
|
||||
stub(Transport.prototype, 'sniff');
|
||||
var tran = new Transport({
|
||||
const tran = new Transport({
|
||||
hosts: 'http://esbox.1.com',
|
||||
sniffOnConnectionFault: true,
|
||||
maxRetries: 0
|
||||
@ -343,7 +343,7 @@ describe('Transport + Mock server', function () {
|
||||
expect(tran.sniff.callCount).to.eql(0);
|
||||
expect(_.size(clock.timers)).to.eql(1);
|
||||
|
||||
var timeout = _.values(clock.timers).pop();
|
||||
const timeout = _.values(clock.timers).pop();
|
||||
timeout.func();
|
||||
expect(tran.sniff.callCount).to.eql(1);
|
||||
});
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var _ = require('../../../src/lib/utils');
|
||||
var expect = require('expect.js');
|
||||
const _ = require('../../../src/lib/utils');
|
||||
const expect = require('expect.js');
|
||||
|
||||
var stub = require('../../utils/auto_release_stub').make();
|
||||
const stub = require('../../utils/auto_release_stub').make();
|
||||
|
||||
describe('Utils', function () {
|
||||
|
||||
@ -238,14 +238,14 @@ describe('Utils', function () {
|
||||
describe('#deepMerge', function () {
|
||||
|
||||
it('returns the same object that was passed', function () {
|
||||
var obj = {
|
||||
const obj = {
|
||||
foo: 'bar'
|
||||
};
|
||||
expect(_.deepMerge(obj, { bar: 'baz' })).to.eql(obj);
|
||||
});
|
||||
|
||||
it('concats arrays', function () {
|
||||
var obj = {
|
||||
const obj = {
|
||||
foo: ['bax', 'boz']
|
||||
};
|
||||
_.deepMerge(obj, { foo: ['boop'] });
|
||||
@ -253,7 +253,7 @@ describe('Utils', function () {
|
||||
});
|
||||
|
||||
it('wont merge values of different types', function () {
|
||||
var obj = {
|
||||
const obj = {
|
||||
foo: ['stop', 'foo', 'stahp']
|
||||
};
|
||||
_.deepMerge(obj, { foo: 'string' });
|
||||
@ -261,7 +261,7 @@ describe('Utils', function () {
|
||||
});
|
||||
|
||||
it('works recursively', function () {
|
||||
var obj = {
|
||||
const obj = {
|
||||
foo: 'bar',
|
||||
bax: {
|
||||
foo: ['bax', 'boz']
|
||||
@ -275,8 +275,8 @@ describe('Utils', function () {
|
||||
|
||||
describe('#createArray', function () {
|
||||
it('accepts an array of things and simply returns a copy of it', function () {
|
||||
var inp = [{ a: 1 }, 'pizza'];
|
||||
var out = _.createArray(inp);
|
||||
const inp = [{ a: 1 }, 'pizza'];
|
||||
const out = _.createArray(inp);
|
||||
expect(out).to.eql(inp);
|
||||
expect(out).to.not.be(inp);
|
||||
});
|
||||
@ -309,28 +309,28 @@ describe('Utils', function () {
|
||||
* _.funcEnum(object, key, opts, default);
|
||||
*/
|
||||
it('tests if the value at key in object is a function, returns it if so', function () {
|
||||
var config = {
|
||||
const config = {
|
||||
func: function () {}
|
||||
};
|
||||
expect(_.funcEnum(config, 'func', {}, 'toString'))
|
||||
.to.be(config.func);
|
||||
});
|
||||
it('tests if the value at key in object is undefined, returns the option at key default if so', function () {
|
||||
var config = {
|
||||
const config = {
|
||||
func: undefined
|
||||
};
|
||||
expect(_.funcEnum(config, 'func', {}, 'toString'))
|
||||
.to.be(Object.prototype.toString);
|
||||
});
|
||||
it('tests if the value at key in object is a string, returns the option at that key if so', function () {
|
||||
var config = {
|
||||
const config = {
|
||||
'config key name': 'toString'
|
||||
};
|
||||
expect(_.funcEnum(config, 'config key name', { toString: 'pizza' }, 'toJSON'))
|
||||
.to.be('pizza');
|
||||
});
|
||||
it('throws an informative error if the selection if invalid', function () {
|
||||
var config = {
|
||||
const config = {
|
||||
'config': 'val'
|
||||
};
|
||||
|
||||
@ -350,15 +350,15 @@ describe('Utils', function () {
|
||||
|
||||
describe('#applyArgs', function () {
|
||||
_.times(10, function (i) {
|
||||
var method = i > 5 ? 'apply' : 'call';
|
||||
var argCount = i + 1;
|
||||
var slice = 1;
|
||||
const method = i > 5 ? 'apply' : 'call';
|
||||
const argCount = i + 1;
|
||||
const slice = 1;
|
||||
|
||||
it('uses ' + method + ' with ' + i + ' args', function () {
|
||||
var func = function () {};
|
||||
const func = function () {};
|
||||
stub(func, method);
|
||||
|
||||
var args = _.map(new Array(i), function (val, i) { return i; });
|
||||
const args = _.map(new Array(i), function (val, i) { return i; });
|
||||
_.applyArgs(func, null, args);
|
||||
|
||||
expect(func[method].callCount).to.eql(1);
|
||||
@ -371,11 +371,11 @@ describe('Utils', function () {
|
||||
|
||||
it('slices the arguments properly before calling ' + method + ' with ' + argCount + ' args sliced at ' + slice,
|
||||
function () {
|
||||
var func = function () {};
|
||||
const func = function () {};
|
||||
stub(func, method);
|
||||
|
||||
var args = _.map(new Array(argCount), function (val, i) { return i; });
|
||||
var expected = args.slice(slice);
|
||||
const args = _.map(new Array(argCount), function (val, i) { return i; });
|
||||
const expected = args.slice(slice);
|
||||
_.applyArgs(func, null, args, slice);
|
||||
|
||||
expect(func[method].callCount).to.eql(1);
|
||||
@ -397,14 +397,14 @@ describe('Utils', function () {
|
||||
});
|
||||
|
||||
if (require('stream').Writable) {
|
||||
var MockWritableStream = require('../../mocks/writable_stream');
|
||||
const MockWritableStream = require('../../mocks/writable_stream');
|
||||
it('ignores empty stream', function () {
|
||||
var stream = new MockWritableStream();
|
||||
const stream = new MockWritableStream();
|
||||
expect(_.getUnwrittenFromStream(stream)).to.be('');
|
||||
});
|
||||
|
||||
it('returns only what is in the buffer', function () {
|
||||
var stream = new MockWritableStream();
|
||||
const stream = new MockWritableStream();
|
||||
stream.write('hot');
|
||||
stream.write('dog');
|
||||
expect(_.getUnwrittenFromStream(stream)).to.be('dog');
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
describe('Yaml Test Reader', function () {
|
||||
var YamlDoc = require('../../integration/yaml_suite/yaml_doc');
|
||||
var compare = YamlDoc.compareRangeToVersion;
|
||||
var expect = require('expect.js');
|
||||
const YamlDoc = require('../../integration/yaml_suite/yaml_doc');
|
||||
const compare = YamlDoc.compareRangeToVersion;
|
||||
const expect = require('expect.js');
|
||||
|
||||
describe('version range comparison', function () {
|
||||
it('supports unbounded ranges', function () {
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
|
||||
var sinon = require('sinon');
|
||||
const sinon = require('sinon');
|
||||
|
||||
exports.make = function () {
|
||||
var log = [];
|
||||
const log = [];
|
||||
afterEach(function () {
|
||||
var stub;
|
||||
let stub;
|
||||
while (stub = log.pop()) {
|
||||
stub.restore();
|
||||
}
|
||||
});
|
||||
var stubber = function () {
|
||||
const stubber = function () {
|
||||
log.push(sinon.stub.apply(sinon, arguments));
|
||||
};
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
var _ = require('lodash');
|
||||
var expect = require('expect.js');
|
||||
const _ = require('lodash');
|
||||
const expect = require('expect.js');
|
||||
module.exports = function expectSubObject(obj, subObj) {
|
||||
_.forOwn(subObj, function (val, prop) {
|
||||
if (typeof obj[prop] === 'object') {
|
||||
|
||||
@ -6,16 +6,16 @@
|
||||
*/
|
||||
module.exports = JenkinsReporter;
|
||||
|
||||
var Base = require('mocha/lib/reporters/base');
|
||||
var _ = require('lodash');
|
||||
var chalk = require('chalk');
|
||||
var makeJUnitXml = require('./make_j_unit_xml');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var inspect = require('util').inspect;
|
||||
const Base = require('mocha/lib/reporters/base');
|
||||
const _ = require('lodash');
|
||||
const chalk = require('chalk');
|
||||
const makeJUnitXml = require('./make_j_unit_xml');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const inspect = require('util').inspect;
|
||||
|
||||
var log = (function () {
|
||||
var locked = _.bind(process.stdout.write, process.stdout);
|
||||
const log = (function () {
|
||||
const locked = _.bind(process.stdout.write, process.stdout);
|
||||
return function (str) {
|
||||
if (typeof str !== 'string') {
|
||||
str = inspect(str);
|
||||
@ -24,9 +24,9 @@ var log = (function () {
|
||||
};
|
||||
}());
|
||||
|
||||
var integration = _.find(process.argv, function (arg) { return arg.indexOf('test/integration') > -1; });
|
||||
var unit = _.find(process.argv, function (arg) { return arg.indexOf('test/unit') > -1; });
|
||||
var output;
|
||||
const integration = _.find(process.argv, function (arg) { return arg.indexOf('test/integration') > -1; });
|
||||
const unit = _.find(process.argv, function (arg) { return arg.indexOf('test/unit') > -1; });
|
||||
let output;
|
||||
|
||||
if (unit) {
|
||||
output = path.join(__dirname, '../junit-node-unit.xml');
|
||||
@ -39,16 +39,16 @@ if (unit) {
|
||||
function JenkinsReporter(runner) {
|
||||
Base.call(this, runner);
|
||||
|
||||
var stats = this.stats;
|
||||
var pass = 0;
|
||||
var pending = 0;
|
||||
var fail = 0;
|
||||
var rootSuite = {
|
||||
const stats = this.stats;
|
||||
let pass = 0;
|
||||
let pending = 0;
|
||||
let fail = 0;
|
||||
const rootSuite = {
|
||||
results: [],
|
||||
suites: []
|
||||
};
|
||||
|
||||
var stack = [rootSuite];
|
||||
const stack = [rootSuite];
|
||||
|
||||
function indt() {
|
||||
return (new Array(stack.length + 1)).join(' ');
|
||||
@ -105,7 +105,7 @@ function JenkinsReporter(runner) {
|
||||
log(chalk.red('x'));
|
||||
}
|
||||
|
||||
var errMsg = void 0;
|
||||
let errMsg = void 0;
|
||||
|
||||
if (test.err) {
|
||||
errMsg = test.err.stack || test.err.toString();
|
||||
@ -146,7 +146,7 @@ function JenkinsReporter(runner) {
|
||||
|
||||
runner.on('hook end', function (hook) {
|
||||
if (hook.title.indexOf('"after each"') > -1 && stack[0] && stack[0].results.length) {
|
||||
var result = _.last(stack[0].results);
|
||||
const result = _.last(stack[0].results);
|
||||
result.stdout += stack[0].stdout;
|
||||
result.stderr += stack[0].stderr;
|
||||
stack[0].stdout = stack[0].stderr = '';
|
||||
@ -155,10 +155,10 @@ function JenkinsReporter(runner) {
|
||||
|
||||
runner.on('end', function () {
|
||||
restoreStdio();
|
||||
var xml = makeJUnitXml('node ' + process.version, {
|
||||
const xml = makeJUnitXml('node ' + process.version, {
|
||||
stats: stats,
|
||||
suites: _.map(rootSuite.suites, function removeElements(suite) {
|
||||
var s = {
|
||||
const s = {
|
||||
name: suite.name,
|
||||
start: suite.start,
|
||||
time: suite.time || 0,
|
||||
@ -186,8 +186,8 @@ function JenkinsReporter(runner) {
|
||||
|
||||
// overload the write methods on stdout and stderr
|
||||
['stdout', 'stderr'].forEach(function (name) {
|
||||
var obj = process[name];
|
||||
var orig = obj.write;
|
||||
const obj = process[name];
|
||||
const orig = obj.write;
|
||||
obj.write = function (chunk) {
|
||||
if (stack[0]) {
|
||||
stack[0][name] = (stack[0][name] || '') + chunk;
|
||||
|
||||
@ -24,17 +24,17 @@
|
||||
*/
|
||||
module.exports = makeJUnitXml;
|
||||
|
||||
var testXml = require('xmlbuilder');
|
||||
var suites = testXml.create('testsuites');
|
||||
var suiteCount = 0;
|
||||
var moment = require('moment');
|
||||
var _ = require('lodash');
|
||||
var chalk = require('chalk');
|
||||
const testXml = require('xmlbuilder');
|
||||
const suites = testXml.create('testsuites');
|
||||
let suiteCount = 0;
|
||||
const moment = require('moment');
|
||||
const _ = require('lodash');
|
||||
const chalk = require('chalk');
|
||||
|
||||
function makeJUnitXml(runnerName, testDetails) {
|
||||
_.each(testDetails.suites, function serializeSuite(suiteInfo) {
|
||||
|
||||
var suite = suites.ele('testsuite', {
|
||||
const suite = suites.ele('testsuite', {
|
||||
package: 'elasticsearch-js',
|
||||
id: suiteCount++,
|
||||
name: suiteInfo.name,
|
||||
@ -47,8 +47,8 @@ function makeJUnitXml(runnerName, testDetails) {
|
||||
});
|
||||
|
||||
_.each(suiteInfo.results, function (testInfo) {
|
||||
var section;
|
||||
var integration = false;
|
||||
let section;
|
||||
let integration = false;
|
||||
|
||||
if (suiteInfo.name.match(/\/.*\.yaml$/)) {
|
||||
section = suiteInfo.name.split('/').slice(0, -1).join('/').replace(/\./g, '/');
|
||||
@ -61,7 +61,7 @@ function makeJUnitXml(runnerName, testDetails) {
|
||||
integration = true;
|
||||
}
|
||||
|
||||
var testcase = suite.ele('testcase', {
|
||||
const testcase = suite.ele('testcase', {
|
||||
name: testInfo.name,
|
||||
time: (testInfo.time || 0) / 1000,
|
||||
classname: runnerName + (integration ? ' - integration' : '') + '.' + section
|
||||
@ -93,8 +93,8 @@ function makeJUnitXml(runnerName, testDetails) {
|
||||
}
|
||||
|
||||
function giveOutput(el, info) {
|
||||
var out = info.stdout.trim();
|
||||
var err = info.stderr.trim();
|
||||
const out = info.stdout.trim();
|
||||
const err = info.stderr.trim();
|
||||
|
||||
if (out) {
|
||||
el.ele('system-out', {}).cdata(chalk.stripColor(out));
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
/* eslint-disable import/no-unresolved */
|
||||
var express = require('express');
|
||||
var http = require('http');
|
||||
var fs = require('fs');
|
||||
var _ = require('lodash');
|
||||
var async = require('async');
|
||||
var root = require('path').join(__dirname, '../..');
|
||||
var browserify = require('browserify');
|
||||
var pkg = require(root + '/package.json');
|
||||
var unitSpecDir = root + '/test/unit/specs';
|
||||
var browserBuildsDir = root + '/test/unit/browser_builds';
|
||||
const express = require('express');
|
||||
const http = require('http');
|
||||
const fs = require('fs');
|
||||
const _ = require('lodash');
|
||||
const async = require('async');
|
||||
const root = require('path').join(__dirname, '../..');
|
||||
const browserify = require('browserify');
|
||||
const pkg = require(root + '/package.json');
|
||||
const unitSpecDir = root + '/test/unit/specs';
|
||||
const browserBuildsDir = root + '/test/unit/browser_builds';
|
||||
|
||||
var testFiles = {};
|
||||
const testFiles = {};
|
||||
|
||||
testFiles.unit = _(fs.readdirSync(unitSpecDir))
|
||||
.difference([
|
||||
@ -33,12 +33,12 @@ testFiles.build = fs.readdirSync(browserBuildsDir)
|
||||
return browserBuildsDir + '/' + file;
|
||||
}
|
||||
|
||||
return null
|
||||
return null;
|
||||
})
|
||||
.filter(Boolean);
|
||||
|
||||
// generic aliasify instance
|
||||
var aliasify = require('aliasify').configure({
|
||||
const aliasify = require('aliasify').configure({
|
||||
aliases: pkg.browser,
|
||||
excludeExtensions: 'json',
|
||||
// verbose: false,
|
||||
@ -46,7 +46,7 @@ var aliasify = require('aliasify').configure({
|
||||
});
|
||||
|
||||
// queue for bundle requests, two at a time
|
||||
var bundleQueue = async.queue(function (task, done) {
|
||||
const bundleQueue = async.queue(function (task, done) {
|
||||
task(done);
|
||||
}, 2);
|
||||
|
||||
@ -54,16 +54,16 @@ var bundleQueue = async.queue(function (task, done) {
|
||||
function bundleTests(name) {
|
||||
return function (req, res, next) {
|
||||
bundleQueue.push(function (_cb) {
|
||||
var done = function (err) {
|
||||
const done = function (err) {
|
||||
if (err) { return next(err); }
|
||||
_cb(err);
|
||||
};
|
||||
|
||||
res.set('Content-Type', 'application/javascript');
|
||||
|
||||
var b = browserify(testFiles[name]);
|
||||
const b = browserify(testFiles[name]);
|
||||
b.transform(aliasify);
|
||||
var str = b.bundle({
|
||||
const str = b.bundle({
|
||||
insertGlobals: true
|
||||
});
|
||||
|
||||
@ -81,7 +81,7 @@ function sendFile(file) {
|
||||
};
|
||||
}
|
||||
|
||||
var app = express();
|
||||
const app = express();
|
||||
|
||||
app
|
||||
.use(app.router)
|
||||
|
||||
Reference in New Issue
Block a user