Skip to content

Commit 286aa65

Browse files
authored
chore: restore backward compatibility for Cloudinary.new() (#1011)
* chore: restore backward-compatibility with old SDK * chore: improve test
1 parent 459f0aa commit 286aa65

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

src/index.umd.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ export const player = (id, playerOptions = {}, ready) =>
1818
export const players = (selector, playerOptions, ready) =>
1919
createMultiplePlayers(selector, playerOptions, ready, player);
2020

21-
const cloudinaryVideoPlayerLegacyConfig = () => {
21+
const cloudinaryVideoPlayerLegacyConfig = (instanceConfig = {}) => {
2222
console.warn(
2323
'Cloudinary.new() is deprecated and will be removed. Please use cloudinary.videoPlayer() instead.'
2424
);
25+
const mergeOpts = (callOpts = {}) => Object.assign({}, instanceConfig, callOpts);
2526
return {
26-
videoPlayer,
27-
videoPlayers
27+
videoPlayer: (id, playerOptions = {}, ready) =>
28+
createVideoPlayer(id, mergeOpts(playerOptions), ready),
29+
videoPlayers: (selector, playerOptions = {}, ready) =>
30+
createMultipleSync(selector, mergeOpts(playerOptions), ready, videoPlayer)
2831
};
2932
};
3033

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2+
3+
vi.mock('~/assets/styles/main.scss', () => ({}));
4+
5+
// Default export is the object returned by setupCloudinaryGlobal({ ... }) in src/index.umd.js
6+
import cloudinary from '../../src/index.umd.js';
7+
8+
describe('Cloudinary.new() legacy instance config', () => {
9+
let warnSpy;
10+
11+
beforeEach(() => {
12+
warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
13+
});
14+
15+
afterEach(() => {
16+
warnSpy.mockRestore();
17+
});
18+
19+
it('merges cloud_name from instance into per-call videoPlayer options', () => {
20+
vi.useFakeTimers();
21+
document.body.innerHTML = '<div><video id="legacy-new-test"/></div>';
22+
23+
const cld = cloudinary.Cloudinary.new({
24+
cloud_name: 'demo',
25+
secure: true,
26+
private_cdn: false
27+
});
28+
29+
const vp = cld.videoPlayer('legacy-new-test', { controls: true });
30+
const conf = vp.videojs.cloudinary.cloudinaryConfig();
31+
expect(conf.cloud_name).toEqual('demo');
32+
});
33+
34+
it('per-call options override instance config', () => {
35+
vi.useFakeTimers();
36+
document.body.innerHTML = '<div><video id="legacy-new-override"/></div>';
37+
38+
const cld = cloudinary.Cloudinary.new({ cloud_name: 'from-instance' });
39+
const vp = cld.videoPlayer('legacy-new-override', { cloud_name: 'from-call' });
40+
const conf = vp.videojs.cloudinary.cloudinaryConfig();
41+
expect(conf.cloud_name).toEqual('from-call');
42+
});
43+
});

0 commit comments

Comments
 (0)