Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix console errors about feature flags when running tests #21275

Merged
merged 2 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,45 @@

import { FeatureFlag, isFeatureEnabled } from '@superset-ui/core';

describe('isFeatureFlagEnabled', () => {
const originalFeatureFlags = window.featureFlags;
// eslint-disable-next-line no-console
const originalConsoleError = console.error;
const reset = () => {
window.featureFlags = originalFeatureFlags;
// eslint-disable-next-line no-console
console.error = originalConsoleError;
};

it('returns false and raises console error if feature flags have not been initialized', () => {
// eslint-disable-next-line no-console
console.error = jest.fn();
delete (window as any).featureFlags;
expect(isFeatureEnabled(FeatureFlag.ALLOW_DASHBOARD_DOMAIN_SHARDING)).toEqual(
false,
);

// eslint-disable-next-line no-console
expect(console.error).toHaveBeenNthCalledWith(
1,
'Failed to query feature flag ALLOW_DASHBOARD_DOMAIN_SHARDING (see error below)',
);

reset();
});

it('returns false for unset feature flag', () => {
expect(isFeatureEnabled(FeatureFlag.ALLOW_DASHBOARD_DOMAIN_SHARDING)).toEqual(
false,
);

reset();
});

it('returns true for set feature flag', () => {
window.featureFlags = {
[FeatureFlag.CLIENT_CACHE]: true,
};
it('returns false for unset feature flag', () => {
expect(
isFeatureEnabled(FeatureFlag.ALLOW_DASHBOARD_DOMAIN_SHARDING),
).toEqual(false);
});

it('returns true for set feature flag', () => {
expect(isFeatureEnabled(FeatureFlag.CLIENT_CACHE)).toEqual(true);
});

expect(isFeatureEnabled(FeatureFlag.CLIENT_CACHE)).toEqual(true);
reset();
});
1 change: 1 addition & 0 deletions superset-frontend/spec/helpers/shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ g.window.performance = { now: () => new Date().getTime() };
g.window.Worker = Worker;
g.window.IntersectionObserver = IntersectionObserver;
g.window.ResizeObserver = ResizeObserver;
g.window.featureFlags = {};
g.URL.createObjectURL = () => '';
g.caches = new CacheStorage();

Expand Down