You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2022/11/03 03:56:49 UTC

[GitHub] [superset] zhaoyongjie opened a new pull request, #22015: refactor: Feature flags getter

zhaoyongjie opened a new pull request, #22015:
URL: https://github.com/apache/superset/pull/22015

   ### SUMMARY
   The Feature flags getter has should be returned an explicit boolean value. The unit test makes a minor refactor.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   <!--- Skip this if not applicable -->
   
   ### TESTING INSTRUCTIONS
   <!--- Required! What steps can be taken to manually verify the changes? -->
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] zhaoyongjie merged pull request #22015: refactor: Feature flags getter

Posted by GitBox <gi...@apache.org>.
zhaoyongjie merged PR #22015:
URL: https://github.com/apache/superset/pull/22015


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] codecov[bot] commented on pull request #22015: refactor: Feature flags getter

Posted by GitBox <gi...@apache.org>.
codecov[bot] commented on PR #22015:
URL: https://github.com/apache/superset/pull/22015#issuecomment-1301638578

   # [Codecov](https://codecov.io/gh/apache/superset/pull/22015?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#22015](https://codecov.io/gh/apache/superset/pull/22015?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (febbdc6) into [master](https://codecov.io/gh/apache/superset/commit/429f246f7a740cc3230491042f74fe5266c03c37?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (429f246) will **increase** coverage by `0.00%`.
   > The diff coverage is `100.00%`.
   
   ```diff
   @@           Coverage Diff           @@
   ##           master   #22015   +/-   ##
   =======================================
     Coverage   65.76%   65.77%           
   =======================================
     Files        1813     1813           
     Lines       69437    69423   -14     
     Branches     7450     7448    -2     
   =======================================
   - Hits        45667    45662    -5     
   + Misses      21850    21841    -9     
     Partials     1920     1920           
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | javascript | `53.50% <100.00%> (+<0.01%)` | :arrow_up: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   | [Impacted Files](https://codecov.io/gh/apache/superset/pull/22015?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...ackages/superset-ui-core/src/utils/featureFlags.ts](https://codecov.io/gh/apache/superset/pull/22015/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQtZnJvbnRlbmQvcGFja2FnZXMvc3VwZXJzZXQtdWktY29yZS9zcmMvdXRpbHMvZmVhdHVyZUZsYWdzLnRz) | `100.00% <100.00%> (ø)` | |
   | [superset-frontend/src/utils/downloadAsImage.ts](https://codecov.io/gh/apache/superset/pull/22015/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL3V0aWxzL2Rvd25sb2FkQXNJbWFnZS50cw==) | `11.11% <0.00%> (-4.68%)` | :arrow_down: |
   | [...perset-frontend/src/addSlice/AddSliceContainer.tsx](https://codecov.io/gh/apache/superset/pull/22015/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL2FkZFNsaWNlL0FkZFNsaWNlQ29udGFpbmVyLnRzeA==) | `59.61% <0.00%> (ø)` | |
   | [...d/src/filters/components/Time/TimeFilterPlugin.tsx](https://codecov.io/gh/apache/superset/pull/22015/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL2ZpbHRlcnMvY29tcG9uZW50cy9UaW1lL1RpbWVGaWx0ZXJQbHVnaW4udHN4) | `0.00% <0.00%> (ø)` | |
   | [...ore/components/controls/DateFilterControl/types.ts](https://codecov.io/gh/apache/superset/pull/22015/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL2V4cGxvcmUvY29tcG9uZW50cy9jb250cm9scy9EYXRlRmlsdGVyQ29udHJvbC90eXBlcy50cw==) | `100.00% <0.00%> (ø)` | |
   | [...ents/controls/DateFilterControl/utils/constants.ts](https://codecov.io/gh/apache/superset/pull/22015/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL2V4cGxvcmUvY29tcG9uZW50cy9jb250cm9scy9EYXRlRmlsdGVyQ29udHJvbC91dGlscy9jb25zdGFudHMudHM=) | `100.00% <0.00%> (ø)` | |
   | [...nts/controls/DateFilterControl/DateFilterLabel.tsx](https://codecov.io/gh/apache/superset/pull/22015/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL2V4cGxvcmUvY29tcG9uZW50cy9jb250cm9scy9EYXRlRmlsdGVyQ29udHJvbC9EYXRlRmlsdGVyTGFiZWwudHN4) | `58.13% <0.00%> (+1.95%)` | :arrow_up: |
   | [superset-frontend/src/utils/common.js](https://codecov.io/gh/apache/superset/pull/22015/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL3V0aWxzL2NvbW1vbi5qcw==) | `100.00% <0.00%> (+10.00%)` | :arrow_up: |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] zhaoyongjie commented on a diff in pull request #22015: refactor: Feature flags getter

Posted by GitBox <gi...@apache.org>.
zhaoyongjie commented on code in PR #22015:
URL: https://github.com/apache/superset/pull/22015#discussion_r1012577085


##########
superset-frontend/packages/superset-ui-core/test/utils/featureFlag.test.ts:
##########
@@ -16,48 +16,41 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
-import { FeatureFlag, isFeatureEnabled } from '@superset-ui/core';
-
-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;
-};
+import mockConsole from 'jest-mock-console';
+import { isFeatureEnabled, FeatureFlag } from '@superset-ui/core';
 
 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)',
+  mockConsole();
+  Object.defineProperty(window, 'featureFlags', {
+    value: undefined,
+  });
+
+  expect(
+    isFeatureEnabled(FeatureFlag.ALLOW_DASHBOARD_DOMAIN_SHARDING),
+  ).toBeFalsy();

Review Comment:
   Good point. I mistakenly thought that `toBeFalsy()` is a shortcut for `toEqual(false)`. will update



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] villebro commented on a diff in pull request #22015: refactor: Feature flags getter

Posted by GitBox <gi...@apache.org>.
villebro commented on code in PR #22015:
URL: https://github.com/apache/superset/pull/22015#discussion_r1012567730


##########
superset-frontend/packages/superset-ui-core/test/utils/featureFlag.test.ts:
##########
@@ -16,48 +16,41 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
-import { FeatureFlag, isFeatureEnabled } from '@superset-ui/core';
-
-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;
-};
+import mockConsole from 'jest-mock-console';
+import { isFeatureEnabled, FeatureFlag } from '@superset-ui/core';
 
 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)',
+  mockConsole();
+  Object.defineProperty(window, 'featureFlags', {
+    value: undefined,
+  });
+
+  expect(
+    isFeatureEnabled(FeatureFlag.ALLOW_DASHBOARD_DOMAIN_SHARDING),
+  ).toBeFalsy();
+  expect(console.error).toHaveBeenCalled();
+  // @ts-expect-error
+  expect(console.error.mock.calls[0][0]).toEqual(
+    'Failed to query feature flag ALLOW_DASHBOARD_DOMAIN_SHARDING',
   );
-
-  reset();
 });
 
 it('returns false for unset feature flag', () => {
-  expect(isFeatureEnabled(FeatureFlag.ALLOW_DASHBOARD_DOMAIN_SHARDING)).toEqual(
-    false,
-  );
+  Object.defineProperty(window, 'featureFlags', {
+    value: {},
+  });
 
-  reset();
+  expect(
+    isFeatureEnabled(FeatureFlag.ALLOW_DASHBOARD_DOMAIN_SHARDING),
+  ).toBeFalsy();

Review Comment:
   same here



##########
superset-frontend/packages/superset-ui-core/test/utils/featureFlag.test.ts:
##########
@@ -16,48 +16,41 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
-import { FeatureFlag, isFeatureEnabled } from '@superset-ui/core';
-
-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;
-};
+import mockConsole from 'jest-mock-console';
+import { isFeatureEnabled, FeatureFlag } from '@superset-ui/core';
 
 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)',
+  mockConsole();
+  Object.defineProperty(window, 'featureFlags', {
+    value: undefined,
+  });
+
+  expect(
+    isFeatureEnabled(FeatureFlag.ALLOW_DASHBOARD_DOMAIN_SHARDING),
+  ).toBeFalsy();

Review Comment:
   If we're expecting a `boolean` value (which this PR is making more specific), I'd prefer to make the assertion more specific, too:
   ```suggestion
     expect(
       isFeatureEnabled(FeatureFlag.ALLOW_DASHBOARD_DOMAIN_SHARDING),
     ).toEqual(false);
   ```



##########
superset-frontend/packages/superset-ui-core/test/utils/featureFlag.test.ts:
##########
@@ -16,48 +16,41 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
-import { FeatureFlag, isFeatureEnabled } from '@superset-ui/core';
-
-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;
-};
+import mockConsole from 'jest-mock-console';
+import { isFeatureEnabled, FeatureFlag } from '@superset-ui/core';
 
 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)',
+  mockConsole();
+  Object.defineProperty(window, 'featureFlags', {
+    value: undefined,
+  });
+
+  expect(
+    isFeatureEnabled(FeatureFlag.ALLOW_DASHBOARD_DOMAIN_SHARDING),
+  ).toBeFalsy();
+  expect(console.error).toHaveBeenCalled();
+  // @ts-expect-error
+  expect(console.error.mock.calls[0][0]).toEqual(
+    'Failed to query feature flag ALLOW_DASHBOARD_DOMAIN_SHARDING',
   );
-
-  reset();
 });
 
 it('returns false for unset feature flag', () => {
-  expect(isFeatureEnabled(FeatureFlag.ALLOW_DASHBOARD_DOMAIN_SHARDING)).toEqual(
-    false,
-  );
+  Object.defineProperty(window, 'featureFlags', {
+    value: {},
+  });
 
-  reset();
+  expect(
+    isFeatureEnabled(FeatureFlag.ALLOW_DASHBOARD_DOMAIN_SHARDING),
+  ).toBeFalsy();
 });
 
 it('returns true for set feature flag', () => {
-  window.featureFlags = {
-    [FeatureFlag.CLIENT_CACHE]: true,
-  };
+  Object.defineProperty(window, 'featureFlags', {
+    value: {
+      CLIENT_CACHE: true,
+    },
+  });
 
-  expect(isFeatureEnabled(FeatureFlag.CLIENT_CACHE)).toEqual(true);
-  reset();
+  expect(isFeatureEnabled(FeatureFlag.CLIENT_CACHE)).toBeTruthy();

Review Comment:
   and here



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org