Skip to content

Commit a41337d

Browse files
committed
Renamed ReportMetric to MetricReporter
1 parent dcbaed4 commit a41337d

File tree

9 files changed

+26
-27
lines changed

9 files changed

+26
-27
lines changed

injected/src/features/duck-player.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { DuckPlayerOverlayMessages, OpenInDuckPlayerMsg, Pixel } from './duckpla
3737
import { isBeingFramed } from '../utils.js';
3838
import { initOverlays } from './duckplayer/overlays.js';
3939
import { Environment } from './duckplayer/environment.js';
40-
import { ReportMetric } from '../../../special-pages/shared/report-metric.js';
40+
import { MetricsReporter } from '../../../special-pages/shared/metrics-reporter.js';
4141

4242
/**
4343
* @typedef UserValues - A way to communicate user settings
@@ -110,7 +110,7 @@ export default class DuckPlayerFeature extends ContentFeature {
110110
comms.serpProxy();
111111
}
112112
} catch (e) {
113-
const metrics = new ReportMetric(this.messaging);
113+
const metrics = new MetricsReporter(this.messaging);
114114
metrics.reportExceptionWithError(e);
115115
}
116116
}

injected/src/features/duckplayer/overlay-messages.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable promise/prefer-await-to-then */
22
import * as constants from './constants.js';
3-
import { ReportMetric, EXCEPTION_KIND_MESSAGING_ERROR } from '../../../../special-pages/shared/report-metric.js';
3+
import { MetricsReporter, EXCEPTION_KIND_MESSAGING_ERROR } from '../../../../special-pages/shared/metrics-reporter.js';
44

55
/**
66
* @typedef {import("@duckduckgo/messaging").Messaging} Messaging
@@ -22,7 +22,7 @@ export class DuckPlayerOverlayMessages {
2222
*/
2323
this.messaging = messaging;
2424
this.environment = environment;
25-
this.metrics = new ReportMetric(messaging);
25+
this.metrics = new MetricsReporter(messaging);
2626
}
2727

2828
/**

injected/src/features/duckplayer/overlays.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { DomState } from './util.js';
22
import { ClickInterception, Thumbnails } from './thumbnails.js';
33
import { VideoOverlay } from './video-overlay.js';
44
import { registerCustomElements } from './components/index.js';
5-
import { EXCEPTION_KIND_INITIAL_SETUP_ERROR } from '../../../../special-pages/shared/report-metric.js';
5+
import { EXCEPTION_KIND_INITIAL_SETUP_ERROR } from '../../../../special-pages/shared/metrics-reporter.js';
66

77
/**
88
* @typedef {object} OverlayOptions

special-pages/pages/duckplayer/app/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { Components } from './components/Components.jsx';
1515
import { MobileApp } from './components/MobileApp.jsx';
1616
import { DesktopApp } from './components/DesktopApp.jsx';
1717
import { YouTubeErrorProvider } from './providers/YouTubeErrorProvider';
18-
import { EXCEPTION_KIND_INIT_ERROR, EXCEPTION_KIND_INITIAL_SETUP_ERROR } from '../../../shared/report-metric';
18+
import { EXCEPTION_KIND_INIT_ERROR, EXCEPTION_KIND_INITIAL_SETUP_ERROR } from '../../../shared/metrics-reporter.js';
1919

2020
/** @typedef {import('../types/duckplayer').YouTubeError} YouTubeError */
2121

