Skip to content

Commit

Permalink
fix: Replace Object.values with ponyfill (#8267)
Browse files Browse the repository at this point in the history
Unpin Firefox in BrowserStack tests, which fixes test failures as well.

Fixes #8266.
  • Loading branch information
dzianis-dashkevich authored May 11, 2023
1 parent 1491d71 commit 866ef24
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/js/title-bar.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -39,7 +40,7 @@ class TitleBar extends Component {

return Dom.createEl('div', {
className: 'vjs-title-bar'
}, {}, Object.values(this.els));
}, {}, Obj.values(this.els));
}

/**
Expand Down
20 changes: 20 additions & 0 deletions src/js/utils/obj.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown>} - 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.
Expand Down
7 changes: 0 additions & 7 deletions test/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
/*
Expand Down
26 changes: 26 additions & 0 deletions test/unit/utils/obj.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});

0 comments on commit 866ef24

Please sign in to comment.