From 866ef24b797320c397893acef37219a53aa7496d Mon Sep 17 00:00:00 2001 From: Dzianis Dashkevich <98566601+dzianis-dashkevich@users.noreply.github.com> Date: Thu, 11 May 2023 18:57:13 -0400 Subject: [PATCH] fix: Replace Object.values with ponyfill (#8267) Unpin Firefox in BrowserStack tests, which fixes test failures as well. Fixes #8266. --- src/js/title-bar.js | 3 ++- src/js/utils/obj.js | 20 ++++++++++++++++++++ test/karma.conf.js | 7 ------- test/unit/utils/obj.test.js | 26 ++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/js/title-bar.js b/src/js/title-bar.js index ae5b21d42b..1b59cb840f 100644 --- a/src/js/title-bar.js +++ b/src/js/title-bar.js @@ -1,6 +1,7 @@ import Component from './component'; import * as Dom from './utils/dom'; import * as Guid from './utils/guid'; +import * as Obj from './utils/obj'; /** * Displays an element over the player which contains an optional title and @@ -39,7 +40,7 @@ class TitleBar extends Component { return Dom.createEl('div', { className: 'vjs-title-bar' - }, {}, Object.values(this.els)); + }, {}, Obj.values(this.els)); } /** diff --git a/src/js/utils/obj.js b/src/js/utils/obj.js index 09a9d4fb45..64e23df186 100644 --- a/src/js/utils/obj.js +++ b/src/js/utils/obj.js @@ -148,6 +148,26 @@ export function merge(...sources) { return result; } +/** + * Returns an array of values for a given object + * + * @param {Object} source - target object + * @return {Array} - object values + */ +export function values(source = {}) { + const result = []; + + for (const key in source) { + if (source.hasOwnProperty(key)) { + const value = source[key]; + + result.push(value); + } + } + + return result; +} + /** * Object.defineProperty but "lazy", which means that the value is only set after * it is retrieved the first time, rather than being set right away. diff --git a/test/karma.conf.js b/test/karma.conf.js index 5cd796f02f..15e61d9add 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -50,13 +50,6 @@ module.exports = function(config) { config.browserStack.project = 'Video.js'; - // pin Browserstack Firefox version to 64 - /* eslint-disable camelcase */ - if (config.customLaunchers && config.customLaunchers.bsFirefox) { - config.customLaunchers.bsFirefox.browser_version = '64.0'; - } - /* eslint-enable camelcase */ - // uncomment the section below to re-enable all browserstack video recording // it is off by default because it slows the build /* diff --git a/test/unit/utils/obj.test.js b/test/unit/utils/obj.test.js index f412e9cf02..f8aa1c6e0f 100644 --- a/test/unit/utils/obj.test.js +++ b/test/unit/utils/obj.test.js @@ -176,4 +176,30 @@ QUnit.module('utils/obj', function() { assert.strictEqual(b, 2, 'the value was retrieved correctly'); assert.strictEqual(descriptor.value, 2, 'descriptor has a value'); }); + + QUnit.module('values', () => { + QUnit.test('returns an array of values for a given object', (assert) => { + const source = { a: 1, b: 2, c: 3 }; + const expectedResult = [1, 2, 3]; + + assert.deepEqual(Obj.values(source), expectedResult, 'All values are extracted correctly'); + }); + + QUnit.test('returns an empty array for an empty object', (assert) => { + const source = {}; + const expectedResult = []; + + assert.deepEqual(Obj.values(source), expectedResult, 'Empty array is returned for an empty object'); + }); + + QUnit.test('ignores prototype properties', (assert) => { + const source = Object.create({ a: 1 }); + + source.b = 2; + + const expectedResult = [2]; + + assert.deepEqual(Obj.values(source), expectedResult, 'Only own properties are included in the result'); + }); + }); });