Skip to content

Commit 776bb58

Browse files
committed
Add badSignature test
1 parent bba93f7 commit 776bb58

File tree

3 files changed

+66
-1
lines changed
  • dev-packages/browser-integration-tests/suites/integrations/featureFlags/unleash/badSignature
  • packages/browser/src/integrations/featureFlags/unleash

3 files changed

+66
-1
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.UnleashClient = class {
4+
isEnabled(x) {
5+
return x;
6+
}
7+
};
8+
9+
window.Sentry = Sentry;
10+
window.sentryUnleashIntegration = Sentry.unleashIntegration({unleashClientClass: window.UnleashClient});
11+
12+
Sentry.init({
13+
dsn: 'https://[email protected]/1337',
14+
sampleRate: 1.0,
15+
integrations: [window.sentryUnleashIntegration],
16+
debug: true, // Required to test logging.
17+
});
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
});

packages/browser/src/integrations/featureFlags/unleash/integration.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ function _wrappedIsEnabled(original: (this: UnleashClient, ...args: unknown[]) =
6161
if (typeof toggleName === 'string' && typeof result === 'boolean') {
6262
insertFlagToScope(toggleName, result);
6363
} else {
64-
// TODO: test this branch
6564
logger.error(`[Feature Flags] UnleashClient.isEnabled does not match expected signature. arg0: ${toggleName} (${typeof toggleName}), result: ${result} (${typeof result})`);
6665
}
6766
return result;

0 commit comments

Comments
 (0)