|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | +import { _INTERNAL_FLAG_BUFFER_SIZE as FLAG_BUFFER_SIZE } from '@sentry/core'; |
| 3 | +import { sentryTest } from '../../../../../../utils/fixtures'; |
| 4 | +import { |
| 5 | + envelopeRequestParser, |
| 6 | + shouldSkipFeatureFlagsTest, |
| 7 | + waitForErrorRequest, |
| 8 | +} from '../../../../../../utils/helpers'; |
| 9 | + |
| 10 | +sentryTest('GrowthBook onError: basic eviction/update and no async tasks', async ({ getLocalTestUrl, page }) => { |
| 11 | + if (shouldSkipFeatureFlagsTest()) { |
| 12 | + sentryTest.skip(); |
| 13 | + } |
| 14 | + |
| 15 | + await page.route('https://dsn.ingest.sentry.io/**/*', route => { |
| 16 | + return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ id: 'test-id' }) }); |
| 17 | + }); |
| 18 | + |
| 19 | + const url = await getLocalTestUrl({ testDir: __dirname, skipDsnRouteHandler: true }); |
| 20 | + await page.goto(url); |
| 21 | + |
| 22 | + await page.evaluate(bufferSize => { |
| 23 | + const gb = new (window as any).GrowthBook(); |
| 24 | + |
| 25 | + for (let i = 1; i <= bufferSize; i++) { |
| 26 | + gb.isOn(`feat${i}`); |
| 27 | + } |
| 28 | + |
| 29 | + gb.__setOn(`feat${bufferSize + 1}`, true); |
| 30 | + gb.isOn(`feat${bufferSize + 1}`); // eviction |
| 31 | + |
| 32 | + gb.__setOn('feat3', true); |
| 33 | + gb.isOn('feat3'); // update |
| 34 | + |
| 35 | + // Test getFeatureValue with boolean values (should be captured) |
| 36 | + gb.__setFeatureValue('bool-feat', true); |
| 37 | + gb.getFeatureValue('bool-feat', false); |
| 38 | + |
| 39 | + // Test getFeatureValue with non-boolean values (should be ignored) |
| 40 | + gb.__setFeatureValue('string-feat', 'hello'); |
| 41 | + gb.getFeatureValue('string-feat', 'default'); |
| 42 | + gb.__setFeatureValue('number-feat', 42); |
| 43 | + gb.getFeatureValue('number-feat', 0); |
| 44 | + }, FLAG_BUFFER_SIZE); |
| 45 | + |
| 46 | + const reqPromise = waitForErrorRequest(page); |
| 47 | + await page.locator('#error').click(); |
| 48 | + const req = await reqPromise; |
| 49 | + const event = envelopeRequestParser(req); |
| 50 | + |
| 51 | + const values = event.contexts?.flags?.values || []; |
| 52 | + |
| 53 | + // After the sequence of operations: |
| 54 | + // 1. feat1-feat100 are added (100 items) |
| 55 | + // 2. feat101 is added, evicts feat1 (100 items: feat2-feat100, feat101) |
| 56 | + // 3. feat3 is updated to true, moves to end (100 items: feat2, feat4-feat100, feat101, feat3) |
| 57 | + // 4. bool-feat is added, evicts feat2 (100 items: feat4-feat100, feat101, feat3, bool-feat) |
| 58 | + |
| 59 | + const expectedFlags = []; |
| 60 | + for (let i = 4; i <= FLAG_BUFFER_SIZE; i++) { |
| 61 | + expectedFlags.push({ flag: `feat${i}`, result: false }); |
| 62 | + } |
| 63 | + expectedFlags.push({ flag: `feat${FLAG_BUFFER_SIZE + 1}`, result: true }); |
| 64 | + expectedFlags.push({ flag: 'feat3', result: true }); |
| 65 | + expectedFlags.push({ flag: 'bool-feat', result: true }); // Only boolean getFeatureValue should be captured |
| 66 | + |
| 67 | + expect(values).toEqual(expectedFlags); |
| 68 | +}); |
0 commit comments