Skip to content

Commit 35540fa

Browse files
committed
Fix tests
1 parent 48e46e4 commit 35540fa

File tree

12 files changed

+38
-117
lines changed

12 files changed

+38
-117
lines changed

package-lock.json

Lines changed: 16 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"@types/jest": "^28.1.2",
6060
"@types/react": "^18.2.0 || ^19.0.0",
6161
"@types/react-native": "0.72.0",
62+
"@types/react-test-renderer": "^19.0.0",
6263
"babel-jest": "^29.5.0",
6364
"del-cli": "^5.0.0",
6465
"eslint": "^8.4.1",
@@ -73,7 +74,7 @@
7374
"react-native-builder-bob": "^0.20.0",
7475
"react-test-renderer": "19.0.0",
7576
"release-it": "^15.0.0",
76-
"typescript": "^4.9.5"
77+
"typescript": "^5.3.0"
7778
},
7879
"dependencies": {
7980
"@cloudinary/url-gen": "^1.10.0",

src/AdvancedVideo.tsx

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ import type { CloudinaryVideo } from '@cloudinary/url-gen';
44
import { SDKAnalyticsConstants } from './internal/SDKAnalyticsConstants';
55
import { VideoPlayerAdapter, VideoPlayerRef, VideoPlayerFactory } from './adapters';
66

7-
// Log module import (but not during tests)
8-
if (process.env.NODE_ENV !== 'test' && typeof jest === 'undefined') {
9-
console.log('🚀 [Cloudinary] AdvancedVideo module imported successfully!');
10-
}
11-
127
interface AdvancedVideoProps {
138
videoUrl?: string;
149
cldVideo?: CloudinaryVideo;
@@ -46,15 +41,6 @@ class AdvancedVideo extends Component<AdvancedVideoProps, AdvancedVideoState> {
4641

4742
const videoAdapter = VideoPlayerFactory.getAvailableAdapter();
4843

49-
// Log detailed information about video adapter selection
50-
if (process.env.NODE_ENV !== 'test' && typeof jest === 'undefined') {
51-
console.log('[Cloudinary AdvancedVideo] Initializing video component...');
52-
const availableAdapters = VideoPlayerFactory.getAvailableAdapters();
53-
console.log(`[Cloudinary AdvancedVideo] Available adapters:`, availableAdapters);
54-
console.log(`[Cloudinary AdvancedVideo] 🎥 Selected video adapter: ${videoAdapter.getAdapterName()}`);
55-
console.log(`[Cloudinary AdvancedVideo] You are using: ${videoAdapter.getAdapterName() === 'expo-video' ? '📱 EXPO-VIDEO (newer)' : videoAdapter.getAdapterName() === 'expo-av' ? '📱 EXPO-AV (legacy)' : '⚠️ FALLBACK'}`);
56-
}
57-
5844
this.state = {
5945
analyticsConnector: null,
6046
previousStatus: undefined,
@@ -211,47 +197,23 @@ class AdvancedVideo extends Component<AdvancedVideoProps, AdvancedVideoState> {
211197
}
212198

213199
try {
214-
if (process.env.NODE_ENV !== 'test' && typeof jest === 'undefined') {
215-
console.log(`[Cloudinary AdvancedVideo] 🎬 Rendering video with ${this.state.videoAdapter.getAdapterName()} adapter`);
216-
}
217200
const videoElement = this.state.videoAdapter.renderVideo({
218201
videoUri,
219202
style: this.props.videoStyle,
220203
onPlaybackStatusUpdate: this.onPlaybackStatusUpdate,
221-
onLoadStart: () => {
222-
if (process.env.NODE_ENV !== 'test' && typeof jest === 'undefined') {
223-
console.log(`[Cloudinary AdvancedVideo] 📡 Video load started using ${this.state.videoAdapter.getAdapterName()}`);
224-
}
225-
},
226-
onLoad: () => {
227-
if (process.env.NODE_ENV !== 'test' && typeof jest === 'undefined') {
228-
console.log(`[Cloudinary AdvancedVideo] ✅ Video loaded successfully using ${this.state.videoAdapter.getAdapterName()}`);
229-
}
230-
},
231-
onError: (error: any) => {
232-
if (process.env.NODE_ENV !== 'test' && typeof jest === 'undefined') {
233-
console.log(`[Cloudinary AdvancedVideo] ❌ Video error with ${this.state.videoAdapter.getAdapterName()}:`, error);
234-
}
235-
},
204+
onLoadStart: () => {},
205+
onLoad: () => {},
206+
onError: (_error: any) => {},
236207
}, this.videoRef);
237208

238-
if (process.env.NODE_ENV !== 'test' && typeof jest === 'undefined') {
239-
console.log(`[Cloudinary AdvancedVideo] ✅ Video component successfully rendered with ${this.state.videoAdapter.getAdapterName()}`);
240-
}
241209
return videoElement;
242210
} catch (error) {
243211
// If the adapter fails, fall back to a fallback adapter
244-
if (process.env.NODE_ENV !== 'test' && typeof jest === 'undefined') {
245-
console.log(`[Cloudinary AdvancedVideo] ❌ ${this.state.videoAdapter.getAdapterName()} adapter failed, falling back to fallback adapter:`, error instanceof Error ? error.message : 'Unknown error');
246-
}
247212
const { FallbackVideoAdapter } = require('./adapters/FallbackVideoAdapter');
248213
const fallbackAdapter = new FallbackVideoAdapter(
249214
error instanceof Error ? `Video Error: ${error.message}` : 'Unknown video error'
250215
);
251216

252-
if (process.env.NODE_ENV !== 'test' && typeof jest === 'undefined') {
253-
console.log(`[Cloudinary AdvancedVideo] 🔄 Using fallback adapter to render video`);
254-
}
255217
return fallbackAdapter.renderVideo({
256218
videoUri,
257219
style: this.props.videoStyle,

src/__tests__/analytics.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import React from 'react';
77
jest.mock('react-native', () => {
88
const mockReact = require('react');
99
return {
10-
Image: ({ source, testID, ...props }) => mockReact.createElement('Image', { source, testID, ...props }),
10+
Image: ({ source, testID, ...props }: { source: any; testID?: string; [key: string]: any }) => mockReact.createElement('Image', { source, testID, ...props }),
1111
Platform: { OS: 'ios' },
1212
};
1313
});
@@ -38,13 +38,13 @@ describe('analytics', () => {
3838
it('creates a url with analytics', () => {
3939
const componentImage = new CloudinaryImage('sample', { cloudName: 'demo' });
4040

41-
let component;
41+
let component: any;
4242
act(() => {
4343
component = create(
4444
<AdvancedImage cldImg={componentImage} testID="cld-image" />
4545
);
4646
});
47-
const tree = component.toJSON();
47+
const tree = component!.toJSON();
4848

4949
// Check that the URL contains analytics parameters
5050
const actualUrl = tree.props.source.uri;

src/__tests__/index.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { create, act } from 'react-test-renderer';
77
jest.mock('react-native', () => {
88
const mockReact = require('react');
99
return {
10-
Image: ({ source, testID, ...props }) => mockReact.createElement('Image', { source, testID, ...props }),
10+
Image: ({ source, testID, ...props }: { source: any; testID?: string; [key: string]: any }) => mockReact.createElement('Image', { source, testID, ...props }),
1111
Platform: { OS: 'ios' },
1212
};
1313
});
@@ -25,27 +25,27 @@ jest.mock('../internal/SDKAnalyticsConstants', () => ({
2525
describe('AdvancedImage', () => {
2626
it('should render an Image with the correct URI', () => {
2727
const cldImg = new CloudinaryImage('sample', { cloudName: 'demo' }, { analytics: false });
28-
let component;
28+
let component: any;
2929

3030
act(() => {
3131
component = create(<AdvancedImage cldImg={cldImg} />);
3232
});
3333

34-
const tree = component.toJSON();
34+
const tree = component!.toJSON();
3535

3636
expect(tree.type).toBe('Image');
3737
expect(tree.props.source.uri).toBe(cldImg.toURL());
3838
});
3939

4040
it('should forward any other props to the Image', () => {
4141
const cldImg = new CloudinaryImage('sample', { cloudName: 'demo' }, { analytics: false });
42-
let component;
42+
let component: any;
4343

4444
act(() => {
4545
component = create(<AdvancedImage cldImg={cldImg} testID="my-image" style={{ width: 100 }} />);
4646
});
4747

48-
const tree = component.toJSON();
48+
const tree = component!.toJSON();
4949

5050
expect(tree.props.testID).toBe('my-image');
5151
expect(tree.props.style).toEqual({ width: 100 });

src/adapters/ExpoAVVideoAdapter.tsx

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import React, { ReactElement, RefObject } from 'react';
22
import { VideoPlayerAdapter, VideoPlayerProps, VideoPlayerRef, VideoPlayerType } from './types';
33

4-
// Log module import (but not during tests)
5-
if (process.env.NODE_ENV !== 'test' && typeof jest === 'undefined') {
6-
console.log('📼 [Cloudinary] ExpoAVVideoAdapter module imported!');
7-
}
8-
94
export class ExpoAVVideoAdapter implements VideoPlayerAdapter {
105
private expoAVModule: any = null;
116

@@ -16,13 +11,7 @@ export class ExpoAVVideoAdapter implements VideoPlayerAdapter {
1611
private loadExpoAV(): void {
1712
try {
1813
this.expoAVModule = require('expo-av');
19-
if (process.env.NODE_ENV !== 'test' && typeof jest === 'undefined') {
20-
console.log('[Cloudinary ExpoAVVideoAdapter] Successfully loaded expo-av module');
21-
}
2214
} catch (error) {
23-
if (process.env.NODE_ENV !== 'test' && typeof jest === 'undefined') {
24-
console.log('[Cloudinary ExpoAVVideoAdapter] Failed to load expo-av module:', (error as Error)?.message || 'Unknown error');
25-
}
2615
this.expoAVModule = null;
2716
}
2817
}
@@ -32,10 +21,6 @@ export class ExpoAVVideoAdapter implements VideoPlayerAdapter {
3221
const hasVideo = !!(this.expoAVModule && this.expoAVModule.Video);
3322
const isAvailable = hasModule && hasVideo;
3423

35-
if (process.env.NODE_ENV !== 'test' && typeof jest === 'undefined') {
36-
console.log(`[Cloudinary ExpoAVVideoAdapter] Availability check: module=${hasModule}, Video=${hasVideo}, available=${isAvailable}`);
37-
}
38-
3924
return isAvailable;
4025
}
4126

src/adapters/ExpoVideoAdapter.tsx

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import React, { ReactElement, RefObject } from 'react';
22
import { VideoPlayerAdapter, VideoPlayerProps, VideoPlayerRef, VideoPlayerType } from './types';
33

4-
// Log module import (but not during tests)
5-
if (process.env.NODE_ENV !== 'test' && typeof jest === 'undefined') {
6-
console.log('📱 [Cloudinary] ExpoVideoAdapter module imported!');
7-
}
8-
94
export class ExpoVideoAdapter implements VideoPlayerAdapter {
105
private expoVideoModule: any = null;
116
private videoPlayer: any = null;
@@ -17,13 +12,7 @@ export class ExpoVideoAdapter implements VideoPlayerAdapter {
1712
private loadExpoVideo(): void {
1813
try {
1914
this.expoVideoModule = require('expo-video');
20-
if (process.env.NODE_ENV !== 'test' && typeof jest === 'undefined') {
21-
console.log('[Cloudinary ExpoVideoAdapter] Successfully loaded expo-video module');
22-
}
2315
} catch (error) {
24-
if (process.env.NODE_ENV !== 'test' && typeof jest === 'undefined') {
25-
console.log('[Cloudinary ExpoVideoAdapter] Failed to load expo-video module:', (error as Error)?.message || 'Unknown error');
26-
}
2716
this.expoVideoModule = null;
2817
}
2918
}
@@ -34,10 +23,6 @@ export class ExpoVideoAdapter implements VideoPlayerAdapter {
3423
const hasCreatePlayer = !!(this.expoVideoModule && this.expoVideoModule.createVideoPlayer);
3524
const isAvailable = hasModule && hasVideoView && hasCreatePlayer;
3625

37-
if (process.env.NODE_ENV !== 'test' && typeof jest === 'undefined') {
38-
console.log(`[Cloudinary ExpoVideoAdapter] Availability check: module=${hasModule}, VideoView=${hasVideoView}, createVideoPlayer=${hasCreatePlayer}, available=${isAvailable}`);
39-
}
40-
4126
return isAvailable;
4227
}
4328

src/adapters/VideoPlayerFactory.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ import { ExpoVideoAdapter } from './ExpoVideoAdapter';
33
import { ExpoAVVideoAdapter } from './ExpoAVVideoAdapter';
44
import { FallbackVideoAdapter } from './FallbackVideoAdapter';
55

6-
// Log module import (but not during tests)
7-
if (process.env.NODE_ENV !== 'test' && typeof jest === 'undefined') {
8-
console.log('🏭 [Cloudinary] VideoPlayerFactory module imported successfully!');
9-
}
10-
116
// Re-export types for external use
127
export { VideoPlayerType } from './types';
138

@@ -32,31 +27,17 @@ export class VideoPlayerFactory {
3227
static getAvailableAdapter(): VideoPlayerAdapter {
3328
this.initializeAdapters();
3429

35-
if (process.env.NODE_ENV !== 'test' && typeof jest === 'undefined') {
36-
console.log('[Cloudinary VideoPlayerFactory] Checking available video adapters...');
37-
}
38-
3930
// Find the first available adapter
4031
for (const adapter of this.adapters) {
4132
const adapterName = adapter.getAdapterName();
4233
const isAvailable = adapter.isAvailable();
4334

44-
if (process.env.NODE_ENV !== 'test' && typeof jest === 'undefined') {
45-
console.log(`[Cloudinary VideoPlayerFactory] Checking ${adapterName}: ${isAvailable ? 'AVAILABLE' : 'NOT AVAILABLE'}`);
46-
}
47-
4835
if (isAvailable) {
49-
if (process.env.NODE_ENV !== 'test' && typeof jest === 'undefined') {
50-
console.log(`[Cloudinary VideoPlayerFactory] ✅ Selected adapter: ${adapterName}`);
51-
}
5236
return adapter;
5337
}
5438
}
5539

5640
// If no adapter is available, return fallback
57-
if (process.env.NODE_ENV !== 'test' && typeof jest === 'undefined') {
58-
console.log('[Cloudinary VideoPlayerFactory] ⚠️ No video adapters available, using fallback');
59-
}
6041
return new FallbackVideoAdapter('No video player library found. Install expo-video or expo-av.');
6142
}
6243

src/index.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
// Log package import (but not during tests)
2-
if (process.env.NODE_ENV !== 'test' && typeof jest === 'undefined') {
3-
console.log('📦 [Cloudinary] cloudinary-react-native package imported!');
4-
}
5-
61
import AdvancedImage from "./AdvancedImage";
72
import AdvancedVideo from './AdvancedVideo';
83
export { upload, unsignedUpload, uploadBase64, rename, explicit } from "./api/upload";

src/widgets/video/analytics/cloudinary-analytics-react-native.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,11 @@ export const connectCloudinaryAnalytics = (videoRef, mainOptions = {}) => {
270270
},
271271
};
272272
} catch (error) {
273-
console.warn('Failed to create minimal tracking session:', error);
274273
return;
275274
}
276275
}
277276

278277
if (!videoTrackingSession || !videoTrackingSession.eventCollector) {
279-
console.warn('No active analytics tracking session. Start tracking first.');
280278
return;
281279
}
282280

@@ -293,8 +291,6 @@ export const connectCloudinaryAnalytics = (videoRef, mainOptions = {}) => {
293291
timestamp: Date.now()
294292
});
295293
} catch (error) {
296-
console.warn('Failed to add custom event:', error);
297-
console.warn('Error details:', error.message);
298294
}
299295
};
300296

0 commit comments

Comments
 (0)