Skip to content

Commit 7bc6304

Browse files
committed
Test refactor
1 parent 888a23f commit 7bc6304

File tree

7 files changed

+113
-30
lines changed

7 files changed

+113
-30
lines changed

injected/integration-test/duckplayer-mobile.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,6 @@ test.describe('Reporting exceptions', () => {
154154
await overlays.withRemoteConfig({ locale: 'en' });
155155
await overlays.initialSetupError();
156156
await overlays.gotoPlayerPage();
157-
await overlays.didSendException('TypeError', "undefined is not an object (evaluating 'userValues.privatePlayerMode')");
157+
await overlays.didSendInitialSetupErrorException();
158158
});
159159
});

injected/integration-test/duckplayer.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,6 @@ test.describe('Reporting exceptions', () => {
376376
await overlays.withRemoteConfig({ locale: 'en' });
377377
await overlays.initialSetupError();
378378
await overlays.gotoPlayerPage();
379-
await overlays.didSendException('TypeError', "Cannot read properties of undefined (reading 'privatePlayerMode')");
379+
await overlays.didSendInitialSetupErrorException();
380380
});
381381
});

injected/integration-test/page-objects/duckplayer-overlays.js

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,31 @@ export class DuckplayerOverlays {
306306
}
307307

308308
async initialSetupError() {
309-
await this.collector.updateMockResponse({
310-
initialSetup: {},
309+
await this.build.switch({
310+
android: async () => {
311+
await this.collector.updateMockResponse({
312+
initialSetup: {
313+
locale: 'en',
314+
env: 'development',
315+
platform: { name: 'android ' },
316+
},
317+
});
318+
},
319+
apple: async () => {
320+
await this.collector.updateMockResponse({
321+
initialSetup: null,
322+
});
323+
},
324+
'apple-isolated': async () => {
325+
await this.collector.updateMockResponse({
326+
initialSetup: null,
327+
});
328+
},
329+
windows: async () => {
330+
await this.collector.updateMockResponse({
331+
initialSetup: '',
332+
});
333+
},
311334
});
312335
}
313336

@@ -487,11 +510,38 @@ export class DuckplayerOverlays {
487510
* @param {string} kind
488511
* @param {string} message
489512
*/
490-
async didSendException(kind, message) {
513+
async didSendException(kind, message, context = 'contentScopeScripts') {
491514
console.log('messages', await this.collector.outgoingMessages());
492515

493516
const messages = await this.collector.waitForMessage('reportMetric');
494-
expect(messages).toMatchObject([{ payload: { params: { metricName: 'exception', params: { kind, message } } } }]);
517+
expect(messages).toMatchObject([
518+
{
519+
payload: {
520+
context,
521+
featureName: 'duckPlayer',
522+
method: 'reportMetric',
523+
params: { metricName: 'exception', params: { kind, message } },
524+
},
525+
},
526+
]);
527+
}
528+
529+
async didSendInitialSetupErrorException() {
530+
await this.build.switch({
531+
android: async () => {
532+
// Android produces a TypeError due to how its messaging lib is wired up
533+
await this.didSendException('TypeError', "undefined is not an object (evaluating 'init2.settings.pip')");
534+
},
535+
apple: async () => {
536+
await this.didSendException('InitialSetupError', 'Error: an unknown error occurred');
537+
},
538+
'apple-isolated': async () => {
539+
await this.didSendException('InitialSetupError', 'Error: an unknown error occurred', 'contentScopeScriptsIsolated');
540+
},
541+
windows: async () => {
542+
await this.didSendException('InitialSetupError', 'Error: unknown error');
543+
},
544+
});
495545
}
496546

497547
/**

injected/src/features/duckplayer/overlays.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +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 { reportException, METRIC_NAME_INITIAL_SETUP_ERROR } from '../../../../special-pages/shared/report-metric.js';
56

67
/**
78
* @typedef {object} OverlayOptions
@@ -28,14 +29,19 @@ export async function initOverlays(settings, environment, messages) {
2829
} catch (e) {
2930
console.log('INITIAL SETUP ERROR');
3031
console.warn(e);
32+
reportException(messages.messaging, { message: e?.toString(), kind: METRIC_NAME_INITIAL_SETUP_ERROR });
3133
return;
3234
}
3335

3436
if (!initialSetup) {
35-
console.warn('cannot continue without user settings');
37+
const message = 'cannot continue without user settings';
38+
console.warn(message);
39+
reportException(messages.messaging, { message, kind: METRIC_NAME_INITIAL_SETUP_ERROR });
3640
return;
3741
}
3842

43+
console.log('initialSetup Yo', JSON.stringify(initialSetup, null, 2));
44+
3945
let { userValues, ui } = initialSetup;
4046

4147
/**

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

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,30 @@ export class DuckPlayerPage {
145145
this.mocks.defaultResponses(clone);
146146
}
147147

148-
initError() {
148+
initialSetupError() {
149149
const clone = structuredClone(this.defaults);
150-
// @ts-expect-error - this is a test
151-
clone.initialSetup = {
152-
locale: 'en',
153-
env: 'development',
154-
platform: this.platform.name === 'windows' ? undefined : { name: this.platform.name },
155-
};
156-
this.mocks.defaultResponses(clone);
150+
151+
this.build.switch({
152+
android: () => {
153+
// @ts-expect-error - this is a test
154+
clone.initialSetup = {
155+
locale: 'en',
156+
env: 'development',
157+
platform: this.platform.name === 'windows' ? undefined : { name: this.platform.name },
158+
};
159+
this.mocks.defaultResponses(clone);
160+
},
161+
apple: () => {
162+
// @ts-expect-error - this is a test
163+
clone.initialSetup = null;
164+
this.mocks.defaultResponses(clone);
165+
},
166+
windows: () => {
167+
// @ts-expect-error - this is a test
168+
clone.initialSetup = '';
169+
this.mocks.defaultResponses(clone);
170+
},
171+
});
157172
}
158173

159174
/**
@@ -270,6 +285,11 @@ export class DuckPlayerPage {
270285
await this.openPage(params);
271286
}
272287

288+
async openWithNoEmbed() {
289+
const params = new URLSearchParams({ videoID: '' });
290+
await this.openPage(params);
291+
}
292+
273293
/**
274294
* @param {string} [videoID]
275295
* @returns {Promise<void>}
@@ -553,16 +573,15 @@ export class DuckPlayerPage {
553573
*/
554574
async didSendReportMetric(evt) {
555575
const events = await this.mocks.waitForCallCount({ method: 'reportMetric', count: 1 });
556-
expect(events).toStrictEqual([
557-
{
558-
payload: {
559-
context: 'specialPages',
560-
featureName: 'duckPlayerPage',
561-
method: 'reportMetric',
562-
params: evt,
563-
},
576+
console.log('events', events);
577+
expect(events).toContainEqual({
578+
payload: {
579+
context: 'specialPages',
580+
featureName: 'duckPlayerPage',
581+
method: 'reportMetric',
582+
params: evt,
564583
},
565-
]);
584+
});
566585
}
567586

568587
/**
@@ -573,16 +592,17 @@ export class DuckPlayerPage {
573592
return this.didSendReportMetric({ metricName: 'exception', params: { kind, message } });
574593
}
575594

576-
async didSendInitErrorException() {
595+
async didSendInitialSetupErrorException() {
577596
await this.build.switch({
578597
android: async () => {
579-
await this.didSendException('InitError', "undefined is not an object (evaluating 'init2.settings.pip')");
598+
// Android produces a TypeError due to how its messaging lib is wired up
599+
await this.didSendException('TypeError', "undefined is not an object (evaluating 'init2.settings.pip')");
580600
},
581601
apple: async () => {
582-
await this.didSendException('InitError', "undefined is not an object (evaluating 'init2.settings.pip')");
602+
await this.didSendException('InitialSetupError', 'Max attempts reached: Error: an unknown error occurred');
583603
},
584604
windows: async () => {
585-
await this.didSendException('InitError', "Cannot read properties of undefined (reading 'pip')");
605+
await this.didSendException('InitialSetupError', 'Max attempts reached: Error: unknown error');
586606
},
587607
});
588608
}

special-pages/pages/duckplayer/integration-tests/duckplayer.spec.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,18 @@ test.describe('reporting exceptions', () => {
335335
await duckplayer.showsErrorMessage();
336336
await duckplayer.didSendException('Error', 'Simulated Exception');
337337
});
338+
test('no embed error', async ({ page }, workerInfo) => {
339+
const duckplayer = DuckPlayerPage.create(page, workerInfo);
340+
// load as normal
341+
await duckplayer.openWithNoEmbed();
342+
await duckplayer.didSendException('InitError', 'embed not found');
343+
});
338344
test('initial setup error', async ({ page }, workerInfo) => {
339345
const duckplayer = DuckPlayerPage.create(page, workerInfo);
340346
// load as normal
341-
duckplayer.initError();
347+
duckplayer.initialSetupError();
342348
await duckplayer.openWithVideoID();
343-
await duckplayer.didSendInitErrorException();
349+
await duckplayer.didSendInitialSetupErrorException();
344350
});
345351
});
346352

special-pages/shared/report-metric.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export const REPORT_METRIC_MESSAGE_ID = 'reportMetric';
22
export const METRIC_NAME_EXCEPTION = 'exception';
3+
/* Error Types */
34
export const METRIC_NAME_GENERIC_ERROR = 'Error';
45
export const METRIC_NAME_INIT_ERROR = 'InitError';
56
export const METRIC_NAME_INITIAL_SETUP_ERROR = 'InitialSetupError';

0 commit comments

Comments
 (0)