Skip to content

Commit

Permalink
Backport PR #6865
Browse files Browse the repository at this point in the history
---------

**Commit 1:**
[internal] Replace var assignments with let in ui tests

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=

* Original sha: 863228d
* Authored by Court Ewing <[email protected]> on 2016-04-12T15:30:18Z
  • Loading branch information
epixa committed Apr 13, 2016
1 parent 3a36b4b commit 84726c3
Show file tree
Hide file tree
Showing 226 changed files with 2,873 additions and 2,873 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 @@ -5,7 +5,7 @@ import UiExports from '../UiExports';
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 @@ -15,7 +15,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
26 changes: 13 additions & 13 deletions src/ui/public/Binder/__tests__/Binder.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var $ = require('jquery');
var sinon = require('auto-release-sinon');
var expect = require('expect.js');
var ngMock = require('ngMock');
let $ = require('jquery');
let sinon = require('auto-release-sinon');
let expect = require('expect.js');
let ngMock = require('ngMock');

var Binder = require('ui/Binder');
let Binder = require('ui/Binder');

describe('Binder class', function () {
let $scope;
Expand All @@ -16,13 +16,13 @@ describe('Binder class', function () {
context('Constructing with a $scope', function () {
it('accepts a $scope and listens for $destroy', function () {
sinon.stub($scope, '$on');
var binder = new Binder($scope);
let binder = new Binder($scope);
expect($scope.$on.callCount).to.be(1);
expect($scope.$on.args[0][0]).to.be('$destroy');
});

it('unbinds when the $scope is destroyed', function () {
var binder = new Binder($scope);
let binder = new Binder($scope);
sinon.stub(binder, 'destroy');
$scope.$destroy();
expect(binder.destroy.callCount).to.be(1);
Expand All @@ -31,12 +31,12 @@ describe('Binder class', function () {

describe('Binder#on', function () {
it('binds to normal event emitters', function () {
var binder = new Binder();
var emitter = {
let binder = new Binder();
let emitter = {
on: sinon.stub(),
removeListener: sinon.stub()
};
var handler = sinon.stub();
let handler = sinon.stub();

binder.on(emitter, 'click', handler);
expect(emitter.on.callCount).to.be(1);
Expand All @@ -52,9 +52,9 @@ describe('Binder class', function () {

describe('Binder#jqOn', function () {
it('binds jquery event handlers', function () {
var binder = new Binder();
var el = document.createElement('div');
var handler = sinon.stub();
let binder = new Binder();
let el = document.createElement('div');
let handler = sinon.stub();

binder.jqOn(el, 'click', handler);
$(el).click();
Expand Down
40 changes: 20 additions & 20 deletions src/ui/public/IndexedArray/__tests__/IndexedArray.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

var _ = require('lodash');
var expect = require('expect.js');
var IndexedArray = require('ui/IndexedArray');
let _ = require('lodash');
let expect = require('expect.js');
let IndexedArray = require('ui/IndexedArray');

// this is generally a data-structure that IndexedArray is good for managing
var users = [
let users = [
{ name: 'John', id: 69, username: 'beast', group: 'admins' },
{ name: 'Anon', id: 0, username: 'shhhh', group: 'secret' },
{ name: 'Fern', id: 42, username: 'kitty', group: 'editor' },
Expand Down Expand Up @@ -43,7 +43,7 @@ describe('IndexedArray', function () {

describe('Indexing', function () {
it('provides the initial set', function () {
var reg = new IndexedArray({
let reg = new IndexedArray({
initialSet: [1, 2, 3]
});

Expand All @@ -55,7 +55,7 @@ describe('IndexedArray', function () {
});

it('indexes the initial set', function () {
var reg = new IndexedArray({
let reg = new IndexedArray({
index: ['username'],
initialSet: users
});
Expand All @@ -66,11 +66,11 @@ describe('IndexedArray', function () {

it('updates indices after values are added', function () {
// split up the user list, and add it in chunks
var firstUser = users.slice(0, 1).pop();
var otherUsers = users.slice(1);
let firstUser = users.slice(0, 1).pop();
let otherUsers = users.slice(1);

// start off with all but the first
var reg = new IndexedArray({
let reg = new IndexedArray({
group: ['group'],
order: ['id'],
initialSet: otherUsers
Expand All @@ -86,7 +86,7 @@ describe('IndexedArray', function () {

it('updates indices after values are removed', function () {
// start off with all
var reg = new IndexedArray({
let reg = new IndexedArray({
group: ['group'],
order: ['id'],
initialSet: users
Expand All @@ -95,18 +95,18 @@ describe('IndexedArray', function () {
// remove the last
reg.pop();

var expectedCount = users.length - 1;
let expectedCount = users.length - 1;
// indexed lists should be updated
expect(reg).to.have.length(expectedCount);

var sumOfGroups = _.reduce(reg.byGroup, function (note, group) {
let sumOfGroups = _.reduce(reg.byGroup, function (note, group) {
return note + group.length;
}, 0);
expect(sumOfGroups).to.eql(expectedCount);
});

it('removes items based on a predicate', function () {
var reg = new IndexedArray({
let reg = new IndexedArray({
group: ['group'],
order: ['id'],
initialSet: users
Expand All @@ -120,26 +120,26 @@ describe('IndexedArray', function () {
});

it('updates indices after values are re-ordered', function () {
var rawUsers = users.slice(0);
let rawUsers = users.slice(0);

// collect and shuffle the ids available
var ids = [];
let ids = [];
_.times(rawUsers.length, function (i) { ids.push(i); });
ids = _.shuffle(ids);

// move something here
var toI = ids.shift();
let toI = ids.shift();
// from here
var fromI = ids.shift();
let fromI = ids.shift();
// do the move
var move = function (arr) { arr.splice(toI, 0, arr.splice(fromI, 1)[0]); };
let move = function (arr) { arr.splice(toI, 0, arr.splice(fromI, 1)[0]); };

var reg = new IndexedArray({
let reg = new IndexedArray({
index: ['username'],
initialSet: rawUsers
});

var index = reg.byUsername;
let index = reg.byUsername;

move(reg);

Expand Down
16 changes: 8 additions & 8 deletions src/ui/public/IndexedArray/__tests__/inflector.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
var inflector = require('ui/IndexedArray/inflector');
var expect = require('expect.js');
let inflector = require('ui/IndexedArray/inflector');
let expect = require('expect.js');

describe('IndexedArray Inflector', function () {
it('returns a function', function () {
var getter = inflector();
let getter = inflector();
expect(getter).to.be.a('function');
});

describe('fn', function () {
it('prepends a prefix', function () {
var inflect = inflector('my');
let inflect = inflector('my');

expect(inflect('Family')).to.be('myFamily');
expect(inflect('family')).to.be('myFamily');
expect(inflect('fAmIlY')).to.be('myFAmIlY');
});

it('adds both a prefix and suffix', function () {
var inflect = inflector('foo', 'Bar');
let inflect = inflector('foo', 'Bar');

expect(inflect('box')).to.be('fooBoxBar');
expect(inflect('box.car.MAX')).to.be('fooBoxCarMaxBar');
expect(inflect('BaZzY')).to.be('fooBaZzYBar');
});

it('ignores prefix if it is already at the end of the inflected string', function () {
var inflect = inflector('foo', 'Bar');
let inflect = inflector('foo', 'Bar');
expect(inflect('fooBox')).to.be('fooBoxBar');
expect(inflect('FooBox')).to.be('FooBoxBar');
});

it('ignores postfix if it is already at the end of the inflected string', function () {
var inflect = inflector('foo', 'Bar');
let inflect = inflector('foo', 'Bar');
expect(inflect('bar')).to.be('fooBar');
expect(inflect('showBoxBar')).to.be('fooShowBoxBar');
});

it('works with "name"', function () {
var inflect = inflector('in', 'Order');
let inflect = inflector('in', 'Order');
expect(inflect('name')).to.be('inNameOrder');
});
});
Expand Down
Loading

0 comments on commit 84726c3

Please sign in to comment.