Skip to content

Commit af297a6

Browse files
committed
WIP react support
1 parent bf4ea2c commit af297a6

File tree

9 files changed

+228
-10
lines changed

9 files changed

+228
-10
lines changed

config/webpack.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ module.exports = {
9494
resolve: {
9595
modules: ['node_modules', path.resolve(__dirname, '../../node_modules')],
9696
mainFields: ['browser', 'module', 'main'],
97-
extensions: ['.js', '.ts'],
97+
extensions: ['.js', '.ts', '.tsx'],
9898
symlinks: true
9999
},
100100
plugins: [

packages/telemetry/index.node.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ registerTelemetry();
2929
export * from './src/api';
3030
export * from './src/public-types';
3131
export * from './src/next';
32+
export * from './src/react';

packages/telemetry/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ registerTelemetry();
2222
export * from './src/api';
2323
export * from './src/public-types';
2424
export * from './src/next';
25+
export * from './src/react';

packages/telemetry/karma.conf.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@
1717

1818
const karmaBase = require('../../config/karma.base');
1919

20-
const files = [`src/**/*.test.ts`];
20+
const files = [`src/**/*.test.ts*`];
2121

2222
module.exports = function (config) {
2323
const karmaConfig = {
2424
...karmaBase,
2525
files,
26+
preprocessors: {
27+
'src/**/*.test.ts*': ['webpack', 'sourcemap']
28+
},
2629
frameworks: ['mocha']
2730
};
2831

packages/telemetry/package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
},
4242
"peerDependencies": {
4343
"@firebase/app": "0.x",
44-
"@firebase/app-types": "0.x"
44+
"@firebase/app-types": "0.x",
45+
"@types/react": "19.x",
46+
"react": "19.x"
4547
},
4648
"dependencies": {
4749
"@firebase/component": "0.7.0",
@@ -52,15 +54,20 @@
5254
"@opentelemetry/otlp-transformer": "0.205.0",
5355
"@opentelemetry/resources": "2.0.1",
5456
"@opentelemetry/sdk-logs": "0.203.0",
55-
"@opentelemetry/semantic-conventions": "1.36.0",
57+
"@opentelemetry/semantic-conventions": "1.36.0",
5658
"tslib": "^2.1.0"
5759
},
5860
"license": "Apache-2.0",
5961
"devDependencies": {
6062
"@firebase/app": "0.14.2",
6163
"@opentelemetry/sdk-trace-web": "2.1.0",
6264
"@rollup/plugin-json": "6.1.0",
65+
"@testing-library/dom": "10.4.1",
66+
"@testing-library/react": "16.3.0",
67+
"@types/react": "19.1.13",
6368
"next": "15.5.2",
69+
"react": "19.1.1",
70+
"react-dom": "19.1.1",
6471
"rollup": "2.79.2",
6572
"rollup-plugin-replace": "2.2.0",
6673
"rollup-plugin-typescript2": "0.36.0",
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { expect, use } from 'chai';
19+
import sinonChai from 'sinon-chai';
20+
import chaiAsPromised from 'chai-as-promised';
21+
import { restore, stub } from 'sinon';
22+
import * as app from '@firebase/app';
23+
import * as telemetry from './api';
24+
import { FirebaseApp } from '@firebase/app';
25+
import { Telemetry } from './public-types';
26+
import { FirebaseTelemetryBoundary } from './react';
27+
import React from 'react';
28+
import { render } from '@testing-library/react';
29+
30+
use(sinonChai);
31+
use(chaiAsPromised);
32+
33+
describe('firebaseTelemetryBoundary', () => {
34+
let getTelemetryStub: sinon.SinonStub;
35+
// let captureErrorStub: sinon.SinonStub;
36+
let fakeApp: FirebaseApp;
37+
let fakeTelemetry: Telemetry;
38+
39+
beforeEach(() => {
40+
fakeApp = {} as FirebaseApp;
41+
fakeTelemetry = {} as Telemetry;
42+
43+
stub(app, 'getApp').returns(fakeApp);
44+
getTelemetryStub = stub(telemetry, 'getTelemetry').returns(fakeTelemetry);
45+
// captureErrorStub = stub(telemetry, 'captureError');
46+
});
47+
48+
afterEach(() => {
49+
restore();
50+
});
51+
52+
it('does something else', async () => {
53+
render(<FirebaseTelemetryBoundary><span>here are my children</span></FirebaseTelemetryBoundary>);
54+
55+
expect(1).to.equal(1);
56+
});
57+
});

packages/telemetry/src/react.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import React from 'react';
19+
20+
console.log(React);
21+
22+
23+
export interface FirebaseTelemetryBoundaryProps {
24+
children: React.ReactNode;
25+
}
26+
27+
export class FirebaseTelemetryBoundary extends React.Component<FirebaseTelemetryBoundaryProps> {
28+
constructor(public props: FirebaseTelemetryBoundaryProps) {
29+
super(props);
30+
31+
console.info('init firebase telemetry boundary');
32+
}
33+
34+
render(): React.ReactNode {
35+
console.info('abc');
36+
return this.props.children;
37+
}
38+
}

packages/telemetry/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"extends": "../../config/tsconfig.base.json",
33
"compilerOptions": {
4-
"outDir": "dist"
4+
"outDir": "dist",
5+
"jsx": "react"
56
},
67
"exclude": ["dist/**/*"]
78
}

0 commit comments

Comments
 (0)