Skip to content

Commit 3b784a6

Browse files
committed
Skip CDN bundle tests, fix unit test, un-export FLAG_BUFFER_SIZE, update lockfile
1 parent b1cb0a5 commit 3b784a6

File tree

8 files changed

+6015
-10482
lines changed

8 files changed

+6015
-10482
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ import { expect } from '@playwright/test';
22

33
import { sentryTest } from '../../../../../utils/fixtures';
44

5-
import { envelopeRequestParser, waitForErrorRequest } from '../../../../../utils/helpers';
6-
import { FLAG_BUFFER_SIZE } from '@sentry/browser';
5+
import { envelopeRequestParser, shouldSkipLaunchDarklyTest, waitForErrorRequest } from '../../../../../utils/helpers';
6+
7+
const FLAG_BUFFER_SIZE = 100; // Corresponds to constant in featureFlags.ts, in browser utils.
78

89
sentryTest('Basic test with eviction, update, and no async tasks', async ({ getLocalTestPath, page }) => {
10+
if (shouldSkipLaunchDarklyTest()) {
11+
sentryTest.skip();
12+
}
13+
914
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
1015
return route.fulfill({
1116
status: 200,

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ import { expect } from '@playwright/test';
22

33
import { sentryTest } from '../../../../../utils/fixtures';
44

5-
import { envelopeRequestParser, waitForErrorRequest } from '../../../../../utils/helpers';
5+
import { envelopeRequestParser, shouldSkipLaunchDarklyTest, waitForErrorRequest } from '../../../../../utils/helpers';
66

77
import type { Scope } from '@sentry/browser';
88

99
sentryTest('Flag evaluations in forked scopes are stored separately.', async ({ getLocalTestPath, page }) => {
10+
if (shouldSkipLaunchDarklyTest()) {
11+
sentryTest.skip();
12+
}
13+
1014
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
1115
return route.fulfill({
1216
status: 200,

dev-packages/browser-integration-tests/utils/helpers.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,18 @@ export function shouldSkipMetricsTest(): boolean {
273273
return bundle != null && !bundle.includes('tracing') && !bundle.includes('esm') && !bundle.includes('cjs');
274274
}
275275

276+
/**
277+
* We can only test the launchdarkly browser integration in certain bundles/packages:
278+
* - NPM (ESM, CJS)
279+
* - Not CDNs.
280+
*
281+
* @returns `true` if we should skip the launchdarkly test
282+
*/
283+
export function shouldSkipLaunchDarklyTest(): boolean {
284+
const bundle = process.env.PW_BUNDLE as string | undefined;
285+
return bundle != null && !bundle.includes('esm') && !bundle.includes('cjs');
286+
}
287+
276288
/**
277289
* Waits until a number of requests matching urlRgx at the given URL arrive.
278290
* If the timeout option is configured, this function will abort waiting, even if it hasn't received the configured

packages/browser/src/exports.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,3 @@ export { linkedErrorsIntegration } from './integrations/linkederrors';
100100
export { browserApiErrorsIntegration } from './integrations/browserapierrors';
101101

102102
export { lazyLoadIntegration } from './utils/lazyLoadIntegration';
103-
export { launchDarklyIntegration, buildLaunchDarklyFlagUsedHandler } from './integrations/featureFlags/launchdarkly';
104-
export { FLAG_BUFFER_SIZE } from './utils/featureFlags';

packages/browser/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,4 @@ export type { Span } from '@sentry/types';
7575
export { makeBrowserOfflineTransport } from './transports/offline';
7676
export { browserProfilingIntegration } from './profiling/integration';
7777
export { spotlightBrowserIntegration } from './integrations/spotlight';
78+
export { launchDarklyIntegration, buildLaunchDarklyFlagUsedHandler } from './integrations/featureFlags/launchdarkly';

packages/browser/src/utils/featureFlags.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function insertToFlagBuffer(
3434
maxSize: number = FLAG_BUFFER_SIZE,
3535
): void {
3636
if (flags.length > maxSize) {
37-
DEBUG_BUILD && logger.error(`insertToFlagBuffer called on a buffer larger than the given maxSize=${maxSize}`);
37+
DEBUG_BUILD && logger.error(`[Feature Flags] insertToFlagBuffer called on a buffer larger than maxSize=${maxSize}`);
3838
return;
3939
}
4040

packages/browser/test/utils/featureFlags.test.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11

2+
import { logger } from '@sentry/utils';
23
import { insertToFlagBuffer } from '../../src/utils/featureFlags';
34
import type { FeatureFlag } from '@sentry/types';
5+
import { vi } from 'vitest';
46

57
describe('flags', () => {
68
describe('insertToFlagBuffer()', () => {
9+
const loggerSpy = vi.spyOn(logger, 'error');
10+
11+
afterEach(() => {
12+
loggerSpy.mockClear();
13+
});
14+
715
it('maintains ordering and evicts the oldest entry', () => {
816
const buffer: FeatureFlag[] = [];
917
const maxSize = 3;
@@ -47,14 +55,29 @@ describe('flags', () => {
4755
]);
4856
});
4957

50-
it('errors when maxSize is less than current buffer size', () => {
58+
it('logs error and is a no-op when buffer is larger than maxSize', () => {
5159
const buffer: FeatureFlag[] = [
5260
{ flag: 'feat1', result: true },
5361
{ flag: 'feat2', result: true },
5462
];
5563

56-
expect(() => insertToFlagBuffer(buffer, 'feat1', true, 1)).toThrowError();
57-
expect(() => insertToFlagBuffer(buffer, 'feat1', true, -2)).toThrowError();
64+
insertToFlagBuffer(buffer, 'feat1', true, 1);
65+
expect(loggerSpy).toHaveBeenCalledWith(
66+
expect.stringContaining('[Feature Flags] insertToFlagBuffer called on a buffer larger than maxSize'),
67+
);
68+
expect(buffer).toEqual([
69+
{ flag: 'feat1', result: true },
70+
{ flag: 'feat2', result: true },
71+
]);
72+
73+
insertToFlagBuffer(buffer, 'feat1', true, -2);
74+
expect(loggerSpy).toHaveBeenCalledWith(
75+
expect.stringContaining('[Feature Flags] insertToFlagBuffer called on a buffer larger than maxSize'),
76+
);
77+
expect(buffer).toEqual([
78+
{ flag: 'feat1', result: true },
79+
{ flag: 'feat2', result: true },
80+
]);
5881
});
5982
})
6083
})

0 commit comments

Comments
 (0)