Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/app/lib/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,15 @@ const mapOfDeprecationReplacements = {
NotificationAndroidVisibility: 'NotificationAndroidVisibility',
},
},
perf: {
default: {
setPerformanceCollectionEnabled: 'initializePerformance()',
newTrace: 'trace()',
newHttpMetric: 'httpMetric()',
newScreenTrace: 'newScreenTrace()',
startScreenTrace: 'startScreenTrace()',
},
},
remoteConfig: {
default: {
activate: 'activate()',
Expand Down
71 changes: 70 additions & 1 deletion packages/perf/__tests__/perf.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 () {
Expand Down Expand Up @@ -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',
);
});
});
});
18 changes: 11 additions & 7 deletions packages/perf/lib/modular/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Comment thread
MichaelVerdon marked this conversation as resolved.
perf.instrumentationEnabled = settings.instrumentationEnabled;
Comment thread
MichaelVerdon marked this conversation as resolved.
}

return perf;
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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.
Expand All @@ -95,5 +99,5 @@ export function newScreenTrace(perf, identifier) {
* @returns {Promise<ScreenTrace>}
*/
export function startScreenTrace(perf, identifier) {
return perf.startScreenTrace(identifier);
return perf.startScreenTrace.call(perf, identifier, MODULAR_DEPRECATION_ARG);
}
Loading