@@ -3,21 +3,25 @@ import { expect } from '@playwright/test';
33import { sentryTest } from '../../../../utils/fixtures' ;
44
55import { envelopeRequestParser , waitForErrorRequest } from '../../../../utils/helpers' ;
6- import { buildLaunchDarklyFlagUsedHandler } from '@sentry/browser' ;
7- import type { LDContext , LDOptions , LDFlagValue , LDClient } from 'launchdarkly-js-client-sdk' ;
6+ import type { LDContext , LDOptions , LDFlagValue , LDClient , LDEvaluationDetail } from 'launchdarkly-js-client-sdk' ;
87import type { Event } from '@sentry/types' ;
98
10- // const MockLaunchDarkly = { //TODO:
9+ // const MockLaunchDarkly = { //TODO: remove in favor of window.MockLaunchDarkly from init.js
1110// initialize(
1211// _clientId: string,
1312// context: LDContext,
1413// options: LDOptions,
1514// ) {
1615// const flagUsedHandler = options?.inspectors?.[0].method;
16+ // const wellTypedHandler = flagUsedHandler as ((
17+ // flagKey: string,
18+ // flagDetail: LDEvaluationDetail,
19+ // context: LDContext,
20+ // ) => void) | undefined;
1721
1822// return {
1923// variation(key: string, defaultValue: LDFlagValue) {
20- // flagUsedHandler ?.(key, { value: defaultValue }, context);
24+ // wellTypedHandler ?.(key, { value: defaultValue }, context);
2125// return defaultValue;
2226// },
2327// };
@@ -44,24 +48,24 @@ sentryTest('e2e test', async ({ getLocalTestPath, page }) => {
4448 await page . goto ( url ) ;
4549
4650 // TODO: could this be in init.js?
47- const ldClient = await page . evaluate ( ( ) => {
48- return ( window as any ) . MockLaunchDarkly . initialize (
49- 'example-client-id' ,
50- { kind : 'user' , key : 'example-context-key' } ,
51- { inspectors : [ buildLaunchDarklyFlagUsedHandler ( ) ] } ,
52- ) as LDClient ;
51+ await page . waitForFunction ( ( ) => {
52+ const ldClient = ( window as any ) . InitializeLD ( ) ;
53+ ldClient . variation ( 'feat1' , false ) ;
54+ ldClient . variation ( 'feat2' , false ) ;
55+ ldClient . variation ( 'feat3' , false ) ;
56+ ldClient . variation ( 'feat2' , true ) ;
57+ return true ;
5358 } ) ;
5459
55- ldClient . variation ( 'feat1' , false ) ;
56- ldClient . variation ( 'feat2' , false ) ;
57- ldClient . variation ( 'feat3' , false ) ;
58- ldClient . variation ( 'feat2' , true ) ;
60+
5961 // TODO: eviction not tested
6062
6163 // trigger error
64+ const reqPromise = waitForErrorRequest ( page ) ;
6265 await page . locator ( '#error' ) . click ( ) ;
66+ const req = await reqPromise ;
6367
64- const req = await waitForErrorRequest ( page ) ;
68+ // console.log(errorEventId );
6569 const event = envelopeRequestParser ( req ) ;
6670
6771 expect ( event . contexts ?. flags ?. values ) . toEqual ( [
0 commit comments