Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Fix flaky SDK tests (#64699)

Mahatthana (Kelvin) Nomsawadi0ab2b9f4f698
diff --git a/e2e/runner/cypress-runner-backend.js b/e2e/runner/cypress-runner-backend.js
index c8c940aa61e..cf9650cf032 100755
--- a/e2e/runner/cypress-runner-backend.js
+++ b/e2e/runner/cypress-runner-backend.js
@@ -49,6 +49,7 @@ const CypressBackend = {
MB_DB_CONNECTION_URI: "", // ignore connection URI in favor of the db file
MB_CONFIG_FILE_PATH: "__cypress__", // ignore config.yml
MB_HTTP_CHANNEL_HOST_STRATEGY: "allow-all", // we use a local webhook service for testing
+ MB_IS_CYPRESS: "true", // custom flag so we can detect we're running in Cypress, used in tests.
};
/**
diff --git a/e2e/test-component/scenarios/embedding-sdk/sdk-bundle.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/sdk-bundle.cy.spec.tsx
index 5da03975f75..c15e637ca6f 100644
--- a/e2e/test-component/scenarios/embedding-sdk/sdk-bundle.cy.spec.tsx
+++ b/e2e/test-component/scenarios/embedding-sdk/sdk-bundle.cy.spec.tsx
@@ -192,10 +192,15 @@ describe(
it("should show a custom loader when the SDK bundle is loading", () => {
sdkBundleCleanup();
+ const MINUTE = 60 * 1000;
cy.intercept("GET", "/api/card/*", (request) => {
- // Delay request for 500ms to avoid flakiness
+ /**
+ * Delay request for 10 min to avoid flakiness. We don't need the request to return, since we're testing the loading state.
+ * From observing the failed test log, it failed at 10.9s, and the timeout for finding the loading indicator was set to 10s.
+ * That means, Cypress started looking for the loading indicator after ~0.9s of the request being delayed.
+ */
request.continue(
- () => new Promise((resolve) => setTimeout(resolve, 500)),
+ () => new Promise((resolve) => setTimeout(resolve, 10 * MINUTE)),
);
});
diff --git a/src/metabase/server/middleware/embedding_sdk_bundle.clj b/src/metabase/server/middleware/embedding_sdk_bundle.clj
index ea04377baf1..47a8df18a14 100644
--- a/src/metabase/server/middleware/embedding_sdk_bundle.clj
+++ b/src/metabase/server/middleware/embedding_sdk_bundle.clj
@@ -36,6 +36,7 @@
(fn [request]
(let [base (response/resource-response bundle-resource)]
(cond
- (nil? base) (not-found)
- config/is-prod? (serve-for-prod base request)
- :else (serve-for-dev base)))))
+ (nil? base) (not-found)
+ (config/config-bool :mb-is-cypress) (serve-for-dev base)
+ config/is-prod? (serve-for-prod base request)
+ :else (serve-for-dev base)))))