special-pages/pages/duckplayer/integration-tests/duck-player.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,6 @@ export class DuckPlayerPage {
572572
*/
573573
async didSendReportMetric(evt) {
574574
const events = await this.mocks.waitForCallCount({ method: 'reportMetric', count: 1 });
575-
console.log('events', events);
576575
expect(events).toContainEqual({
577576
payload: {
578577
context: 'specialPages',

special-pages/pages/duckplayer/src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createSpecialPageMessaging } from '../../../shared/create-special-page-
44
import { init } from '../app/index.js';
55
import { initStorage } from './storage.js';
66
import '../../../shared/live-reload.js';
7-
import { ReportMetric, EXCEPTION_KIND_MESSAGING_ERROR } from '../../../shared/report-metric.js';
7+
import { MetricsReporter, EXCEPTION_KIND_MESSAGING_ERROR } from '../../../shared/metrics-reporter.js';
88

99
export class DuckplayerPage {
1010
/**
@@ -13,7 +13,7 @@ export class DuckplayerPage {
1313
constructor(messaging, injectName) {
1414
this.messaging = createTypedMessages(this, messaging);
1515
this.injectName = injectName;
16-
this.metrics = new ReportMetric(messaging);
16+
this.metrics = new MetricsReporter(messaging);
1717
}
1818

1919
/**

special-pages/shared/report-metric.js renamed to special-pages/shared/metrics-reporter.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
*
1111
* @example
1212
* ```javascript
13-
* import { ReportMetric } from './report-metric.js';
13+
* import { MetricsReporter } from './metrics-reporter.js';
1414
*
15-
* const metrics = new ReportMetric(messaging);
15+
* const metrics = new MetricsReporter(messaging);
1616
*
1717
* // Report a custom metric
1818
* metrics.reportMetric({
@@ -30,7 +30,7 @@
3030
* metrics.reportExceptionWithError(new Error('Missing params'));
3131
* ```
3232
*
33-
* @module Report Metric
33+
* @module Metrics Reporter
3434
*/
3535

3636
/**
@@ -55,7 +55,7 @@ export const EXCEPTION_KIND_MESSAGING_ERROR = 'MessagingError';
5555
/**
5656
* Class for reporting metrics and exceptions to the native layer.
5757
*/
58-
export class ReportMetric {
58+
export class MetricsReporter {
5959
/** The message ID used for reporting metrics to the native layer */
6060
static MESSAGE_ID = /** @type {const} */ ('reportMetric');
6161

@@ -66,7 +66,7 @@ export class ReportMetric {
6666
static DEFAULT_EXCEPTION_MESSAGE = /** @type {const} */ ('Unknown error');
6767

6868
/**
69-
* Creates a new ReportMetric instance.
69+
* Creates a new MetricsReporter instance.
7070
*
7171
* @param {SharedMessaging} messaging - The messaging instance used to communicate with the native layer
7272
* @throws {Error} When messaging is not provided or messaging.notify is not defined
@@ -90,7 +90,7 @@ export class ReportMetric {
9090
if (!metricEvent?.metricName) {
9191
throw new Error('metricName is required');
9292
}
93-
this.messaging.notify(ReportMetric.MESSAGE_ID, metricEvent);
93+
this.messaging.notify(MetricsReporter.MESSAGE_ID, metricEvent);
9494
}
9595

9696
/**
@@ -108,11 +108,11 @@ export class ReportMetric {
108108
* @private
109109
*/
110110
_createExceptionMetric(params) {
111-
const message = params?.message && typeof params.message === 'string' ? params.message : ReportMetric.DEFAULT_EXCEPTION_MESSAGE;
111+
const message = params?.message && typeof params.message === 'string' ? params.message : MetricsReporter.DEFAULT_EXCEPTION_MESSAGE;
112112
const kind = params?.kind && typeof params.kind === 'string' ? params.kind : EXCEPTION_KIND_GENERIC_ERROR;
113113

114114
return {
115-
metricName: ReportMetric.METRIC_NAME_EXCEPTION,
115+
metricName: MetricsReporter.METRIC_NAME_EXCEPTION,
116116
params: {
117117
message,
118118
kind,

special-pages/unit-test/report-metric.mjs renamed to special-pages/unit-test/metrics-reporter.mjs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, it, mock, beforeEach } from 'node:test';
22
import assert from 'node:assert';
3-
import { ReportMetric } from '../shared/report-metric.js';
3+
import { MetricsReporter } from '../shared/metrics-reporter.js';
44

55
describe('reportMetric', () => {
66
let messaging;
@@ -16,18 +16,18 @@ describe('reportMetric', () => {
1616

1717
it('should throw an error if messaging is not provided', () => {
1818
// @ts-expect-error - this is a forced error
19-
assert.throws(() => new ReportMetric(null));
19+
assert.throws(() => new MetricsReporter(null));
2020
});
2121

2222
it('should throw an error if metricName is not provided', () => {
23-
const metrics = new ReportMetric(messaging);
23+
const metrics = new MetricsReporter(messaging);
2424
const metricParams = /** @type {any} */ ({ metricName: '', params: {} });
2525
assert.throws(() => metrics.reportMetric(metricParams));
2626
assert.strictEqual(messaging.notify.mock.callCount(), 0);
2727
});
2828

2929
it('should call messaging.notify with the correct parameters', () => {
30-
const metrics = new ReportMetric(messaging);
30+
const metrics = new MetricsReporter(messaging);
3131
const metricParams = /** @type {any} */ ({ metricName: 'exception', params: { message: 'This is a test' } });
3232
assert.strictEqual(messaging.notify.mock.callCount(), 0);
3333

@@ -44,7 +44,7 @@ describe('reportMetric', () => {
4444
});
4545

4646
it('should call messaging.notify when reportException is called', () => {
47-
const metrics = new ReportMetric(messaging);
47+
const metrics = new MetricsReporter(messaging);
4848
const eventParams = /** @type {any} */ ({ message: 'This is a test', kind: 'TestError' });
4949
assert.strictEqual(messaging.notify.mock.callCount(), 0);
5050

@@ -61,7 +61,7 @@ describe('reportMetric', () => {
6161
});
6262

6363
it('should send default values when reportException is called with empty params', () => {
64-
const metrics = new ReportMetric(messaging);
64+
const metrics = new MetricsReporter(messaging);
6565
const eventParams = /** @type {any} */ ({});
6666
assert.strictEqual(messaging.notify.mock.callCount(), 0);
6767

@@ -78,7 +78,7 @@ describe('reportMetric', () => {
7878
});
7979

8080
it('should not report anything when reportExceptionWithError is called with a non-Error object', () => {
81-
const metrics = new ReportMetric(messaging);
81+
const metrics = new MetricsReporter(messaging);
8282
const eventParams = /** @type {any} */ ({ message: 'This is a test', kind: 'TestError' });
8383
assert.strictEqual(messaging.notify.mock.callCount(), 0);
8484

@@ -87,7 +87,7 @@ describe('reportMetric', () => {
8787
});
8888

8989
it('should send the error message and kind when reportExceptionWithError is called with an Error object', () => {
90-
const metrics = new ReportMetric(messaging);
90+
const metrics = new MetricsReporter(messaging);
9191
const error = new Error('This is a test');
9292
error.name = 'TestError';
9393
assert.strictEqual(messaging.notify.mock.callCount(), 0);
@@ -105,7 +105,7 @@ describe('reportMetric', () => {
105105
});
106106

107107
it('should send default values when reportExceptionWithError is called with an empty error object', () => {
108-
const metrics = new ReportMetric(messaging);
108+
const metrics = new MetricsReporter(messaging);
109109
const error = new Error();
110110
assert.strictEqual(messaging.notify.mock.callCount(), 0);
111111

typedoc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const config = {
3636
'special-pages/pages/new-tab/app/favorites/constants.js',
3737
'special-pages/pages/**/types/*.ts',
3838
'special-pages/shared/types/*.ts',
39-
'special-pages/shared/report-metric.js',
39+
'special-pages/shared/metrics-reporter.js',
4040
],
4141
categoryOrder: ['Special Pages', 'Content Scope Scripts Integrations', 'Other'],
4242
out: 'docs',

0 commit comments

Comments
 (0)