Skip to content

Commit

Permalink
test(perf): ensure modular API are exported properly (#7939)
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley authored Jul 29, 2024
1 parent 246b86c commit ab1e2f6
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 10 deletions.
36 changes: 35 additions & 1 deletion packages/perf/__tests__/perf.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { describe, expect, it } from '@jest/globals';

import perf, { firebase } from '../lib';
import perf, {
firebase,
getPerformance,
initializePerformance,
trace,
httpMetric,
newScreenTrace,
startScreenTrace,
} from '../lib';

describe('Performance Monitoring', function () {
describe('namespace', function () {
Expand Down Expand Up @@ -119,4 +127,30 @@ describe('Performance Monitoring', function () {
}
});
});

describe('modular', function () {
it('`getPerformance` function is properly exposed to end user', function () {
expect(getPerformance).toBeDefined();
});

it('`initializePerformance` function is properly exposed to end user', function () {
expect(initializePerformance).toBeDefined();
});

it('`trace` function is properly exposed to end user', function () {
expect(trace).toBeDefined();
});

it('`httpMetric` function is properly exposed to end user', function () {
expect(httpMetric).toBeDefined();
});

it('`newScreenTrace` function is properly exposed to end user', function () {
expect(newScreenTrace).toBeDefined();
});

it('`startScreenTrace` function is properly exposed to end user', function () {
expect(startScreenTrace).toBeDefined();
});
});
});
2 changes: 2 additions & 0 deletions packages/perf/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,8 @@ export const firebase: ReactNativeFirebase.Module & {

export default defaultExport;

export * from './modular';

/**
* Attach namespace to `firebase.` and `FirebaseApp.`.
*/
Expand Down
11 changes: 2 additions & 9 deletions packages/perf/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ import Trace from './Trace';
import ScreenTrace from './ScreenTrace';
import version from './version';

export {
getPerformance,
initializePerformance,
trace,
httpMetric,
newScreenTrace,
startScreenTrace,
} from './modular/index';

const statics = {};

const namespace = 'perf';
Expand Down Expand Up @@ -175,6 +166,8 @@ export default createModuleNamespace({
ModuleClass: FirebasePerfModule,
});

export * from './modular';

// import perf, { firebase } from '@react-native-firebase/perf';
// perf().X(...);
// firebase.perf().X(...);
Expand Down
88 changes: 88 additions & 0 deletions packages/perf/lib/modular/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright (c) 2016-present Invertase Limited & Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this library except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import { FirebaseApp } from '@firebase/app-types';
import { FirebasePerformanceTypes } from '..';

import Performance = FirebasePerformanceTypes.Module;

import Trace = FirebasePerformanceTypes.Module.Trace;
import HttpMethod = FirebasePerformanceTypes.HttpMethod;
import HttpMetric = FirebasePerformanceTypes.HttpMetric;
import ScreenTrace = FirebasePerformanceTypes.ScreenTrace;

/**
* Returns a Performance instance for the given app.
* @param app - FirebaseApp. Optional.
* @returns {Performance}
*/
export function getPerformance(app?: FirebaseApp): Performance;

type PerformanceSettings = {
dataCollectionEnabled: boolean;
};

/**
* Returns a Performance instance for the given app.
* @param app - FirebaseApp. Required.
* @param settings - PerformanceSettings. Set "dataCollectionEnabled" which will enable/disable Performance collection.
* @returns {Promise<Performance>}
*/
export function initializePerformance(
app: FirebaseApp,
settings: PerformanceSettings,
): Promise<Performance>;

/**
* Returns a Trace instance.
* @param perf - Performance instance.
* @param identifier - A String to identify the Trace instance.
* @returns {Trace}
*/
export function trace(perf: Performance, identifier: string): Trace;

/**
* Returns a HttpMetric instance.
* @param perf - Performance instance.
* @param identifier - A String to identify the HttpMetric instance.
* @param httpMethod - The HTTP method for the HttpMetric instance.
* @returns {HttpMetric}
*/
export function httpMetric(
perf: Performance,
identifier: string,
httpMethod: HttpMethod,
): HttpMetric;

/**
* Creates a ScreenTrace instance with the given identifier.
* Throws if hardware acceleration is disabled or if Android is 9.0 or 9.1.
* @platform android Android !== 9.0.0 && Android !== 9.1.0
* @param perf - Performance instance.
* @param identifier - Name of the trace, no leading or trailing whitespace allowed, no leading underscore '_' character allowed, max length is 100.
* @returns {ScreenTrace}
*/
export function newScreenTrace(perf: Performance, identifier: string): ScreenTrace;

/**
* Creates a ScreenTrace instance with the given identifier and immediately starts it.
* Throws if hardware acceleration is disabled or if Android is 9.0 or 9.1.
* @platform android Android !== 9.0.0 && Android !== 9.1.0
* @param perf - Performance instance.
* @param identifier - Name of the screen.
* @returns {Promise<ScreenTrace>}
*/
export function startScreenTrace(perf: Performance, identifier: string): Promise<ScreenTrace>;
10 changes: 10 additions & 0 deletions packages/perf/lib/modular/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
*
*/

/**
* @typedef {import('@firebase/app').FirebaseApp} FirebaseApp
* @typedef {import('..').FirebasePerformanceTypes.Module} Performance
* @typedef {import('..').FirebasePerformanceTypes.Trace} Trace
* @typedef {import('..').FirebasePerformanceTypes.ScreenTrace} ScreenTrace
* @typedef {import('..').FirebasePerformanceTypes.HttpMetric} HttpMetric
*/

import { isBoolean } from '@react-native-firebase/app/lib/common';
import { firebase } from '..';

Expand Down Expand Up @@ -73,6 +81,7 @@ export function httpMetric(perf, identifier, httpMethod) {
* @platform android Android !== 9.0.0 && Android !== 9.1.0
* @param perf - Performance instance
* @param identifier Name of the trace, no leading or trailing whitespace allowed, no leading underscore '_' character allowed, max length is 100.
* @returns {ScreenTrace}
*/
export function newScreenTrace(perf, identifier) {
return perf.newScreenTrace(identifier);
Expand All @@ -83,6 +92,7 @@ export function newScreenTrace(perf, identifier) {
* @platform android Android !== 9.0.0 && Android !== 9.1.0
* @param perf - Performance instance
* @param identifier Name of the screen
* @returns {Promise<ScreenTrace>}
*/
export function startScreenTrace(perf, identifier) {
return perf.startScreenTrace(identifier);
Expand Down

0 comments on commit ab1e2f6

Please sign in to comment.