Skip to content

Commit 42f7194

Browse files
MichaelVerdonmikehardy
authored andcommitted
chore(perf): deprecations for v8 API ahead of future major release
1 parent 0e0b725 commit 42f7194

File tree

3 files changed

+90
-8
lines changed

3 files changed

+90
-8
lines changed

packages/app/lib/common/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,15 @@ const mapOfDeprecationReplacements = {
403403
NotificationAndroidVisibility: 'NotificationAndroidVisibility',
404404
},
405405
},
406+
perf: {
407+
default: {
408+
setPerformanceCollectionEnabled: 'initializePerformance()',
409+
newTrace: 'trace()',
410+
newHttpMetric: 'httpMetric()',
411+
newScreenTrace: 'newScreenTrace()',
412+
startScreenTrace: 'startScreenTrace()',
413+
},
414+
},
406415
remoteConfig: {
407416
default: {
408417
activate: 'activate()',

packages/perf/__tests__/perf.test.ts

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { afterAll, beforeAll, describe, expect, it } from '@jest/globals';
1+
import { afterAll, beforeAll, describe, expect, it, beforeEach, jest } from '@jest/globals';
22

33
import perf, {
44
firebase,
@@ -10,6 +10,14 @@ import perf, {
1010
startScreenTrace,
1111
} from '../lib';
1212

13+
import {
14+
createCheckV9Deprecation,
15+
CheckV9DeprecationFunction,
16+
} from '../../app/lib/common/unitTestUtils';
17+
18+
// @ts-ignore test
19+
import FirebaseModule from '../../app/lib/internal/FirebaseModule';
20+
1321
describe('Performance Monitoring', function () {
1422
describe('namespace', function () {
1523
beforeAll(async function () {
@@ -163,4 +171,65 @@ describe('Performance Monitoring', function () {
163171
expect(startScreenTrace).toBeDefined();
164172
});
165173
});
174+
175+
describe('test `console.warn` is called for RNFB v8 API & not called for v9 API', function () {
176+
let perfV9Deprecation: CheckV9DeprecationFunction;
177+
178+
beforeEach(function () {
179+
perfV9Deprecation = createCheckV9Deprecation(['perf']);
180+
181+
// @ts-ignore test
182+
jest.spyOn(FirebaseModule.prototype, 'native', 'get').mockImplementation(() => {
183+
return new Proxy(
184+
{},
185+
{
186+
get: () =>
187+
jest.fn().mockResolvedValue({
188+
result: true,
189+
constants: {
190+
isPerformanceCollectionEnabled: true,
191+
isInstrumentationEnabled: true,
192+
},
193+
} as never),
194+
},
195+
);
196+
});
197+
});
198+
199+
it('newTrace()', function () {
200+
const perf = getPerformance();
201+
perfV9Deprecation(
202+
() => trace(perf, 'invertase'),
203+
() => perf.newTrace('invertase'),
204+
'newTrace',
205+
);
206+
});
207+
208+
it('newHttpMetric()', function () {
209+
const perf = getPerformance();
210+
perfV9Deprecation(
211+
() => httpMetric(perf, 'https://invertase.io', 'GET'),
212+
() => perf.newHttpMetric('https://invertase.io', 'GET'),
213+
'newHttpMetric',
214+
);
215+
});
216+
217+
it('newScreenTrace()', function () {
218+
const perf = getPerformance();
219+
perfV9Deprecation(
220+
() => newScreenTrace(perf, 'invertase'),
221+
() => perf.newScreenTrace('invertase'),
222+
'newScreenTrace',
223+
);
224+
});
225+
226+
it('startScreenTrace()', function () {
227+
const perf = getPerformance();
228+
perfV9Deprecation(
229+
() => startScreenTrace(perf, 'invertase'),
230+
() => perf.startScreenTrace('invertase'),
231+
'startScreenTrace',
232+
);
233+
});
234+
});
166235
});

packages/perf/lib/modular/index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
* @typedef {import('..').FirebasePerformanceTypes.HttpMetric} HttpMetric
2424
*/
2525

26-
import { isBoolean } from '@react-native-firebase/app/lib/common';
2726
import { getApp } from '@react-native-firebase/app';
2827

28+
import { MODULAR_DEPRECATION_ARG } from '@react-native-firebase/app/lib/common';
29+
2930
/**
3031
* Returns a Performance instance for the given app.
3132
* @param app - FirebaseApp. Optional.
@@ -48,8 +49,11 @@ export function getPerformance(app) {
4849
export async function initializePerformance(app, settings) {
4950
const perf = getApp(app.name).perf();
5051

51-
if (settings && isBoolean(settings.dataCollectionEnabled)) {
52-
await perf.setPerformanceCollectionEnabled(settings.dataCollectionEnabled);
52+
if (settings && settings.dataCollectionEnabled !== undefined) {
53+
perf.dataCollectionEnabled = settings.dataCollectionEnabled;
54+
}
55+
if (settings && settings.instrumentationEnabled !== undefined) {
56+
perf.instrumentationEnabled = settings.instrumentationEnabled;
5357
}
5458

5559
return perf;
@@ -62,7 +66,7 @@ export async function initializePerformance(app, settings) {
6266
* @returns {Trace}
6367
*/
6468
export function trace(perf, identifier) {
65-
return perf.newTrace(identifier);
69+
return perf.newTrace.call(perf, identifier, MODULAR_DEPRECATION_ARG);
6670
}
6771

6872
/**
@@ -72,7 +76,7 @@ export function trace(perf, identifier) {
7276
* @returns {HttpMetric}
7377
*/
7478
export function httpMetric(perf, identifier, httpMethod) {
75-
return perf.newHttpMetric(identifier, httpMethod);
79+
return perf.newHttpMetric.call(perf, identifier, httpMethod, MODULAR_DEPRECATION_ARG);
7680
}
7781

7882
/**
@@ -84,7 +88,7 @@ export function httpMetric(perf, identifier, httpMethod) {
8488
* @returns {ScreenTrace}
8589
*/
8690
export function newScreenTrace(perf, identifier) {
87-
return perf.newScreenTrace(identifier);
91+
return perf.newScreenTrace.call(perf, identifier, MODULAR_DEPRECATION_ARG);
8892
}
8993
/**
9094
* Creates a ScreenTrace instance with the given identifier and immediately starts it.
@@ -95,5 +99,5 @@ export function newScreenTrace(perf, identifier) {
9599
* @returns {Promise<ScreenTrace>}
96100
*/
97101
export function startScreenTrace(perf, identifier) {
98-
return perf.startScreenTrace(identifier);
102+
return perf.startScreenTrace.call(perf, identifier, MODULAR_DEPRECATION_ARG);
99103
}

0 commit comments

Comments
 (0)