diff --git a/.eslintrc-hound.json b/.eslintrc-hound.json index 3b00a31332..1482baee37 100644 --- a/.eslintrc-hound.json +++ b/.eslintrc-hound.json @@ -19,7 +19,8 @@ "webkitSpeechRecognition": false }, "env": { - "browser": true + "browser": true, + "mocha": true }, "rules": { "class-methods-use-this": 0, diff --git a/.eslintrc.json b/.eslintrc.json index 6b3bb5e959..7861c7aa9e 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -3,5 +3,8 @@ "plugins": [ "html", "react" - ] + ], + "env": { + "browser": true + } } diff --git a/test-mocha/.eslintrc b/test-mocha/.eslintrc new file mode 100644 index 0000000000..7eeefc33b6 --- /dev/null +++ b/test-mocha/.eslintrc @@ -0,0 +1,5 @@ +{ + "env": { + "mocha": true + } +} diff --git a/test-mocha/common/util/attribute_class_names_test.js b/test-mocha/common/util/attribute_class_names_test.js index 3088cd12c8..9aaeea1940 100644 --- a/test-mocha/common/util/attribute_class_names_test.js +++ b/test-mocha/common/util/attribute_class_names_test.js @@ -2,17 +2,18 @@ import attributeClassNames from '../../../js/common/util/attribute_class_names'; const assert = require('assert'); -describe('attributeClassNames', function() { +describe('attributeClassNames', () => { const attrs = ['mock_attr1', 'mock_attr2']; - it('Skips null states', function() { + it('Skips null states', () => { const stateObj = null; assert.strictEqual( attributeClassNames(stateObj, attrs), - ''); + '' + ); }); - it('Matches no attrbutes', function() { + it('Matches no attrbutes', () => { const stateObj = { attributes: { other_attr_1: 1, @@ -21,10 +22,11 @@ describe('attributeClassNames', function() { }; assert.strictEqual( attributeClassNames(stateObj, attrs), - ''); + '' + ); }); - it('Matches one attrbute', function() { + it('Matches one attrbute', () => { const stateObj = { attributes: { other_attr_1: 1, @@ -34,10 +36,11 @@ describe('attributeClassNames', function() { }; assert.strictEqual( attributeClassNames(stateObj, attrs), - 'has-mock_attr1'); + 'has-mock_attr1' + ); }); - it('Matches two attrbutes', function() { + it('Matches two attrbutes', () => { const stateObj = { attributes: { other_attr_1: 1, @@ -48,6 +51,7 @@ describe('attributeClassNames', function() { }; assert.strictEqual( attributeClassNames(stateObj, attrs), - 'has-mock_attr1 has-mock_attr2'); + 'has-mock_attr1 has-mock_attr2' + ); }); }); diff --git a/test-mocha/common/util/compute_domain.js b/test-mocha/common/util/compute_domain.js index e26811b242..44f55bd61e 100644 --- a/test-mocha/common/util/compute_domain.js +++ b/test-mocha/common/util/compute_domain.js @@ -2,8 +2,8 @@ import computeDomain from '../../../js/common/util/compute_domain'; const assert = require('assert'); -describe('computeDomain', function() { - it('Detects sensor domain', function() { +describe('computeDomain', () => { + it('Detects sensor domain', () => { const stateObj = { entity_id: 'sensor.test', }; diff --git a/test-mocha/common/util/compute_state_display.js b/test-mocha/common/util/compute_state_display.js index a49a0e3848..00596e0742 100644 --- a/test-mocha/common/util/compute_state_display.js +++ b/test-mocha/common/util/compute_state_display.js @@ -2,13 +2,13 @@ import computeStateDisplay from '../../../js/common/util/compute_state_display'; const assert = require('assert'); -describe('computeStateDisplay', function() { - const haLocalize = function(namespace, message, ...args) { +describe('computeStateDisplay', () => { + const haLocalize = function (namespace, message, ...args) { // Mock Localize function for testing return namespace + '.' + message + (args.length ? ': ' + args.join(',') : ''); }; - it('Localizes binary sensor defaults', function() { + it('Localizes binary sensor defaults', () => { const stateObj = { entity_id: 'binary_sensor.test', state: 'off', @@ -18,7 +18,7 @@ describe('computeStateDisplay', function() { assert.strictEqual(computeStateDisplay(haLocalize, stateObj, 'en'), 'state.binary_sensor.default.off'); }); - it('Localizes binary sensor device class', function() { + it('Localizes binary sensor device class', () => { const stateObj = { entity_id: 'binary_sensor.test', state: 'off', @@ -29,8 +29,8 @@ describe('computeStateDisplay', function() { assert.strictEqual(computeStateDisplay(haLocalize, stateObj, 'en'), 'state.binary_sensor.moisture.off'); }); - it('Localizes binary sensor invalid device class', function() { - const altHaLocalize = function(namespace, message, ...args) { + it('Localizes binary sensor invalid device class', () => { + const altHaLocalize = function (namespace, message, ...args) { if (namespace === 'state.binary_sensor.invalid_device_class') return null; return haLocalize(namespace, message, ...args); }; @@ -44,7 +44,7 @@ describe('computeStateDisplay', function() { assert.strictEqual(computeStateDisplay(altHaLocalize, stateObj, 'en'), 'state.binary_sensor.default.off'); }); - it('Localizes sensor value with units', function() { + it('Localizes sensor value with units', () => { const stateObj = { entity_id: 'sensor.test', state: '123', @@ -55,7 +55,7 @@ describe('computeStateDisplay', function() { assert.strictEqual(computeStateDisplay(haLocalize, stateObj, 'en'), '123 m'); }); - it('Localizes input_datetime with full date time', function() { + it('Localizes input_datetime with full date time', () => { const stateObj = { entity_id: 'input_datetime.test', state: '123', @@ -73,7 +73,7 @@ describe('computeStateDisplay', function() { assert.strictEqual(computeStateDisplay(haLocalize, stateObj, 'en'), 'November 18, 2017, 11:12 AM'); }); - it('Localizes input_datetime with date', function() { + it('Localizes input_datetime with date', () => { const stateObj = { entity_id: 'input_datetime.test', state: '123', @@ -91,7 +91,7 @@ describe('computeStateDisplay', function() { assert.strictEqual(computeStateDisplay(haLocalize, stateObj, 'en'), 'November 18, 2017'); }); - it('Localizes input_datetime with time', function() { + it('Localizes input_datetime with time', () => { const stateObj = { entity_id: 'input_datetime.test', state: '123', @@ -109,7 +109,7 @@ describe('computeStateDisplay', function() { assert.strictEqual(computeStateDisplay(haLocalize, stateObj, 'en'), '11:12 AM'); }); - it('Localizes zwave ready', function() { + it('Localizes zwave ready', () => { const stateObj = { entity_id: 'zwave.test', state: 'ready', @@ -120,7 +120,7 @@ describe('computeStateDisplay', function() { assert.strictEqual(computeStateDisplay(haLocalize, stateObj, 'en'), 'state.zwave.default.ready'); }); - it('Localizes zwave initializing', function() { + it('Localizes zwave initializing', () => { const stateObj = { entity_id: 'zwave.test', state: 'initializing', @@ -131,7 +131,7 @@ describe('computeStateDisplay', function() { assert.strictEqual(computeStateDisplay(haLocalize, stateObj, 'en'), 'state.zwave.query_stage.initializing: query_stage,Probe'); }); - it('Localizes cover open', function() { + it('Localizes cover open', () => { const stateObj = { entity_id: 'cover.test', state: 'open', @@ -141,8 +141,8 @@ describe('computeStateDisplay', function() { assert.strictEqual(computeStateDisplay(haLocalize, stateObj, 'en'), 'state.cover.open'); }); - it('Localizes unavailable', function() { - const altHaLocalize = function(namespace, message, ...args) { + it('Localizes unavailable', () => { + const altHaLocalize = function (namespace, message, ...args) { if (namespace === 'state.sensor') return null; return haLocalize(namespace, message, ...args); }; @@ -155,8 +155,8 @@ describe('computeStateDisplay', function() { assert.strictEqual(computeStateDisplay(altHaLocalize, stateObj, 'en'), 'state.default.unavailable'); }); - it('Localizes custom state', function() { - const altHaLocalize = function(namespace, message, ...args) { + it('Localizes custom state', () => { + const altHaLocalize = function (namespace, message, ...args) { // No matches can be found return null; }; @@ -169,7 +169,7 @@ describe('computeStateDisplay', function() { assert.strictEqual(computeStateDisplay(altHaLocalize, stateObj, 'en'), 'My Custom State'); }); - it('Only calculates state display once per immutable state object', function() { + it('Only calculates state display once per immutable state object', () => { const stateObj = { entity_id: 'cover.test', state: 'open', diff --git a/test-mocha/common/util/format_date.js b/test-mocha/common/util/format_date.js index d681a58b37..b1a1df09ce 100644 --- a/test-mocha/common/util/format_date.js +++ b/test-mocha/common/util/format_date.js @@ -2,19 +2,19 @@ import formatDate from '../../../js/common/util/format_date'; const assert = require('assert'); -describe('formatDate', function() { +describe('formatDate', () => { const dateObj = new Date( 2017, 10, 18, 11, 12, 13, 1400, ); - it('Formats English dates', function() { + it('Formats English dates', () => { assert.strictEqual(formatDate(dateObj, 'en'), 'November 18, 2017'); }); // Node only contains intl support for english formats. This test at least ensures // the fallback to a different locale - it('Formats other dates', function() { + it('Formats other dates', () => { assert.strictEqual(formatDate(dateObj, 'fr'), '2017 M11 18'); }); }); diff --git a/test-mocha/common/util/format_date_time.js b/test-mocha/common/util/format_date_time.js index 4b22a54ad1..fe98276f96 100644 --- a/test-mocha/common/util/format_date_time.js +++ b/test-mocha/common/util/format_date_time.js @@ -2,19 +2,19 @@ import formatDateTime from '../../../js/common/util/format_date_time'; const assert = require('assert'); -describe('formatDateTime', function() { +describe('formatDateTime', () => { const dateObj = new Date( 2017, 10, 18, 11, 12, 13, 1400, ); - it('Formats English date times', function() { + it('Formats English date times', () => { assert.strictEqual(formatDateTime(dateObj, 'en'), 'November 18, 2017, 11:12 AM'); }); // Node only contains intl support for english formats. This test at least ensures // the fallback to a different locale - it('Formats other date times', function() { + it('Formats other date times', () => { assert.strictEqual(formatDateTime(dateObj, 'fr'), '2017 M11 18 11:12'); }); }); diff --git a/test-mocha/common/util/format_time.js b/test-mocha/common/util/format_time.js index 66d4c9105b..86c6784dc0 100644 --- a/test-mocha/common/util/format_time.js +++ b/test-mocha/common/util/format_time.js @@ -2,19 +2,19 @@ import formatTime from '../../../js/common/util/format_time'; const assert = require('assert'); -describe('formatTime', function() { +describe('formatTime', () => { const dateObj = new Date( 2017, 10, 18, 11, 12, 13, 1400, ); - it('Formats English times', function() { + it('Formats English times', () => { assert.strictEqual(formatTime(dateObj, 'en'), '11:12 AM'); }); // Node only contains intl support for english formats. This test at least ensures // the fallback to a different locale - it('Formats other times', function() { + it('Formats other times', () => { assert.strictEqual(formatTime(dateObj, 'fr'), '11:12'); }); }); diff --git a/test-mocha/mocha.opts b/test-mocha/mocha.opts index 59a615cb67..a304825765 100644 --- a/test-mocha/mocha.opts +++ b/test-mocha/mocha.opts @@ -1,5 +1,4 @@ --r reify --recursive ---compilers js:babel-core/register +--require reify babel-core/register --timeout 10000 test-mocha