You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2024/08/14 03:36:12 UTC

(superset) branch fixing-flaky-test-1 updated: fix(cypress): fixing a flaky test

This is an automated email from the ASF dual-hosted git repository.

rusackas pushed a commit to branch fixing-flaky-test-1
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/fixing-flaky-test-1 by this push:
     new 0090a2d3bf fix(cypress): fixing a flaky test
0090a2d3bf is described below

commit 0090a2d3bfa5d3a394d8a5d20a7b784a9f5e8185
Author: Evan Rusackas <ev...@rusackas.com>
AuthorDate: Tue Aug 13 21:36:02 2024 -0600

    fix(cypress): fixing a flaky test
---
 package-lock.json                                  | 26 +++++++++++++++++++++
 package.json                                       |  5 ++++
 .../cypress/e2e/dashboard/nativeFilters.test.ts    | 27 +++++++++++++++++++---
 .../cypress-base/cypress/support/commands.ts       | 20 ++++++++++++++++
 .../cypress-base/cypress/support/e2e.ts            |  2 ++
 superset-frontend/cypress-base/tsconfig.json       |  2 +-
 6 files changed, 78 insertions(+), 4 deletions(-)

diff --git a/package-lock.json b/package-lock.json
new file mode 100644
index 0000000000..14269556f5
--- /dev/null
+++ b/package-lock.json
@@ -0,0 +1,26 @@
+{
+  "name": "superset",
+  "lockfileVersion": 2,
+  "requires": true,
+  "packages": {
+    "": {
+      "devDependencies": {
+        "cypress-wait-until": "^3.0.2"
+      }
+    },
+    "node_modules/cypress-wait-until": {
+      "version": "3.0.2",
+      "resolved": "https://registry.npmjs.org/cypress-wait-until/-/cypress-wait-until-3.0.2.tgz",
+      "integrity": "sha512-iemies796dD5CgjG5kV0MnpEmKSH+s7O83ZoJLVzuVbZmm4lheMsZqAVT73hlMx4QlkwhxbyUzhOBUOZwoOe0w==",
+      "dev": true
+    }
+  },
+  "dependencies": {
+    "cypress-wait-until": {
+      "version": "3.0.2",
+      "resolved": "https://registry.npmjs.org/cypress-wait-until/-/cypress-wait-until-3.0.2.tgz",
+      "integrity": "sha512-iemies796dD5CgjG5kV0MnpEmKSH+s7O83ZoJLVzuVbZmm4lheMsZqAVT73hlMx4QlkwhxbyUzhOBUOZwoOe0w==",
+      "dev": true
+    }
+  }
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000000..efc3d0f464
--- /dev/null
+++ b/package.json
@@ -0,0 +1,5 @@
+{
+  "devDependencies": {
+    "cypress-wait-until": "^3.0.2"
+  }
+}
diff --git a/superset-frontend/cypress-base/cypress/e2e/dashboard/nativeFilters.test.ts b/superset-frontend/cypress-base/cypress/e2e/dashboard/nativeFilters.test.ts
index f2e88b1390..09ed109bad 100644
--- a/superset-frontend/cypress-base/cypress/e2e/dashboard/nativeFilters.test.ts
+++ b/superset-frontend/cypress-base/cypress/e2e/dashboard/nativeFilters.test.ts
@@ -415,15 +415,23 @@ describe('Native filters', () => {
     });
 
     it('Verify that default value is respected after revisit', () => {
+      // Intercept the API call that fetches chart data
+      cy.intercept('GET', '**/api/v1/chart/data*').as('chartData');
+
       prepareDashboardFilters([
         { name: 'country_name', column: 'country_name', datasetId: 2 },
       ]);
       enterNativeFilterEditModal();
       inputNativeFilterDefaultValue(testItems.filterDefaultValue);
       saveNativeFilterSettings([SAMPLE_CHART]);
+
+      // Wait for chart data to load
+      cy.wait('@chartData');
+
       cy.get(nativeFilters.filterItem)
         .contains(testItems.filterDefaultValue)
         .should('be.visible');
+
       cy.get(dataTestChartName(testItems.topTenChart.name)).within(() => {
         cy.contains(testItems.filterDefaultValue).should('be.visible');
         cy.contains(testItems.filterOtherCountry).should('not.exist');
@@ -431,10 +439,23 @@ describe('Native filters', () => {
 
       // reload dashboard
       cy.reload();
-      cy.get(dataTestChartName(testItems.topTenChart.name)).within(() => {
-        cy.contains(testItems.filterDefaultValue).should('be.visible');
-        cy.contains(testItems.filterOtherCountry).should('not.exist');
+
+      // Wait for dashboard to load after reload
+      cy.get('[data-test="dashboard-grid"]', { timeout: 30000 }).should(
+        'be.visible',
+      );
+
+      // Wait for chart data to load again
+      cy.wait('@chartData');
+
+      // Use a custom command to retry assertions
+      cy.retryAssertion(() => {
+        cy.get(dataTestChartName(testItems.topTenChart.name)).within(() => {
+          cy.contains(testItems.filterDefaultValue).should('be.visible');
+          cy.contains(testItems.filterOtherCountry).should('not.exist');
+        });
       });
+
       validateFilterContentOnDashboard(testItems.filterDefaultValue);
     });
 
diff --git a/superset-frontend/cypress-base/cypress/support/commands.ts b/superset-frontend/cypress-base/cypress/support/commands.ts
new file mode 100644
index 0000000000..c2f1170b75
--- /dev/null
+++ b/superset-frontend/cypress-base/cypress/support/commands.ts
@@ -0,0 +1,20 @@
+/// <reference types="cypress" />
+
+declare namespace Cypress {
+  interface Chainable {
+    retryAssertion(
+      assertionFn: () => void,
+      options?: Partial<Cypress.WaitUntilOptions>,
+    ): Chainable<any>;
+  }
+}
+
+Cypress.Commands.add('retryAssertion', (assertionFn, options = {}) => {
+  const defaultOptions: Cypress.WaitUntilOptions = {
+    timeout: 10000,
+    interval: 1000,
+  };
+  const opts = { ...defaultOptions, ...options };
+
+  return cy.waitUntil(assertionFn, opts);
+});
diff --git a/superset-frontend/cypress-base/cypress/support/e2e.ts b/superset-frontend/cypress-base/cypress/support/e2e.ts
index 6556d8e5eb..17cd342c27 100644
--- a/superset-frontend/cypress-base/cypress/support/e2e.ts
+++ b/superset-frontend/cypress-base/cypress/support/e2e.ts
@@ -19,6 +19,8 @@
 import '@cypress/code-coverage/support';
 import '@applitools/eyes-cypress/commands';
 import failOnConsoleError from 'cypress-fail-on-console-error';
+import './commands';
+import 'cypress-wait-until';
 
 /* eslint-disable @typescript-eslint/no-explicit-any */
 
diff --git a/superset-frontend/cypress-base/tsconfig.json b/superset-frontend/cypress-base/tsconfig.json
index 9249195c0c..7d97459b20 100644
--- a/superset-frontend/cypress-base/tsconfig.json
+++ b/superset-frontend/cypress-base/tsconfig.json
@@ -6,7 +6,7 @@
     "strict": true,
     "target": "es2019",
     "lib": ["es2019", "DOM"],
-    "types": ["cypress", "@applitools/eyes-cypress", "node"],
+    "types": ["cypress", "@applitools/eyes-cypress", "node", "cypress-wait-until"],
     "allowJs": true,
     "noEmit": true
   },