Skip to content

Commit 969c5c0

Browse files
committed
Fix playwright tests
1 parent 7e24158 commit 969c5c0

File tree

3 files changed

+42
-14
lines changed
  • dev-packages/browser-integration-tests/suites/integrations/featureFlags/launchdarkly

3 files changed

+42
-14
lines changed

dev-packages/browser-integration-tests/suites/integrations/featureFlags/launchdarkly/init.js renamed to dev-packages/browser-integration-tests/suites/integrations/featureFlags/launchdarkly/basic/init.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,10 @@ const MockLaunchDarkly = {
2727
},
2828
};
2929

30-
window.ldClient = undefined;
31-
3230
window.initializeLD = () => {
33-
window.ldClient = MockLaunchDarkly.initialize(
31+
return MockLaunchDarkly.initialize(
3432
'example-client-id',
3533
{ kind: 'user', key: 'example-context-key' },
3634
{ inspectors: [buildLaunchDarklyFlagUsedHandler()] },
3735
);
38-
return window.ldClient;
3936
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import * as Sentry from '@sentry/browser';
2+
import { launchDarklyIntegration, buildLaunchDarklyFlagUsedHandler } from '@sentry/browser';
3+
4+
window.Sentry = Sentry;
5+
window.sentryLDIntegration = launchDarklyIntegration();
6+
7+
Sentry.init({
8+
dsn: 'https://[email protected]/1337',
9+
sampleRate: 1.0,
10+
integrations: [window.sentryLDIntegration],
11+
});
12+
13+
// Manually mocking this because LD only has mock test utils for the React SDK.
14+
// Also, no SDK has mock utils for FlagUsedHandler's.
15+
const MockLaunchDarkly = {
16+
initialize(_clientId, context, options) {
17+
const flagUsedHandler = (options && options.inspectors) ? options.inspectors[0].method : undefined;
18+
19+
return {
20+
variation(key, defaultValue) {
21+
if (flagUsedHandler) {
22+
flagUsedHandler(key, { value: defaultValue }, context);
23+
}
24+
return defaultValue;
25+
},
26+
};
27+
},
28+
};
29+
30+
window.initializeLD = () => {
31+
return MockLaunchDarkly.initialize(
32+
'example-client-id',
33+
{ kind: 'user', key: 'example-context-key' },
34+
{ inspectors: [buildLaunchDarklyFlagUsedHandler()] },
35+
);
36+
};

dev-packages/browser-integration-tests/suites/integrations/featureFlags/launchdarkly/withScope/test.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@ sentryTest('Flag evaluations in forked scopes are stored separately.', async ({
2121
const forkedReqPromise = waitForErrorRequest(page, event => !!event.tags && event.tags.isForked === true);
2222
const mainReqPromise = waitForErrorRequest(page, event => !!event.tags && event.tags.isForked === false);
2323

24-
const hasButton = await page.evaluate(() => {
24+
await page.waitForFunction(() => {
2525
const Sentry = (window as any).Sentry;
26-
const errorButton = document.querySelector('#error');
27-
if (!(errorButton instanceof HTMLButtonElement)) {
28-
return false;
29-
}
26+
const errorButton = document.querySelector('#error') as HTMLButtonElement;
3027
const ldClient = (window as any).initializeLD();
3128

3229
ldClient.variation('shared', true);
@@ -35,7 +32,9 @@ sentryTest('Flag evaluations in forked scopes are stored separately.', async ({
3532
ldClient.variation('forked', true);
3633
ldClient.variation('shared', false);
3734
scope.setTag('isForked', true);
38-
errorButton.click();
35+
if (errorButton) {
36+
errorButton.click();
37+
}
3938
});
4039

4140
ldClient.variation('main', true);
@@ -44,10 +43,6 @@ sentryTest('Flag evaluations in forked scopes are stored separately.', async ({
4443
return true;
4544
});
4645

47-
if (!hasButton) {
48-
throw new Error('Expected template to have a button that throws an error')
49-
}
50-
5146
const forkedReq = await forkedReqPromise;
5247
const forkedEvent = envelopeRequestParser(forkedReq);
5348

0 commit comments

Comments
 (0)