Skip to content

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

De-clutter the Cypress (nodejs) Module runner (#65881)

Nemanja Glumac248a95e70402
diff --git a/.github/workflows/e2e-component-tests-embedding-sdk-backward-compatibility.yml b/.github/workflows/e2e-component-tests-embedding-sdk-backward-compatibility.yml
index edeb510586b..1c8fb060896 100644
--- a/.github/workflows/e2e-component-tests-embedding-sdk-backward-compatibility.yml
+++ b/.github/workflows/e2e-component-tests-embedding-sdk-backward-compatibility.yml
@@ -137,13 +137,16 @@ jobs:
run: node e2e/runner/run_cypress_ci.js start
- name: Make app db snapshot
- run: node e2e/runner/run_cypress_ci.js snapshot --browser ${{ steps.cypress-prep.outputs.chrome-path }}
+ env:
+ CYPRESS_BROWSER: ${{ steps.cypress-prep.outputs.chrome-path }}
+ run: node e2e/runner/run_cypress_ci.js snapshot
- name: Run component tests for Embedding SDK
+ env:
+ CYPRESS_BROWSER: ${{ steps.cypress-prep.outputs.chrome-path }}
run: |
node e2e/runner/run_cypress_ci.js component \
- --browser ${{ steps.cypress-prep.outputs.chrome-path }} \
- --env grepTags="-@skip-backward-compatibility",grepOmitFiltered=true
+ --env grepTags="-@skip-backward-compatibility"
- name: Upload Test Results
uses: ./.github/actions/upload-test-results
diff --git a/.github/workflows/e2e-component-tests-embedding-sdk.yml b/.github/workflows/e2e-component-tests-embedding-sdk.yml
index e90f12aac86..6723a06a852 100644
--- a/.github/workflows/e2e-component-tests-embedding-sdk.yml
+++ b/.github/workflows/e2e-component-tests-embedding-sdk.yml
@@ -154,14 +154,18 @@ jobs:
run: node e2e/runner/run_cypress_ci.js start
- name: Make app db snapshot
- run: node e2e/runner/run_cypress_ci.js snapshot --browser ${{ steps.cypress-prep.outputs.chrome-path }}
+ env:
+ CYPRESS_BROWSER: ${{ steps.cypress-prep.outputs.chrome-path }}
+ run: node e2e/runner/run_cypress_ci.js snapshot
# Has to be run after the app db snapshot is made, as it is not compatible with React 19
- name: Change React version to ${{ matrix.react-version }}
run: ./bin/embedding-sdk/change-react-version.bash ${{ matrix.react-version }}
- name: Run component tests for Embedding SDK
- run: node e2e/runner/run_cypress_ci.js component --browser ${{ steps.cypress-prep.outputs.chrome-path }}
+ env:
+ CYPRESS_BROWSER: ${{ steps.cypress-prep.outputs.chrome-path }}
+ run: node e2e/runner/run_cypress_ci.js component
- name: Upload Test Results
uses: ./.github/actions/upload-test-results
diff --git a/.github/workflows/e2e-embedding-sdk-compatibility-tests.yml b/.github/workflows/e2e-embedding-sdk-compatibility-tests.yml
index 1ddf0271195..3afce27bbe1 100644
--- a/.github/workflows/e2e-embedding-sdk-compatibility-tests.yml
+++ b/.github/workflows/e2e-embedding-sdk-compatibility-tests.yml
@@ -298,7 +298,9 @@ jobs:
id: run-e2e-tests
if: ${{ steps.check-sample-app-branch.outputs.sample_app_branch_exists == 'true' }}
continue-on-error: true
- run: node e2e/runner/run_cypress_ci.js ${{ matrix.test_suite }} --browser ${{ steps.cypress-prep.outputs.chrome-path }}
+ env:
+ CYPRESS_BROWSER: ${{ steps.cypress-prep.outputs.chrome-path }}
+ run: node e2e/runner/run_cypress_ci.js ${{ matrix.test_suite }}
- name: Upload Cypress Artifacts upon failure
uses: actions/upload-artifact@v4
@@ -392,7 +394,9 @@ jobs:
- name: Run e2e tests for Host App
id: run-e2e-tests
continue-on-error: true
- run: node e2e/runner/run_cypress_ci.js ${{ matrix.test_suite }} --browser ${{ steps.cypress-prep.outputs.chrome-path }}
+ env:
+ CYPRESS_BROWSER: ${{ steps.cypress-prep.outputs.chrome-path }}
+ run: node e2e/runner/run_cypress_ci.js ${{ matrix.test_suite }}
- name: Upload Cypress Artifacts upon failure
uses: actions/upload-artifact@v4
diff --git a/.github/workflows/e2e-stress-test-flake-fix.yml b/.github/workflows/e2e-stress-test-flake-fix.yml
index 2971760246f..b06dc09c096 100644
--- a/.github/workflows/e2e-stress-test-flake-fix.yml
+++ b/.github/workflows/e2e-stress-test-flake-fix.yml
@@ -37,26 +37,26 @@ on:
default: true
jobs:
- determine-suite:
- name: Determine test suite
+ determine-test-type:
+ name: Determine test type
runs-on: ubuntu-22.04
timeout-minutes: 5
outputs:
- suite: ${{ steps.detect.outputs.suite }}
+ type: ${{ steps.detect.outputs.type }}
steps:
- - name: Detect suite from spec path
+ - name: Detect test type from spec path
id: detect
run: |
SPEC='${{ inputs.spec }}'
if [[ "$SPEC" == e2e/test-component/scenarios/embedding-sdk/* ]]; then
- echo "suite=component" >> $GITHUB_OUTPUT
+ echo "type=component" >> $GITHUB_OUTPUT
else
- echo "suite=e2e" >> $GITHUB_OUTPUT
+ echo "type=e2e" >> $GITHUB_OUTPUT
fi
workflow-summary:
name: Stress test inputs
- needs: [determine-suite]
+ needs: [determine-test-type]
runs-on: ubuntu-22.04
timeout-minutes: 5
steps:
@@ -66,7 +66,7 @@ jobs:
echo '' >> $GITHUB_STEP_SUMMARY
echo '- `branch`: ${{ github.ref_name }}' >> $GITHUB_STEP_SUMMARY
echo '- `spec`: ${{ inputs.spec }}' >> $GITHUB_STEP_SUMMARY
- echo '- `test_suite` (inferred): ${{ needs.determine-suite.outputs.suite }}' >> $GITHUB_STEP_SUMMARY
+ echo '- `test_type` (inferred): ${{ needs.determine-test-type.outputs.type }}' >> $GITHUB_STEP_SUMMARY
echo '- `burn_in`: ${{ inputs.burn_in }}' >> $GITHUB_STEP_SUMMARY
echo '- `grep`: "${{ inputs.grep }}"' >> $GITHUB_STEP_SUMMARY
echo '- `qa_db`: "${{ inputs.qa_db }}"' >> $GITHUB_STEP_SUMMARY
@@ -75,7 +75,7 @@ jobs:
echo 'triggered by: @${{ github.event.sender.login }}' >> $GITHUB_STEP_SUMMARY
stress-test-flake-fix:
- needs: [determine-suite]
+ needs: [determine-test-type]
runs-on: ubuntu-22.04
timeout-minutes: 60
name: Stress test E2E flake fix
@@ -122,12 +122,12 @@ jobs:
uses: ./.github/actions/prepare-frontend
- name: Prepare back-end environment
- if: ${{ needs.determine-suite.outputs.suite == 'component' }}
+ if: ${{ needs.determine-test-type.outputs.type == 'component' }}
uses: ./.github/actions/prepare-backend
with:
m2-cache-key: "cljs"
- name: Build Embedding SDK package
- if: ${{ needs.determine-suite.outputs.suite == 'component' }}
+ if: ${{ needs.determine-test-type.outputs.type == 'component' }}
run: yarn build-embedding-sdk-package
- name: Prepare JDK 21
@@ -148,12 +148,12 @@ jobs:
- name: Stress-test ${{ github.event.inputs.spec }} ${{ github.event.inputs.burn_in }} times
env:
GREP: ${{ github.event.inputs.grep }}
+ CYPRESS_BROWSER: ${{ steps.cypress-prep.outputs.chrome-path }}
run: |
- node e2e/runner/run_cypress_ci.js ${{ needs.determine-suite.outputs.suite }} \
+ node e2e/runner/run_cypress_ci.js ${{ needs.determine-test-type.outputs.type }} \
--spec '${{ github.event.inputs.spec }}' \
--env burn=${{ github.event.inputs.burn_in }} \
- --config-file e2e/support/cypress-stress-test.config.js \
- --browser ${{ steps.cypress-prep.outputs.chrome-path }}
+ --config-file e2e/support/cypress-stress-test.config.js
- name: Upload Cypress Artifacts upon failure
uses: actions/upload-artifact@v4
diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml
index 3e3e4544cad..865f41d23aa 100644
--- a/.github/workflows/e2e-test.yml
+++ b/.github/workflows/e2e-test.yml
@@ -120,6 +120,8 @@ jobs:
run: node e2e/runner/run_cypress_ci.js start
- name: Generate database snapshots
+ env:
+ CYPRESS_BROWSER: ${{ steps.cypress-prep.outputs.chrome-path }}
run: node e2e/runner/run_cypress_ci.js snapshot
- name: Run auto-split Cypress tests on ${{ inputs.name }}
@@ -133,13 +135,13 @@ jobs:
# do not write cypress-split summary to github
SPLIT_SUMMARY: false
SPEC_PATH: ${{ env.specs || inputs.specs }}
+ CYPRESS_BROWSER: ${{ steps.cypress-prep.outputs.chrome-path }}
shell: bash
run: |
echo "Running tests with specs: $SPEC_PATH"
node e2e/runner/run_cypress_ci.js e2e \
- --env grepTags="-@mongo+-@python+-@OSS+-@skip",grepOmitFiltered=true \
- --spec "$SPEC_PATH" \
- --browser ${{ steps.cypress-prep.outputs.chrome-path }}
+ --env grepTags="-@mongo+-@python+-@OSS+-@skip" \
+ --spec "$SPEC_PATH"
# Trunk Quarantine controls the final state of the run in the CI!
# Even if this step fails we let it pass, and then `trunk-io/analytics-uploader` determines
# whether to fail or to pass the whole job, based on the quarantine list.
@@ -150,12 +152,12 @@ jobs:
shell: bash
env:
SPEC_PATH: ${{ env.specs || inputs.specs }}
+ CYPRESS_BROWSER: ${{ steps.cypress-prep.outputs.chrome-path }}
run: |
echo "Running tests with specs: $SPEC_PATH"
node e2e/runner/run_cypress_ci.js e2e \
- --env grepTags="${{inputs.tags && format('{0}+-@skip', inputs.tags) || '-@skip'}}",grepOmitFiltered=true \
- --spec "$SPEC_PATH" \
- --browser ${{ steps.cypress-prep.outputs.chrome-path }}
+ --env grepTags="${{inputs.tags && format('{0}+-@skip', inputs.tags) || '-@skip'}}" \
+ --spec "$SPEC_PATH"
# Trunk Quarantine controls the final state of the run in the CI!
# Even if this step fails we let it pass, and then `trunk-io/analytics-uploader` determines
# whether to fail or to pass the whole job, based on the quarantine list.
diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml
index e04203d4baa..bf6ad4cfd70 100644
--- a/.github/workflows/pre-release.yml
+++ b/.github/workflows/pre-release.yml
@@ -194,19 +194,21 @@ jobs:
- name: Run a few important OSS Cypress tests as sanity check
if: ${{ matrix.edition == 'oss' }}
+ env:
+ CYPRESS_BROWSER: ${{ steps.cypress-prep.outputs.chrome-path }}
run: |
node e2e/runner/run_cypress_ci.js e2e \
- --env grepTags="@smoke+-@EE",grepOmitFiltered=true \
- --spec './e2e/test/scenarios/**/*.cy.spec.(js|ts)' \
- --browser ${{ steps.cypress-prep.outputs.chrome-path }}
+ --env grepTags="@smoke+-@EE" \
+ --spec './e2e/test/scenarios/**/*.cy.spec.(js|ts)'
- name: Run a few important EE Cypress tests as sanity check
if: ${{ matrix.edition == 'ee' }}
+ env:
+ CYPRESS_BROWSER: ${{ steps.cypress-prep.outputs.chrome-path }}
run: |
node e2e/runner/run_cypress_ci.js e2e \
- --env grepTags="@smoke+-@OSS",grepOmitFiltered=true \
- --spec './e2e/test/scenarios/**/*.cy.spec.(js|ts)' \
- --browser ${{ steps.cypress-prep.outputs.chrome-path }}
+ --env grepTags="@smoke+-@OSS" \
+ --spec './e2e/test/scenarios/**/*.cy.spec.(js|ts)'
- name: Upload Cypress Artifacts upon failure
uses: actions/upload-artifact@v4
diff --git a/e2e/runner/constants/backend-port.js b/e2e/runner/constants/backend-port.js
index a084b8e3038..e95a74c20d4 100644
--- a/e2e/runner/constants/backend-port.js
+++ b/e2e/runner/constants/backend-port.js
@@ -1 +1,3 @@
-export const BACKEND_PORT = process.env.BACKEND_PORT ?? 4000;
+export const BACKEND_HOST = process.env.MB_JETTY_HOST || "localhost";
+export const BACKEND_PORT =
+ process.env.MB_JETTY_PORT || process.env.BACKEND_PORT || 4000;
diff --git a/e2e/runner/cypress-node-js-runner.js b/e2e/runner/cypress-node-js-runner.js
new file mode 100644
index 00000000000..eb87b2f2181
--- /dev/null
+++ b/e2e/runner/cypress-node-js-runner.js
@@ -0,0 +1,40 @@
+const cypress = require("cypress");
+
+const { FAILURE_EXIT_CODE } = require("./constants/exit-code");
+
+/**
+ * This simply runs Cypress through the Cypress Module API rather than the CLI.
+ * See: https://docs.cypress.io/app/references/module-api
+ *
+ * @param {Partial<CypressCommandLine.CypressRunOptions> | Partial<CypressCommandLine.CypressOpenOptions>} options - Cypress configuration options for running or opening tests
+ * @param {function(number): Promise<void>} exitFunction - Async function to call on exit with the exit code
+ * @returns {Promise<CypressCommandLine.CypressRunResult | CypressCommandLine.CypressFailedRunResult | void>}
+ * @throws {Error} When Cypress fails to run tests
+ */
+const runCypress = async (options, exitFunction) => {
+ const openMode = process.env.OPEN_UI === "true";
+
+ try {
+ const { status, message, totalFailed, failures } = openMode
+ ? await cypress.open(options)
+ : await cypress.run(options);
+
+ // At least one test failed
+ if (totalFailed > 0) {
+ await exitFunction(FAILURE_EXIT_CODE);
+ }
+
+ // Something went wrong and Cypress failed to even run tests
+ if (status === "failed" && failures) {
+ console.error(message);
+
+ await exitFunction(failures);
+ }
+ } catch (e) {
+ console.error("Failed to run Cypress!\n", e);
+
+ await exitFunction(FAILURE_EXIT_CODE);
+ }
+};
+
+module.exports = runCypress;
diff --git a/e2e/runner/cypress-runner-backend.js b/e2e/runner/cypress-runner-backend.js
index 7298a98aea5..bd605828163 100755
--- a/e2e/runner/cypress-runner-backend.js
+++ b/e2e/runner/cypress-runner-backend.js
@@ -6,18 +6,18 @@ const http = require("http");
const os = require("os");
const path = require("path");
+const { BACKEND_HOST, BACKEND_PORT } = require("./constants/backend-port");
const { delay } = require("./cypress-runner-utils");
const CypressBackend = {
server: null,
- createServer(port = process.env.BACKEND_PORT || 4000) {
+ createServer(port = BACKEND_PORT) {
const generateTempDbPath = () =>
path.join(os.tmpdir(), `metabase-test-${process.pid}.db`);
const server = {
dbFile: generateTempDbPath(),
host: `http://localhost:${port}`,
- port,
};
this.server = server;
@@ -41,8 +41,8 @@ const CypressBackend = {
const metabaseConfig = {
MB_DB_TYPE: "h2",
MB_DB_FILE: this.server.dbFile,
- MB_JETTY_HOST: "0.0.0.0",
- MB_JETTY_PORT: this.server.port,
+ MB_JETTY_HOST: BACKEND_HOST,
+ MB_JETTY_PORT: BACKEND_PORT,
MB_ENABLE_TEST_ENDPOINTS: "true",
MB_DANGEROUS_UNSAFE_ENABLE_TESTING_H2_CONNECTIONS_DO_NOT_ENABLE: "true",
MB_LAST_ANALYTICS_CHECKSUM: "-1",
diff --git a/e2e/runner/cypress-runner-run-tests.js b/e2e/runner/cypress-runner-run-tests.js
deleted file mode 100644
index 5fbdbff7360..00000000000
--- a/e2e/runner/cypress-runner-run-tests.js
+++ /dev/null
@@ -1,174 +0,0 @@
-const cypress = require("cypress");
-
-const { BACKEND_PORT } = require("./constants/backend-port");
-const { FAILURE_EXIT_CODE } = require("./constants/exit-code");
-const { parseArguments, args } = require("./cypress-runner-utils");
-const {
- HOST_APP_SETUP_CONFIGS,
-} = require("./embedding-sdk/host-apps/constants/host-app-setup-configs");
-const {
- SAMPLE_APP_SETUP_CONFIGS,
-} = require("./embedding-sdk/sample-apps/constants/sample-app-setup-configs");
-
-const getHost = (port = BACKEND_PORT) => `http://localhost:${port}`;
-
-const getEmbeddingSdkAppE2eConfig = async ({
- baseUrl,
- env,
- project,
- specPattern,
-}) => {
- process.env = {
- ...process.env,
- ...env,
- };
-
- const defaultConfig = {
- browser: process.env.CYPRESS_BROWSER ?? "chrome",
- project,
- configFile: "e2e/support/cypress.config.js",
- config: {
- baseUrl,
- specPattern,
- env,
- },
- testingType: "e2e",
- openMode: args["--open"] || process.env.OPEN_UI === "true",
- };
-
- const userArgs = await parseArguments(args);
-
- return Object.assign({}, defaultConfig, userArgs);
-};
-
-const getSampleAppE2eConfig = (suite) => ({
- [suite]: async () => {
- const { appName, env } = SAMPLE_APP_SETUP_CONFIGS[suite];
- const { CLIENT_PORT } = env;
-
- return getEmbeddingSdkAppE2eConfig({
- // If the `clientPort` is not set, it means we have multiple apps running on different ports,
- // so we control the `baseUrl` based on other `env` variables on the Sample App tests level.
- baseUrl: CLIENT_PORT ? getHost(CLIENT_PORT) : "",
- env,
- project: ["e2e/tmp", appName].join("/"),
- });
- },
-});
-
-const getHostAppE2eConfig = (suite) => ({
- [suite]: async () => {
- const { appName, env } = HOST_APP_SETUP_CONFIGS[suite];
-
- return getEmbeddingSdkAppE2eConfig({
- baseUrl: getHost(),
- env,
- specPattern: [
- "e2e/test-host-app/shared/**/*.cy.spec.{js,ts}",
- ["e2e/test-host-app", appName, "**/*.cy.spec.{js,ts}"].join("/"),
- ],
- });
- },
-});
-
-// This is a map of all possible Cypress configurations we can run.
-const configs = {
- e2e: async () => {
- const defaultConfig = {
- browser: process.env.CYPRESS_BROWSER ?? "chrome",
- configFile: "e2e/support/cypress.config.js",
- config: {
- baseUrl: getHost(),
- },
- testingType: "e2e",
- openMode: args["--open"] || process.env.OPEN_UI === "true",
- };
-
- const userArgs = await parseArguments(args);
-
- const finalConfig = Object.assign({}, defaultConfig, userArgs);
- return finalConfig;
- },
- ...getSampleAppE2eConfig("metabase-nodejs-react-sdk-embedding-sample-e2e"),
- ...getSampleAppE2eConfig("metabase-nextjs-sdk-embedding-sample-e2e"),
- ...getSampleAppE2eConfig("shoppy-e2e"),
- ...getHostAppE2eConfig("vite-6-host-app-e2e"),
- ...getHostAppE2eConfig("next-15-app-router-host-app-e2e"),
- ...getHostAppE2eConfig("next-15-pages-router-host-app-e2e"),
- ...getHostAppE2eConfig("angular-20-host-app-e2e"),
- snapshot: async () => {
- // We only ever care about a browser out of all possible user arguments,
- // when it comes to the snapshot generation.
- // Anything else could result either in a failure or in a wrong database snapshot!
- const { browser } = await parseArguments(args);
-
- const snapshotConfig = {
- browser: browser ?? process.env.CYPRESS_BROWSER ?? "chrome",
- configFile: "e2e/support/cypress-snapshots.config.js",
- config: {
- baseUrl: getHost(),
- },
- testingType: "e2e",
- openMode: false,
- };
-
- return snapshotConfig;
- },
- component: async () => {
- const { browser } = await parseArguments(args);
-
- const sdkComponentConfig = {
- browser: browser ?? process.env.CYPRESS_BROWSER ?? "chrome",
- configFile: "e2e/support/cypress-embedding-sdk-component-test.config.js",
- config: {
- baseUrl: getHost(),
- },
- testingType: "component",
- openMode: args["--open"] || process.env.OPEN_UI === "true",
- };
-
- const userArgs = await parseArguments(args);
-
- const finalConfig = Object.assign({}, sdkComponentConfig, userArgs);
- return finalConfig;
- },
-};
-
-/**
- * This simply runs cypress through the javascript API rather than the CLI, and
- * lets us conditionally load a config file and some other options along with it.
- */
-const runCypress = async (suite = "e2e", exitFunction) => {
- if (!configs[suite]) {
- console.error(
- `Invalid suite: ${suite}, try one of: ${Object.keys(configs)}`,
- );
- await exitFunction(FAILURE_EXIT_CODE);
- }
-
- const config = await configs[suite]();
-
- try {
- const { status, message, totalFailed, failures } = config.openMode
- ? await cypress.open(config)
- : await cypress.run(config);
-
- // At least one test failed
- if (totalFailed > 0) {
- await exitFunction(FAILURE_EXIT_CODE);
- }
-
- // Something went wrong and Cypress failed to even run tests
- if (status === "failed" && failures) {
- console.error(message);
-
- await exitFunction(failures);
- }
- } catch (e) {
- console.error("Failed to run Cypress!\n", e);
-
- await exitFunction(FAILURE_EXIT_CODE);
- }
-};
-
-module.exports = runCypress;
diff --git a/e2e/runner/cypress-runner-utils.js b/e2e/runner/cypress-runner-utils.js
index a584a74d6da..27fdeb19678 100644
--- a/e2e/runner/cypress-runner-utils.js
+++ b/e2e/runner/cypress-runner-utils.js
@@ -1,6 +1,5 @@
const { execSync, spawn } = require("child_process");
-const arg = require("arg");
const chalk = require("chalk");
const cypress = require("cypress");
@@ -8,16 +7,7 @@ function printBold(message) {
console.log(`\n${chalk.bold(chalk.magenta(message.trim()))}\n`);
}
-const args = arg(
- {
- "--open": [Boolean], // Run Cypress in open mode or not? Doesn't accept additional arguments
- },
- { permissive: true }, // Passes all other flags and args to the Cypress parser
-);
-
-async function parseArguments(args) {
- const cliArgs = args._;
-
+async function parseArguments(cliArgs) {
// cypress.cli.parseArguments requires `cypress run` as the first two arguments
if (cliArgs[0] !== "cypress") {
cliArgs.unshift("cypress");
@@ -92,7 +82,6 @@ function delay(durationMs) {
}
module.exports = {
- args,
booleanify,
unBooleanify,
parseArguments,
diff --git a/e2e/runner/resolve-sdk-e2e-config.js b/e2e/runner/resolve-sdk-e2e-config.js
new file mode 100644
index 00000000000..f7be3a1cde8
--- /dev/null
+++ b/e2e/runner/resolve-sdk-e2e-config.js
@@ -0,0 +1,81 @@
+const { BACKEND_PORT } = require("./constants/backend-port");
+const {
+ HOST_APP_SETUP_CONFIGS,
+} = require("./embedding-sdk/host-apps/constants/host-app-setup-configs");
+const {
+ SAMPLE_APP_SETUP_CONFIGS,
+} = require("./embedding-sdk/sample-apps/constants/sample-app-setup-configs");
+
+const getHost = (port = BACKEND_PORT) => `http://localhost:${port}`;
+
+const getEmbeddingSdkAppE2eConfig = ({
+ baseUrl,
+ env,
+ project,
+ specPattern,
+}) => {
+ process.env = {
+ ...process.env,
+ ...env,
+ };
+
+ return {
+ project,
+ configFile: "e2e/support/cypress.config.js",
+ config: {
+ baseUrl,
+ specPattern,
+ env,
+ },
+ };
+};
+
+const getSampleAppE2eConfig = (suite) => ({
+ [suite]: () => {
+ const { appName, env } = SAMPLE_APP_SETUP_CONFIGS[suite];
+ const { CLIENT_PORT } = env;
+
+ return getEmbeddingSdkAppE2eConfig({
+ // If the `clientPort` is not set, it means we have multiple apps running on different ports,
+ // so we control the `baseUrl` based on other `env` variables on the Sample App tests level.
+ baseUrl: CLIENT_PORT ? getHost(CLIENT_PORT) : "",
+ env,
+ project: ["e2e/tmp", appName].join("/"),
+ });
+ },
+});
+
+const getHostAppE2eConfig = (suite) => ({
+ [suite]: () => {
+ const { env } = HOST_APP_SETUP_CONFIGS[suite];
+
+ return getEmbeddingSdkAppE2eConfig({
+ baseUrl: getHost(),
+ env,
+ specPattern: "e2e/test-host-app/shared/**/*.cy.spec.{js,ts}",
+ });
+ },
+});
+
+// This is a map of all possible custom SDK configurations we can run.
+const configs = {
+ ...getSampleAppE2eConfig("metabase-nodejs-react-sdk-embedding-sample-e2e"),
+ ...getSampleAppE2eConfig("metabase-nextjs-sdk-embedding-sample-e2e"),
+ ...getSampleAppE2eConfig("shoppy-e2e"),
+ ...getHostAppE2eConfig("vite-6-host-app-e2e"),
+ ...getHostAppE2eConfig("next-15-app-router-host-app-e2e"),
+ ...getHostAppE2eConfig("next-15-pages-router-host-app-e2e"),
+ ...getHostAppE2eConfig("angular-20-host-app-e2e"),
+};
+
+const resolveSdkE2EConfig = (suite) => {
+ if (!configs[suite]) {
+ throw new Error(
+ `Invalid suite: ${suite}, try one of: ${Object.keys(configs)}`,
+ );
+ }
+
+ return configs[suite]();
+};
+
+module.exports = { resolveSdkE2EConfig };
diff --git a/e2e/runner/run_cypress_ci.js b/e2e/runner/run_cypress_ci.js
index 89ae3317ca2..06e50204a5a 100755
--- a/e2e/runner/run_cypress_ci.js
+++ b/e2e/runner/run_cypress_ci.js
@@ -1,14 +1,15 @@
const { FAILURE_EXIT_CODE } = require("./constants/exit-code");
+const runCypress = require("./cypress-node-js-runner");
const CypressBackend = require("./cypress-runner-backend");
-const runCypress = require("./cypress-runner-run-tests");
-const { printBold } = require("./cypress-runner-utils");
+const { parseArguments, printBold } = require("./cypress-runner-utils");
+const { resolveSdkE2EConfig } = require("./resolve-sdk-e2e-config");
-const modeOrTestSuite = process.argv?.[2]?.trim();
+const command = process.argv?.[2]?.trim();
+const cliArguments = process.argv.slice(3);
const availableModes = ["start", "snapshot"];
-const availableTestSuites = [
- "e2e",
- "component",
+const availableTestingTypes = ["e2e", "component"];
+const availableSDKTestSuites = [
"metabase-nodejs-react-sdk-embedding-sample-e2e",
"metabase-nextjs-sdk-embedding-sample-e2e",
"shoppy-e2e",
@@ -18,11 +19,14 @@ const availableTestSuites = [
"angular-20-host-app-e2e",
];
-if (
- !availableModes.includes(modeOrTestSuite) &&
- !availableTestSuites.includes(modeOrTestSuite)
-) {
- console.error(`Invalid mode or test suite: ${modeOrTestSuite}`);
+const permittedCommands = [
+ ...availableModes,
+ ...availableTestingTypes,
+ ...availableSDKTestSuites,
+];
+
+if (!permittedCommands.includes(command)) {
+ console.error(`Invalid command: ${command}`);
process.exit(FAILURE_EXIT_CODE);
}
@@ -31,13 +35,34 @@ const startServer = async () => {
await CypressBackend.start();
};
-const runTests = async (testSuite) => {
- printBold(`Running ${testSuite} Cypress Tests`);
- await runCypress(testSuite, process.exit);
+const runTests = async (config, cliArguments = []) => {
+ const userOverrides = await parseArguments(cliArguments);
+ await runCypress({ ...config, ...userOverrides }, process.exit);
};
-if (modeOrTestSuite === "start") {
+// Custom "modes"
+if (command === "start") {
startServer();
-} else {
- runTests(modeOrTestSuite);
+}
+
+if (command === "snapshot") {
+ runTests({ configFile: "e2e/support/cypress-snapshots.config.js" });
+}
+
+// Metabase component or e2e tests
+if (command === "component") {
+ runTests({
+ configFile: "e2e/support/cypress-embedding-sdk-component-test.config.js",
+ testingType: "component",
+ });
+}
+
+if (command === "e2e") {
+ runTests({ configFile: "e2e/support/cypress.config.js" }, cliArguments);
+}
+
+// Custom SDK Host/Sample App e2e tests
+if (availableSDKTestSuites.includes(command)) {
+ const config = resolveSdkE2EConfig(command);
+ runTests(config);
}
diff --git a/e2e/runner/run_cypress_local.ts b/e2e/runner/run_cypress_local.ts
index 1af12e0ceab..7be7f46ae8f 100644
--- a/e2e/runner/run_cypress_local.ts
+++ b/e2e/runner/run_cypress_local.ts
@@ -2,27 +2,31 @@ import fs from "fs";
import os from "os";
import path from "path";
+import { BACKEND_PORT } from "./constants/backend-port";
import { FAILURE_EXIT_CODE, SUCCESS_EXIT_CODE } from "./constants/exit-code";
+import runCypress from "./cypress-node-js-runner";
import CypressBackend from "./cypress-runner-backend";
-import runCypress from "./cypress-runner-run-tests";
import {
booleanify,
+ parseArguments,
printBold,
shell,
unBooleanify,
} from "./cypress-runner-utils";
import { startHostAppContainers } from "./embedding-sdk/host-apps/start-host-app-containers";
import { startSampleAppContainers } from "./embedding-sdk/sample-apps/start-sample-app-containers";
+import { resolveSdkE2EConfig } from "./resolve-sdk-e2e-config";
let tempSampleDBDir: string | null = null;
// if you want to change these, set them as environment variables in your shell
const userOptions = {
- TEST_SUITE: "e2e", // e2e | component
+ CYPRESS_TESTING_TYPE: "e2e", // e2e | component
+ SDK_TEST_SUITE: undefined, // one of the many sample-app, or host-app Embedding SDK suites
MB_EDITION: "ee", // ee | oss
START_CONTAINERS: true,
STOP_CONTAINERS: false,
- BACKEND_PORT: 4000,
+ BACKEND_PORT: BACKEND_PORT, // override with MB_JETTY_PORT in your env
OPEN_UI: true,
SHOW_BACKEND_LOGS: false,
GENERATE_SNAPSHOTS: true,
@@ -61,20 +65,24 @@ if (options.MB_EDITION === "ee" && missingTokens.length > 0) {
}
printBold(`Running Cypress with options:
- - TEST_SUITE : ${options.TEST_SUITE}
- - MB_EDITION : ${options.MB_EDITION}
- - START_CONTAINERS : ${options.START_CONTAINERS}
- - STOP_CONTAINERS : ${options.STOP_CONTAINERS}
- - BUILD_JAR : ${options.BUILD_JAR}
- - GENERATE_SNAPSHOTS : ${options.GENERATE_SNAPSHOTS}
- - BACKEND_PORT : ${options.BACKEND_PORT}
- - START_BACKEND : ${options.START_BACKEND}
- - OPEN_UI : ${options.OPEN_UI}
- - SHOW_BACKEND_LOGS : ${options.SHOW_BACKEND_LOGS}
- - TZ : ${options.TZ}
+ - CYPRESS_TESTING_TYPE : ${options.CYPRESS_TESTING_TYPE}
+ - SDK_TEST_SUITE : ${options.SDK_TEST_SUITE}
+ - MB_EDITION : ${options.MB_EDITION}
+ - START_CONTAINERS : ${options.START_CONTAINERS}
+ - STOP_CONTAINERS : ${options.STOP_CONTAINERS}
+ - BUILD_JAR : ${options.BUILD_JAR}
+ - GENERATE_SNAPSHOTS : ${options.GENERATE_SNAPSHOTS}
+ - BACKEND_PORT : ${options.BACKEND_PORT}
+ - START_BACKEND : ${options.START_BACKEND}
+ - OPEN_UI : ${options.OPEN_UI}
+ - SHOW_BACKEND_LOGS : ${options.SHOW_BACKEND_LOGS}
+ - TZ : ${options.TZ}
`);
const init = async () => {
+ const cliArguments = process.argv.slice(2);
+ const userOverrides = await parseArguments(cliArguments);
+
if (options.START_CONTAINERS) {
printBold("⏳ Starting containers");
shell("docker compose -f ./e2e/test/scenarios/docker-compose.yml up -d");
@@ -121,37 +129,64 @@ const init = async () => {
// reset cache
shell("rm -f e2e/support/cypress_sample_instance_data.json");
- printBold("⏳ Generating snapshots");
- await runCypress("snapshot", cleanup);
+ printBold("⏳ Generating app db snapshots");
+ process.env.OPEN_UI = "false";
+ await runCypress(
+ { configFile: "e2e/support/cypress-snapshots.config.js" },
+ cleanup,
+ );
+ process.env.OPEN_UI = `${options.OPEN_UI}`;
} else {
printBold("Skipping snapshot generation, beware of stale snapshot caches");
shell("echo 'Existing snapshots:' && ls -1 e2e/snapshots");
}
const isFrontendRunning = shell("lsof -ti:8080 || echo ''", { quiet: true });
- if (!isFrontendRunning && options.TEST_SUITE === "e2e") {
+ if (!isFrontendRunning && options.CYPRESS_TESTING_TYPE === "e2e") {
printBold(
"⚠️⚠️ You don't have your frontend running. You should probably run yarn build-hot ⚠️⚠️",
);
}
- switch (options.TEST_SUITE) {
- case "metabase-nodejs-react-sdk-embedding-sample-e2e":
- case "metabase-nextjs-sdk-embedding-sample-e2e":
- case "shoppy-e2e":
- await startSampleAppContainers(options.TEST_SUITE);
- break;
-
- case "vite-6-host-app-e2e":
- case "next-15-app-router-host-app-e2e":
- case "next-15-pages-router-host-app-e2e":
- case "angular-20-host-app-e2e":
- await startHostAppContainers(options.TEST_SUITE);
- break;
+ if (options.SDK_TEST_SUITE) {
+ switch (options.SDK_TEST_SUITE) {
+ case "metabase-nodejs-react-sdk-embedding-sample-e2e":
+ case "metabase-nextjs-sdk-embedding-sample-e2e":
+ case "shoppy-e2e":
+ await startSampleAppContainers(options.SDK_TEST_SUITE);
+ break;
+
+ case "vite-6-host-app-e2e":
+ case "next-15-app-router-host-app-e2e":
+ case "next-15-pages-router-host-app-e2e":
+ case "angular-20-host-app-e2e":
+ await startHostAppContainers(options.SDK_TEST_SUITE);
+ break;
+ }
+
+ printBold("⏳ Starting Sample/Host App Cypress Tests");
+ const config = resolveSdkE2EConfig(options.SDK_TEST_SUITE);
+ await runCypress(config, cleanup);
}
- printBold("⏳ Starting Cypress");
- await runCypress(options.TEST_SUITE, cleanup);
+ if (options.CYPRESS_TESTING_TYPE === "component") {
+ printBold("⏳ Starting Cypress SDK component tests");
+ await runCypress(
+ {
+ configFile:
+ "e2e/support/cypress-embedding-sdk-component-test.config.js",
+ testingType: "component",
+ },
+ cleanup,
+ );
+ }
+
+ if (options.CYPRESS_TESTING_TYPE === "e2e") {
+ const config = { configFile: "e2e/support/cypress.config.js" };
+
+ printBold("⏳ Starting Cypress");
+ await runCypress({ ...config, ...userOverrides }, cleanup);
+ }
};
const cleanup = async (exitCode: string | number = SUCCESS_EXIT_CODE) => {
diff --git a/e2e/support/config.js b/e2e/support/config.js
index be4d05f9e84..54fd8d8a304 100644
--- a/e2e/support/config.js
+++ b/e2e/support/config.js
@@ -4,6 +4,8 @@ import path from "node:path";
import cypressOnFix from "cypress-on-fix";
import installLogsPrinter from "cypress-terminal-report/src/installLogsPrinter";
+import { BACKEND_HOST, BACKEND_PORT } from "../runner/constants/backend-port";
+
import * as ciTasks from "./ci_tasks";
import { collectFailingTests } from "./collectFailedTests";
import {
@@ -27,8 +29,6 @@ const isCI = process.env["CYPRESS_CI"] === "true";
const snowplowMicroUrl = process.env["MB_SNOWPLOW_URL"];
-const isQaDatabase = process.env["QA_DB_ENABLED"] === "true";
-
// docs say that tsconfig paths should handle aliases, but they don't
const assetsResolverPlugin = {
name: "assetsResolver",
@@ -123,14 +123,11 @@ const defaultConfig = {
** CONFIG **
********************************************************************/
- if (!isQaDatabase) {
- config.excludeSpecPattern = "e2e/snapshot-creators/qa-db.cy.snap.js";
- }
-
// `grepIntegrationFolder` needs to point to the root!
// See: https://github.com/cypress-io/cypress/issues/24452#issuecomment-1295377775
config.env.grepIntegrationFolder = "../../";
config.env.grepFilterSpecs = true;
+ config.env.grepOmitFiltered = true;
config.env.IS_ENTERPRISE = isEnterprise;
config.env.SNOWPLOW_MICRO_URL = snowplowMicroUrl;
@@ -156,6 +153,8 @@ const defaultConfig = {
return config;
},
+ baseUrl: `http://${BACKEND_HOST}:${BACKEND_PORT}`,
+ defaultBrowser: process.env.CYPRESS_BROWSER ?? "chrome",
supportFile: "e2e/support/cypress.js",
chromeWebSecurity: false,
modifyObstructiveCode: false,
@@ -203,17 +202,6 @@ const mainConfig = {
},
};
-const snapshotsConfig = {
- ...defaultConfig,
- specPattern: "e2e/snapshot-creators/**/*.cy.snap.js",
- video: false,
-};
-
-const stressTestConfig = {
- ...defaultConfig,
- retries: 0,
-};
-
const embeddingSdkComponentTestConfig = {
...defaultConfig,
defaultCommandTimeout: 10000,
@@ -235,8 +223,7 @@ const embeddingSdkComponentTestConfig = {
};
module.exports = {
+ defaultConfig,
mainConfig,
- snapshotsConfig,
- stressTestConfig,
embeddingSdkComponentTestConfig,
};
diff --git a/e2e/support/cypress-embedding-sdk-component-test.config.js b/e2e/support/cypress-embedding-sdk-component-test.config.js
index 003472c468c..8ae50f7471e 100644
--- a/e2e/support/cypress-embedding-sdk-component-test.config.js
+++ b/e2e/support/cypress-embedding-sdk-component-test.config.js
@@ -1,5 +1,8 @@
const { embeddingSdkComponentTestConfig } = require("./config");
module.exports = {
- component: embeddingSdkComponentTestConfig,
+ component: {
+ ...embeddingSdkComponentTestConfig,
+ baseUrl: undefined, // baseUrl is not a valid *component* config option,
+ },
};
diff --git a/e2e/support/cypress-snapshots.config.js b/e2e/support/cypress-snapshots.config.js
index 87e7be3dfd9..aee6ee38f67 100644
--- a/e2e/support/cypress-snapshots.config.js
+++ b/e2e/support/cypress-snapshots.config.js
@@ -1,5 +1,16 @@
const { defineConfig } = require("cypress");
-const { snapshotsConfig } = require("./config");
+const { defaultConfig } = require("./config");
-module.exports = defineConfig({ e2e: snapshotsConfig });
+const isQaDatabase = process.env["QA_DB_ENABLED"] === "true";
+
+module.exports = defineConfig({
+ e2e: {
+ ...defaultConfig,
+ specPattern: "e2e/snapshot-creators/**/*.cy.snap.js",
+ excludeSpecPattern: !isQaDatabase
+ ? "e2e/snapshot-creators/qa-db.cy.snap.js"
+ : undefined,
+ video: false,
+ },
+});
diff --git a/e2e/support/cypress-stress-test.config.js b/e2e/support/cypress-stress-test.config.js
index c066dc7d637..4e78bfadfa9 100644
--- a/e2e/support/cypress-stress-test.config.js
+++ b/e2e/support/cypress-stress-test.config.js
@@ -1,11 +1,8 @@
const { defineConfig } = require("cypress");
-const {
- stressTestConfig,
- embeddingSdkComponentTestConfig,
-} = require("./config");
+const { defaultConfig, embeddingSdkComponentTestConfig } = require("./config");
module.exports = defineConfig({
- e2e: stressTestConfig,
+ e2e: { ...defaultConfig, retries: 0 },
component: { ...embeddingSdkComponentTestConfig, retries: 0 },
});
diff --git a/enterprise/frontend/src/embedding-sdk-package/dev.md b/enterprise/frontend/src/embedding-sdk-package/dev.md
index a494c095fe0..cb2a31010c3 100644
--- a/enterprise/frontend/src/embedding-sdk-package/dev.md
+++ b/enterprise/frontend/src/embedding-sdk-package/dev.md
@@ -62,7 +62,7 @@ We recommend running either the dev or the watch command to have shorter a feedb
To start the cypress for the e2e tests:
```bash
-TEST_SUITE="component" yarn test-cypress
+CYPRESS_TESTING_TYPE="component" yarn test-cypress
```
Then in a separate terminal run `yarn embedding-sdk:dev` to build SDK NPM package and SDK bundle in the `watch` mode.
@@ -78,18 +78,18 @@ Define one of the following environment variables with enterprise token: `CYPRES
To run these tests locally, run:
```
-TEST_SUITE=<sample_app_repo_name>-e2e OPEN_UI=false EMBEDDING_SDK_VERSION=local START_METABASE=false GENERATE_SNAPSHOTS=false START_CONTAINERS=false yarn test-cypress
+SDK_TEST_SUITE=<sample_app_repo_name>-e2e OPEN_UI=false EMBEDDING_SDK_VERSION=local START_METABASE=false GENERATE_SNAPSHOTS=false START_CONTAINERS=false yarn test-cypress
```
For example for the `metabase-nodejs-react-sdk-embedding-sample`, run:
```
-TEST_SUITE=metabase-nodejs-react-sdk-embedding-sample-e2e OPEN_UI=false EMBEDDING_SDK_VERSION=local START_METABASE=false GENERATE_SNAPSHOTS=false START_CONTAINERS=false yarn test-cypress
+SDK_TEST_SUITE=metabase-nodejs-react-sdk-embedding-sample-e2e OPEN_UI=false EMBEDDING_SDK_VERSION=local START_METABASE=false GENERATE_SNAPSHOTS=false START_CONTAINERS=false yarn test-cypress
```
##### :warning: Obtaining the Shoppy's Metabase App DB Dump locally
-For the Shoppy's Sample App Tests (`TEST_SUITE=shoppy-e2e`) locally, a proper App DB dump of the Shoppy's Metabase instance must be placed to the `./e2e/tmp/db_dumps/shoppy_metabase_app_db_dump.sql`
+For the Shoppy's Sample App Tests (`SDK_TEST_SUITE=shoppy-e2e`) locally, a proper App DB dump of the Shoppy's Metabase instance must be placed to the `./e2e/tmp/db_dumps/shoppy_metabase_app_db_dump.sql`
You can get it by:
@@ -130,13 +130,13 @@ Tests a bit similar to Sample App tests, but:
To run these tests locally, run:
```
-ENTERPRISE_TOKEN=<token> TEST_SUITE=<host_app_name>-e2e OPEN_UI=false EMBEDDING_SDK_VERSION=local HOST_APP_ENVIRONMENT=production yarn test-cypress
+ENTERPRISE_TOKEN=<token> SDK_TEST_SUITE=<host_app_name>-e2e OPEN_UI=false EMBEDDING_SDK_VERSION=local HOST_APP_ENVIRONMENT=production yarn test-cypress
```
For example for the `vite-6-host-app` Host App, run:
```
-ENTERPRISE_TOKEN=<token> TEST_SUITE=vite-6-host-app-e2e OPEN_UI=false EMBEDDING_SDK_VERSION=local HOST_APP_ENVIRONMENT=production yarn test-cypress
+ENTERPRISE_TOKEN=<token> SDK_TEST_SUITE=vite-6-host-app-e2e OPEN_UI=false EMBEDDING_SDK_VERSION=local HOST_APP_ENVIRONMENT=production yarn test-cypress
```
#### CI runs
diff --git a/package.json b/package.json
index 1d41a5e1e09..a40fef7f54f 100644
--- a/package.json
+++ b/package.json
@@ -240,7 +240,6 @@
"@types/underscore": "^1.11.3",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
- "arg": "^5.0.0",
"babel-eslint": "10.1.0",
"babel-loader": "^9.1.2",
"babel-plugin-ttag": "^1.7.26",
diff --git a/yarn.lock b/yarn.lock
index d7ca0f9e585..c74db5b9437 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -6867,11 +6867,6 @@ arch@^2.2.0:
resolved "https://registry.yarnpkg.com/arch/-/arch-2.2.0.tgz#1bc47818f305764f23ab3306b0bfc086c5a29d11"
integrity sha512-Of/R0wqp83cgHozfIYLbBMnej79U/SVGOOyuB3VVFv1NRM/PSFMK12x9KVtiYzJqmnU5WR2qp0Z5rHb7sWGnFQ==
-arg@^5.0.0:
- version "5.0.0"
- resolved "https://registry.yarnpkg.com/arg/-/arg-5.0.0.tgz#a20e2bb5710e82950a516b3f933fee5ed478be90"
- integrity sha512-4P8Zm2H+BRS+c/xX1LrHw0qKpEhdlZjLCgWy+d78T9vqa2Z2SiD2wMrYuWIAFy5IZUD7nnNXroRttz+0RzlrzQ==
-
arg@^5.0.1, arg@^5.0.2:
version "5.0.2"
resolved "https://registry.yarnpkg.com/arg/-/arg-5.0.2.tgz#c81433cc427c92c4dcf4865142dbca6f15acd59c"