Skip to content

Commit

Permalink
[internal] Replace var assignments with let in ui tests
Browse files Browse the repository at this point in the history
This change was applied to any .js files under __tests__ directories in
the ui module.

This was an automatic replacement from var to let for any variable
declaration that doubles as the initial assignment. Ultimately we want
most of these to be converted to const, but this commit is so large that
it warrants breaking each step of automation up into its own commit.

For example:

var foo = 'bar'; becomes let foo = 'var';

This was accomplished by replacing:
find: var ([a-zA-Z_$][0-9a-zA-Z_$]*)(\s+)=
replace: let $1$2=
  • Loading branch information
epixa committed Apr 12, 2016
1 parent 2f3cdf6 commit 863228d
Show file tree
Hide file tree
Showing 204 changed files with 2,016 additions and 2,016 deletions.
4 changes: 2 additions & 2 deletions src/ui/__tests__/ui_exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as kbnTestServer from '../../../test/utils/kbn_server';
describe('UiExports', function () {
describe('#find()', function () {
it('finds exports based on the passed export names', function () {
var uiExports = new UiExports({});
let uiExports = new UiExports({});
uiExports.aliases.foo = ['a', 'b', 'c'];
uiExports.aliases.bar = ['d', 'e', 'f'];

Expand All @@ -17,7 +17,7 @@ describe('UiExports', function () {
});

it('allows query types that match nothing', function () {
var uiExports = new UiExports({});
let uiExports = new UiExports({});
uiExports.aliases.foo = ['a', 'b', 'c'];

expect(uiExports.find(['foo'])).to.eql(['a', 'b', 'c']);
Expand Down
32 changes: 16 additions & 16 deletions src/ui/public/agg_response/geo_json/__tests__/geo_json.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ describe('GeoJson Agg Response Converter', function () {

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
var Vis = Private(VisProvider);
var indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
let Vis = Private(VisProvider);
let indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);

esResponse = Private(FixturesAggRespGeohashGridProvider);
tabify = Private(AggResponseTabifyTabifyProvider);
Expand Down Expand Up @@ -60,8 +60,8 @@ describe('GeoJson Agg Response Converter', function () {

describe('with table ' + JSON.stringify(tableOpts), function () {
it('outputs a chart', function () {
var table = makeTable();
var chart = makeSingleChart(table);
let table = makeTable();
let chart = makeSingleChart(table);
expect(chart).to.only.have.keys(
'title',
'tooltipFormatter',
Expand All @@ -78,18 +78,18 @@ describe('GeoJson Agg Response Converter', function () {
});

it('outputs geohash points as features in a feature collection', function () {
var table = makeTable();
var chart = makeSingleChart(table);
var geoJson = chart.geoJson;
let table = makeTable();
let chart = makeSingleChart(table);
let geoJson = chart.geoJson;

expect(geoJson.type).to.be('FeatureCollection');
expect(geoJson.features).to.be.an('array');
expect(geoJson.features).to.have.length(table.rows.length);
});

it('exports a bunch of properties about the geo hash grid', function () {
var geoJson = makeGeoJson();
var props = geoJson.properties;
let geoJson = makeGeoJson();
let props = geoJson.properties;

// props
expect(props).to.be.an('object');
Expand Down Expand Up @@ -122,7 +122,7 @@ describe('GeoJson Agg Response Converter', function () {

it('should be geoJson format', function () {
table.rows.forEach(function (row, i) {
var feature = chart.geoJson.features[i];
let feature = chart.geoJson.features[i];
expect(feature).to.have.property('geometry');
expect(feature.geometry).to.be.an('object');
expect(feature).to.have.property('properties');
Expand All @@ -132,7 +132,7 @@ describe('GeoJson Agg Response Converter', function () {

it('should have valid geometry data', function () {
table.rows.forEach(function (row, i) {
var geometry = chart.geoJson.features[i].geometry;
let geometry = chart.geoJson.features[i].geometry;
expect(geometry.type).to.be('Point');
expect(geometry).to.have.property('coordinates');
expect(geometry.coordinates).to.be.an('array');
Expand All @@ -144,8 +144,8 @@ describe('GeoJson Agg Response Converter', function () {

it('should have value properties data', function () {
table.rows.forEach(function (row, i) {
var props = chart.geoJson.features[i].properties;
var keys = ['value', 'geohash', 'aggConfigResult', 'rectangle', 'center'];
let props = chart.geoJson.features[i].properties;
let keys = ['value', 'geohash', 'aggConfigResult', 'rectangle', 'center'];
expect(props).to.be.an('object');
expect(props).to.only.have.keys(keys);
expect(props.geohash).to.be.a('string');
Expand All @@ -155,15 +155,15 @@ describe('GeoJson Agg Response Converter', function () {

it('should use latLng in properties and lngLat in geometry', function () {
table.rows.forEach(function (row, i) {
var geometry = chart.geoJson.features[i].geometry;
var props = chart.geoJson.features[i].properties;
let geometry = chart.geoJson.features[i].geometry;
let props = chart.geoJson.features[i].properties;
expect(props.center).to.eql(geometry.coordinates.slice(0).reverse());
});
});

it('should handle both AggConfig and non-AggConfig results', function () {
table.rows.forEach(function (row, i) {
var props = chart.geoJson.features[i].properties;
let props = chart.geoJson.features[i].properties;
if (tableOpts.asAggConfigResults) {
expect(props.aggConfigResult).to.be(row[metricColI]);
expect(props.value).to.be(row[metricColI].value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('buildHierarchicalData', function () {
let results;

beforeEach(function () {
var id = 1;
let id = 1;
vis = new Vis(indexPattern, {
type: 'pie',
aggs: [
Expand All @@ -48,7 +48,7 @@ describe('buildHierarchicalData', function () {
});

it('should set the slices with one child to a consistent label', function () {
var checkLabel = 'Count';
let checkLabel = 'Count';
expect(results).to.have.property('slices');
expect(results.slices).to.have.property('children');
expect(results.slices.children).to.have.length(1);
Expand All @@ -67,8 +67,8 @@ describe('buildHierarchicalData', function () {
describe('rows and columns', function () {

it('should set the rows', function () {
var id = 1;
var vis = new Vis(indexPattern, {
let id = 1;
let vis = new Vis(indexPattern, {
type: 'pie',
aggs: [
{ type: 'avg', schema: 'metric', params: { field: 'bytes' } },
Expand All @@ -79,13 +79,13 @@ describe('buildHierarchicalData', function () {
});
// We need to set the aggs to a known value.
_.each(vis.aggs, function (agg) { agg.id = 'agg_' + id++; });
var results = buildHierarchicalData(vis, fixtures.threeTermBuckets);
let results = buildHierarchicalData(vis, fixtures.threeTermBuckets);
expect(results).to.have.property('rows');
});

it('should set the columns', function () {
var id = 1;
var vis = new Vis(indexPattern, {
let id = 1;
let vis = new Vis(indexPattern, {
type: 'pie',
aggs: [
{ type: 'avg', schema: 'metric', params: { field: 'bytes' } },
Expand All @@ -96,7 +96,7 @@ describe('buildHierarchicalData', function () {
});
// We need to set the aggs to a known value.
_.each(vis.aggs, function (agg) { agg.id = 'agg_' + id++; });
var results = buildHierarchicalData(vis, fixtures.threeTermBuckets);
let results = buildHierarchicalData(vis, fixtures.threeTermBuckets);
expect(results).to.have.property('columns');
});

Expand All @@ -107,7 +107,7 @@ describe('buildHierarchicalData', function () {
let results;

beforeEach(function () {
var id = 1;
let id = 1;
vis = new Vis(indexPattern, {
type: 'pie',
aggs: [
Expand Down Expand Up @@ -149,7 +149,7 @@ describe('buildHierarchicalData', function () {
let results;

beforeEach(function () {
var id = 1;
let id = 1;
vis = new Vis(indexPattern, {
type: 'pie',
aggs: [
Expand Down Expand Up @@ -181,7 +181,7 @@ describe('buildHierarchicalData', function () {
let results;

beforeEach(function () {
var id = 1;
let id = 1;
vis = new Vis(indexPattern, {
type: 'pie',
aggs: [
Expand Down Expand Up @@ -222,7 +222,7 @@ describe('buildHierarchicalData', function () {
let results;

beforeEach(function () {
var id = 1;
let id = 1;
vis = new Vis(indexPattern, {
type: 'pie',
aggs: [
Expand Down Expand Up @@ -258,7 +258,7 @@ describe('buildHierarchicalData', function () {
let results;

beforeEach(function () {
var id = 1;
let id = 1;
vis = new Vis(indexPattern, {
type: 'pie',
aggs: [
Expand All @@ -281,7 +281,7 @@ describe('buildHierarchicalData', function () {
});

it('should set the hits attribute for the results', function () {
var errCall = Notifier.prototype.error.getCall(0);
let errCall = Notifier.prototype.error.getCall(0);
expect(errCall).to.be.ok();
expect(errCall.args[0]).to.contain('not supported');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import collectBranch from 'ui/agg_response/hierarchical/_collect_branch';
import expect from 'expect.js';
describe('collectBranch()', function () {
let results;
var convert = function (name) {
let convert = function (name) {
return 'converted:' + name;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('buildHierarchicalData()', function () {
}));

beforeEach(function () {
var id = 1;
let id = 1;
vis = new Vis(indexPattern, {
type: 'pie',
aggs: [
Expand All @@ -37,7 +37,7 @@ describe('buildHierarchicalData()', function () {
{ type: 'terms', schema: 'segment', params: { field: 'geo.src' }}
]
});
var buckets = arrayToLinkedList(vis.aggs.bySchemaGroup.buckets);
let buckets = arrayToLinkedList(vis.aggs.bySchemaGroup.buckets);
// We need to set the aggs to a known value.
_.each(vis.aggs, function (agg) { agg.id = 'agg_' + id++; });
results = createRawData(vis, fixtures.threeTermBuckets);
Expand All @@ -48,7 +48,7 @@ describe('buildHierarchicalData()', function () {
expect(results.columns).to.have.length(6);
_.each(results.columns, function (column) {
expect(column).to.have.property('aggConfig');
var agg = column.aggConfig;
let agg = column.aggConfig;
expect(column).to.have.property('categoryName', agg.schema.name);
expect(column).to.have.property('id', agg.id);
expect(column).to.have.property('aggType', agg.type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ describe('buildHierarchicalData()', function () {

it('should normalize a bucket object into an array', function () {

var bucket = {
let bucket = {
buckets: {
foo: { doc_count: 1 },
bar: { doc_count: 2 }
}
};

var buckets = extractBuckets(bucket);
let buckets = extractBuckets(bucket);
expect(buckets).to.be.an(Array);
expect(buckets).to.have.length(2);
expect(buckets[0]).to.have.property('key', 'foo');
Expand All @@ -24,19 +24,19 @@ describe('buildHierarchicalData()', function () {
});

it('should return an empty array for undefined buckets', function () {
var buckets = extractBuckets();
let buckets = extractBuckets();
expect(buckets).to.be.an(Array);
expect(buckets).to.have.length(0);
});

it('should return the bucket array', function () {
var bucket = {
let bucket = {
buckets: [
{ key: 'foo', doc_count: 1 },
{ key: 'bar', doc_count: 2 }
]
};
var buckets = extractBuckets(bucket);
let buckets = extractBuckets(bucket);
expect(buckets).to.be.an(Array);
expect(buckets).to.be(bucket.buckets);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,25 @@ describe('buildHierarchicalData()', function () {
});

it('relies on metricAgg#getValue() for the size of the children', function () {
var aggData = {
let aggData = {
buckets: [
{ key: 'foo' },
{ key: 'bar' }
]
};

var football = {};
let football = {};
fixture.metric.getValue = _.constant(football);

var children = transform(fixture.agg, fixture.metric, aggData);
let children = transform(fixture.agg, fixture.metric, aggData);
expect(children).to.be.an(Array);
expect(children).to.have.length(2);
expect(children[0]).to.have.property('size', football);
expect(children[1]).to.have.property('size', football);
});

it('should create two levels of metrics', function () {
var children = transform(fixture.agg, fixture.metric, fixture.aggData);
let children = transform(fixture.agg, fixture.metric, fixture.aggData);
fixture.metric.getValue = function (b) { return b.doc_count; };

expect(children).to.be.an(Array);
Expand Down
22 changes: 11 additions & 11 deletions src/ui/public/agg_response/point_series/__tests__/_add_to_siri.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ describe('addToSiri', function () {
}));

it('creates a new series the first time it sees an id', function () {
var series = new Map();
var point = {};
var id = 'id';
let series = new Map();
let point = {};
let id = 'id';
addToSiri(series, point, id);

expect(series.has(id)).to.be(true);
Expand All @@ -23,13 +23,13 @@ describe('addToSiri', function () {
});

it('adds points to existing series if id has been seen', function () {
var series = new Map();
var id = 'id';
let series = new Map();
let id = 'id';

var point = {};
let point = {};
addToSiri(series, point, id);

var point2 = {};
let point2 = {};
addToSiri(series, point2, id);

expect(series.has(id)).to.be(true);
Expand All @@ -41,10 +41,10 @@ describe('addToSiri', function () {
});

it('allows overriding the series label', function () {
var series = new Map();
var id = 'id';
var label = 'label';
var point = {};
let series = new Map();
let id = 'id';
let label = 'label';
let point = {};
addToSiri(series, point, id, label);

expect(series.has(id)).to.be(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ describe('makeFakeXAspect', function () {
}));

it('creates an object that looks like an aspect', function () {
var vis = new Vis(indexPattern, { type: 'histogram' });
var aspect = makeFakeXAspect(vis);
let vis = new Vis(indexPattern, { type: 'histogram' });
let aspect = makeFakeXAspect(vis);

expect(aspect)
.to.have.property('i', -1)
Expand Down
Loading

0 comments on commit 863228d

Please sign in to comment.