|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | + |
| 3 | +import { sentryTest } from '../../../../../utils/fixtures'; |
| 4 | + |
| 5 | +import { envelopeRequestParser, shouldSkipFeatureFlagsTest, waitForErrorRequest } from '../../../../../utils/helpers'; |
| 6 | + |
| 7 | +const FLAG_BUFFER_SIZE = 100; // Corresponds to constant in featureFlags.ts, in browser utils. |
| 8 | + |
| 9 | +sentryTest('Basic test with eviction, update, and no async tasks', async ({ getLocalTestUrl, page }) => { |
| 10 | + if (shouldSkipFeatureFlagsTest()) { |
| 11 | + sentryTest.skip(); |
| 12 | + } |
| 13 | + |
| 14 | + await page.route('https://dsn.ingest.sentry.io/**/*', route => { |
| 15 | + return route.fulfill({ |
| 16 | + status: 200, |
| 17 | + contentType: 'application/json', |
| 18 | + body: JSON.stringify({ id: 'test-id' }), |
| 19 | + }); |
| 20 | + }); |
| 21 | + |
| 22 | + const url = await getLocalTestUrl({ testDir: __dirname, skipDsnRouteHandler: true }); |
| 23 | + await page.goto(url); |
| 24 | + |
| 25 | + await page.evaluate(bufferSize => { |
| 26 | + const client = new (window as any).UnleashClient(); |
| 27 | + |
| 28 | + client.isEnabled('feat1'); |
| 29 | + client.isEnabled('strFeat'); |
| 30 | + client.isEnabled('noPayloadFeat'); |
| 31 | + client.isEnabled('jsonFeat'); |
| 32 | + client.isEnabled('noVariantFeat'); |
| 33 | + client.isEnabled('disabledFeat'); |
| 34 | + |
| 35 | + for (let i = 7; i <= bufferSize; i++) { |
| 36 | + client.isEnabled(`feat${i}`); |
| 37 | + } |
| 38 | + client.isEnabled(`feat${bufferSize + 1}`); // eviction |
| 39 | + client.isEnabled('noPayloadFeat'); // update (move to tail) |
| 40 | + }, FLAG_BUFFER_SIZE); |
| 41 | + |
| 42 | + const reqPromise = waitForErrorRequest(page); |
| 43 | + await page.locator('#error').click(); |
| 44 | + const req = await reqPromise; |
| 45 | + const event = envelopeRequestParser(req); |
| 46 | + |
| 47 | + const expectedFlags = [{ flag: 'strFeat', result: true }]; |
| 48 | + expectedFlags.push({ flag: 'jsonFeat', result: true }); |
| 49 | + expectedFlags.push({ flag: 'noVariantFeat', result: true }); |
| 50 | + expectedFlags.push({ flag: 'disabledFeat', result: false }); |
| 51 | + for (let i = 7; i <= FLAG_BUFFER_SIZE; i++) { |
| 52 | + expectedFlags.push({ flag: `feat${i}`, result: false }); |
| 53 | + } |
| 54 | + expectedFlags.push({ flag: `feat${FLAG_BUFFER_SIZE + 1}`, result: false }); |
| 55 | + expectedFlags.push({ flag: 'noPayloadFeat', result: true }); |
| 56 | + |
| 57 | + expect(event.contexts?.flags?.values).toEqual(expectedFlags); |
| 58 | +}); |
0 commit comments