|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | + |
| 3 | +import { sentryTest } from '../../../../../utils/fixtures'; |
| 4 | + |
| 5 | +import { shouldSkipFeatureFlagsTest } from '../../../../../utils/helpers'; |
| 6 | + |
| 7 | +sentryTest('Logs and returns if isEnabled does not match expected signature', async ({ getLocalTestUrl, page }) => { |
| 8 | + if (shouldSkipFeatureFlagsTest()) { |
| 9 | + sentryTest.skip(); |
| 10 | + } |
| 11 | + |
| 12 | + await page.route('https://dsn.ingest.sentry.io/**/*', route => { |
| 13 | + return route.fulfill({ |
| 14 | + status: 200, |
| 15 | + contentType: 'application/json', |
| 16 | + body: JSON.stringify({ id: 'test-id' }), |
| 17 | + }); |
| 18 | + }); |
| 19 | + |
| 20 | + const url = await getLocalTestUrl({ testDir: __dirname, skipDsnRouteHandler: true }); |
| 21 | + await page.goto(url); |
| 22 | + |
| 23 | + const errorLogs: string[] = []; |
| 24 | + page.on('console', msg => { |
| 25 | + if (msg.type() == 'error') { |
| 26 | + errorLogs.push(msg.text()); |
| 27 | + } |
| 28 | + }); |
| 29 | + |
| 30 | + const results = await page.evaluate(() => { |
| 31 | + const unleash = new (window as any).UnleashClient(); |
| 32 | + const res1 = unleash.isEnabled('my-feature'); |
| 33 | + const res2 = unleash.isEnabled(999); |
| 34 | + const res3 = unleash.isEnabled({}); |
| 35 | + return [res1, res2, res3]; |
| 36 | + }); |
| 37 | + |
| 38 | + // Test that the expected results are still returned. Note isEnabled is identity function for this test. |
| 39 | + expect(results).toEqual(['my-feature', 999, {}]); |
| 40 | + |
| 41 | + // Expected error logs. |
| 42 | + expect(errorLogs).toEqual( |
| 43 | + expect.arrayContaining([ |
| 44 | + expect.stringContaining('[Feature Flags] UnleashClient.isEnabled does not match expected signature. arg0: my-feature (string), result: my-feature (string)'), |
| 45 | + expect.stringContaining('[Feature Flags] UnleashClient.isEnabled does not match expected signature. arg0: 999 (number), result: 999 (number)'), |
| 46 | + expect.stringContaining('[Feature Flags] UnleashClient.isEnabled does not match expected signature. arg0: [object Object] (object), result: [object Object] (object)'), |
| 47 | + ]), |
| 48 | + ); |
| 49 | +}); |
0 commit comments