refactor(core): rework media config as a plain getter/setter (#1697)

This commit is contained in:
Wesley Luyten
2026-06-17 17:58:52 -07:00
committed by GitHub
parent 1b31f3e8d7
commit b32b80e55b
8 changed files with 195 additions and 108 deletions
@@ -1,3 +1,4 @@
import { getComponents } from '@videojs/core/dom/media/media-host';
import { MuxData } from '@videojs/core/dom/media/mux';
import { afterEach, describe, expect, it } from 'vitest';
import { MuxVideo } from '../mux-video';
@@ -17,18 +18,31 @@ afterEach(() => {
});
describe('MuxVideo', () => {
it('exposes the mux data component config on element config', () => {
it('constructs the mux data component with the player software name', () => {
const el = createMuxVideo();
const muxData = getComponents(el.host).get(MuxData);
expect(muxData).toBeInstanceOf(MuxData);
expect(muxData?.playerSoftwareName).toBe('mux-video');
});
it('exposes the element config as plain values, not the component instance', () => {
const el = createMuxVideo();
expect(el.config.muxData).toBeInstanceOf(MuxData);
expect((el.config.muxData as MuxData).playerSoftwareName).toBe('mux-video');
// `config` reflects exactly what was set — a plain namespace bag.
expect(el.config.muxData).toEqual({ MuxDataSdk: undefined });
expect(el.config.muxData).not.toBeInstanceOf(MuxData);
});
it('routes component config writes to the component', () => {
const el = createMuxVideo();
const muxData = getComponents(el.host).get(MuxData);
el.config = { muxData: { envKey: 'test-key' } };
// The write reached the live component...
expect(muxData?.envKey).toBe('test-key');
// ...and config reads back the plain value, not the instance.
expect(el.config.muxData?.envKey).toBe('test-key');
expect(el.hasAttribute('config')).toBe(false);
});