diff --git a/packages/app/lib/common/index.js b/packages/app/lib/common/index.js index d4ff6fb134..c731d7f341 100644 --- a/packages/app/lib/common/index.js +++ b/packages/app/lib/common/index.js @@ -403,6 +403,15 @@ const mapOfDeprecationReplacements = { NotificationAndroidVisibility: 'NotificationAndroidVisibility', }, }, + perf: { + default: { + setPerformanceCollectionEnabled: 'initializePerformance()', + newTrace: 'trace()', + newHttpMetric: 'httpMetric()', + newScreenTrace: 'newScreenTrace()', + startScreenTrace: 'startScreenTrace()', + }, + }, remoteConfig: { default: { activate: 'activate()', diff --git a/packages/perf/__tests__/perf.test.ts b/packages/perf/__tests__/perf.test.ts index feb6e8ee77..ad6bbe1eb1 100644 --- a/packages/perf/__tests__/perf.test.ts +++ b/packages/perf/__tests__/perf.test.ts @@ -1,4 +1,4 @@ -import { afterAll, beforeAll, describe, expect, it } from '@jest/globals'; +import { afterAll, beforeAll, describe, expect, it, beforeEach, jest } from '@jest/globals'; import perf, { firebase, @@ -10,6 +10,14 @@ import perf, { startScreenTrace, } from '../lib'; +import { + createCheckV9Deprecation, + CheckV9DeprecationFunction, +} from '../../app/lib/common/unitTestUtils'; + +// @ts-ignore test +import FirebaseModule from '../../app/lib/internal/FirebaseModule'; + describe('Performance Monitoring', function () { describe('namespace', function () { beforeAll(async function () { @@ -163,4 +171,65 @@ describe('Performance Monitoring', function () { expect(startScreenTrace).toBeDefined(); }); }); + + describe('test `console.warn` is called for RNFB v8 API & not called for v9 API', function () { + let perfV9Deprecation: CheckV9DeprecationFunction; + + beforeEach(function () { + perfV9Deprecation = createCheckV9Deprecation(['perf']); + + // @ts-ignore test + jest.spyOn(FirebaseModule.prototype, 'native', 'get').mockImplementation(() => { + return new Proxy( + {}, + { + get: () => + jest.fn().mockResolvedValue({ + result: true, + constants: { + isPerformanceCollectionEnabled: true, + isInstrumentationEnabled: true, + }, + } as never), + }, + ); + }); + }); + + it('newTrace()', function () { + const perf = getPerformance(); + perfV9Deprecation( + () => trace(perf, 'invertase'), + () => perf.newTrace('invertase'), + 'newTrace', + ); + }); + + it('newHttpMetric()', function () { + const perf = getPerformance(); + perfV9Deprecation( + () => httpMetric(perf, 'https://invertase.io', 'GET'), + () => perf.newHttpMetric('https://invertase.io', 'GET'), + 'newHttpMetric', + ); + }); + + it('newScreenTrace()', function () { + const perf = getPerformance(); + perfV9Deprecation( + () => newScreenTrace(perf, 'invertase'), + () => perf.newScreenTrace('invertase'), + 'newScreenTrace', + ); + }); + + it('startScreenTrace()', function () { + const perf = getPerformance(); + perfV9Deprecation( + () => startScreenTrace(perf, 'invertase'), + () => perf.startScreenTrace('invertase'), + 'startScreenTrace', + ); + }); + }); }); diff --git a/packages/perf/lib/modular/index.js b/packages/perf/lib/modular/index.js index 26c8b8581e..959eeb5ac6 100644 --- a/packages/perf/lib/modular/index.js +++ b/packages/perf/lib/modular/index.js @@ -23,9 +23,10 @@ * @typedef {import('..').FirebasePerformanceTypes.HttpMetric} HttpMetric */ -import { isBoolean } from '@react-native-firebase/app/lib/common'; import { getApp } from '@react-native-firebase/app'; +import { MODULAR_DEPRECATION_ARG } from '@react-native-firebase/app/lib/common'; + /** * Returns a Performance instance for the given app. * @param app - FirebaseApp. Optional. @@ -48,8 +49,11 @@ export function getPerformance(app) { export async function initializePerformance(app, settings) { const perf = getApp(app.name).perf(); - if (settings && isBoolean(settings.dataCollectionEnabled)) { - await perf.setPerformanceCollectionEnabled(settings.dataCollectionEnabled); + if (settings && settings.dataCollectionEnabled !== undefined) { + perf.dataCollectionEnabled = settings.dataCollectionEnabled; + } + if (settings && settings.instrumentationEnabled !== undefined) { + perf.instrumentationEnabled = settings.instrumentationEnabled; } return perf; @@ -62,7 +66,7 @@ export async function initializePerformance(app, settings) { * @returns {Trace} */ export function trace(perf, identifier) { - return perf.newTrace(identifier); + return perf.newTrace.call(perf, identifier, MODULAR_DEPRECATION_ARG); } /** @@ -72,7 +76,7 @@ export function trace(perf, identifier) { * @returns {HttpMetric} */ export function httpMetric(perf, identifier, httpMethod) { - return perf.newHttpMetric(identifier, httpMethod); + return perf.newHttpMetric.call(perf, identifier, httpMethod, MODULAR_DEPRECATION_ARG); } /** @@ -84,7 +88,7 @@ export function httpMetric(perf, identifier, httpMethod) { * @returns {ScreenTrace} */ export function newScreenTrace(perf, identifier) { - return perf.newScreenTrace(identifier); + return perf.newScreenTrace.call(perf, identifier, MODULAR_DEPRECATION_ARG); } /** * Creates a ScreenTrace instance with the given identifier and immediately starts it. @@ -95,5 +99,5 @@ export function newScreenTrace(perf, identifier) { * @returns {Promise} */ export function startScreenTrace(perf, identifier) { - return perf.startScreenTrace(identifier); + return perf.startScreenTrace.call(perf, identifier, MODULAR_DEPRECATION_ARG); }