The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
E2E test environment setup based on deps.edn `:e2e` alias (#66431)
Nemanja Glumacfd47d82ba136
diff --git a/.env.example b/.env.examplenew file mode 100644index 00000000000..83d4494cd1c--- /dev/null+++ b/.env.example@@ -0,0 +1,84 @@+# ==============================================================================+# 0. METABASE DEVELOPMENT ENVIRONMENT+# ==============================================================================+#+# Central configuration for local Metabase development.+# Copy to .env and uncomment/modify values as needed.+#+# Usage:+# op inject --in-file .env.example --out-file .env (populate using CLI)+# cp .env.example .env (populate manually)+#+# Hint: Auto-load environment variables with mise or direnv:+# mise - mise.toml: [settings] env_file = ".env" (https://mise.jdx.dev)+# direnv - Create .envrc with: dotenv .env (https://direnv.net)+#+# Full Metabase environment configuration reference:+# https://www.metabase.com/docs/latest/configuring-metabase/environment-variables+++# ==============================================================================+# 1. E2E / CYPRESS TESTING+# ==============================================================================+#+# Configuration for running Cypress end-to-end tests locally.+#+# The whole environment is already orchestrated via deps.edn using :e2e alias.+# Treat it as a source of truth for JVM flags and ENVs whether you decide to run+# backend on your own, or using `yarn test-cypress` (local test runner).+#+# You don't _have to_ export any of these vars (except for the tokens below).+# Things will still work.++# 1.1. E2E Application Database (H2 required)+# ------------------------------------------------------------------------------++# Whether to run the enterprise or the open-source Metabase version+MB_EDITION="ee"++# Which file to use for the ephemeral testing application database?+MB_DB_FILE="./e2e/tmp/cypress-test.db"++# Where does Cypress go to look for the application?+MB_JETTY_PORT=4000++# 1.2 E2E Local Runner Setup+# ------------------------------------------------------------------------------++# Whether to run true e2e test suite, or SDK component tests (e2e | component)+CYPRESS_TESTING_TYPE="e2e"++# Whether to start Cypress in an interactive (open) mode with full GUI+CYPRESS_GUI="true"++# Whether to generate application database dumps (colloquially "snapshots")+# Keep this enabled unless you're experimenting, or know what you're doing.+GENERATE_SNAPSHOTS="true"++# E2E tests run the backend from source by default.+# To run tests against a JAR instead, set the JAR_PATH variable.+#+# Hint: build the JAR with ./bin/build.sh+# JAR_PATH="target/uberjar/metabase.jar"++# 1.3 E2E Tokens+# ------------------------------------------------------------------------------+#+# These make sense for Metabase core devs only+# op inject --in-file .env.example --out-file .env++CYPRESS_MB_ALL_FEATURES_TOKEN="op://Shared/Metabase License Dev Tokens/Licenses/MB_ALL_FEATURES_TOKEN"+CYPRESS_MB_STARTER_CLOUD_TOKEN="op://Shared/Metabase License Dev Tokens/Licenses/MB_STARTER_CLOUD_TOKEN"+CYPRESS_MB_PRO_CLOUD_TOKEN="op://Shared/Metabase License Dev Tokens/Licenses/MB_PRO_CLOUD_TOKEN"+CYPRESS_MB_PRO_SELF_HOSTED_TOKEN="op://Shared/Metabase License Dev Tokens/Licenses/MB_PRO_SELF_HOSTED_TOKEN"++# 1.4 E2E Misc.+# ------------------------------------------------------------------------------++# To make Node.js match the instance tz+TZ="US/Pacific"++# Export this environment variable when running tests on Apple Silicon.+# DO NOT USE Docker Desktop. Use Orbstack instead. Metabase will fail to connect+# to the dockerized Mongo QA database otherwise.+EXPERIMENTAL_DOCKER_DESKTOP_FORCE_QEMU=1diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.ymlindex 123a19f3e20..ab82551b044 100644--- a/.github/workflows/e2e-test.yml+++ b/.github/workflows/e2e-test.yml@@ -41,8 +41,6 @@ jobs:GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}HASH: ${{ github.event.pull_request.head.sha || github.sha }}-${{ github.run_attempt }}JOB_NAME: ${{ inputs.name }}- MB_RUN_MODE: "e2e"- METASTORE_DEV_SERVER_URL: ${{ secrets.METASTORE_DEV_SERVER_URL }}# Any env starting with `CYPRESS_` will be available to all Cypress tests via `Cypress.env()`# Example: you can get `CYPRESS_FOO` with `Cypress.env("FOO")`CYPRESS_MB_ALL_FEATURES_TOKEN: ${{ secrets.STAGING_MB_ALL_FEATURES_TOKEN }}@@ -51,10 +49,6 @@ jobs:CYPRESS_MB_PRO_SELF_HOSTED_TOKEN: ${{ secrets.STAGING_MB_PRO_SELF_HOSTED_TOKEN }}CYPRESS_PULL_REQUEST_ID: ${{ github.event.pull_request.number || '' }}COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title || github.event.head_commit.message || github.event.head.sha }}- MB_EXPERIMENTAL_SEARCH_BLOCK_ON_QUEUE: true- MB_SEARCH_ENGINE: appdb- MB_SNOWPLOW_AVAILABLE: true- MB_SNOWPLOW_URL: "http://localhost:9090" # Snowplow microTZ: US/Pacific # to make node match the instance tzCYPRESS_CI: truesteps:@@ -91,12 +85,8 @@ jobs:- name: Prepare front-end environmentuses: ./.github/actions/prepare-frontend-- - name: Prepare JDK 21- uses: actions/setup-java@v4- with:- java-version: 21- distribution: "temurin"+ - name: Prepare back-end environment+ uses: ./.github/actions/prepare-backend- name: Prepare Cypress environmentid: cypress-prepdiff --git a/.github/workflows/embedding-sdk-component-tests.yml b/.github/workflows/embedding-sdk-component-tests.ymlindex c3ee70bf8d4..05180a10a3a 100644--- a/.github/workflows/embedding-sdk-component-tests.yml+++ b/.github/workflows/embedding-sdk-component-tests.yml@@ -15,8 +15,6 @@ jobs:env:MB_EDITION: eeDISPLAY: ""- MB_RUN_MODE: "e2e"- METASTORE_DEV_SERVER_URL: ${{ secrets.METASTORE_DEV_SERVER_URL }}# Any env starting with `CYPRESS_` will be available to all Cypress tests via `Cypress.env()`# Example: you can get `CYPRESS_FOO` with `Cypress.env("FOO")`CYPRESS_MB_ALL_FEATURES_TOKEN: ${{ secrets.STAGING_MB_ALL_FEATURES_TOKEN }}@@ -45,12 +43,8 @@ jobs:- name: Prepare front-end environmentuses: ./.github/actions/prepare-frontend-- - name: Prepare JDK 21- uses: actions/setup-java@v4- with:- java-version: 21- distribution: "temurin"+ - name: Prepare back-end environment+ uses: ./.github/actions/prepare-backend- name: Prepare Cypress environmentid: cypress-prep@@ -171,6 +165,8 @@ jobs:- name: Prepare front-end environmentuses: ./.github/actions/prepare-frontend+ - name: Prepare back-end environment+ uses: ./.github/actions/prepare-backend- name: Attempt to retrieve the ee uberjar artifact from the previous commitid: download-uberjardiff --git a/.github/workflows/embedding-sdk-host-sample-apps-tests.yml b/.github/workflows/embedding-sdk-host-sample-apps-tests.ymlindex 62ea23ae99f..474f138804b 100644--- a/.github/workflows/embedding-sdk-host-sample-apps-tests.yml+++ b/.github/workflows/embedding-sdk-host-sample-apps-tests.yml@@ -236,8 +236,6 @@ jobs:GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}PR_NUMBER: ${{ github.event.pull_request.number || '' }}HASH: ${{ github.event.pull_request.head.sha || github.sha }}-${{ github.run_attempt }}- MB_RUN_MODE: e2e- METASTORE_DEV_SERVER_URL: ${{ secrets.METASTORE_DEV_SERVER_URL }}CYPRESS_MB_ALL_FEATURES_TOKEN: ${{ secrets.STAGING_MB_ALL_FEATURES_TOKEN }}TZ: US/Pacific # to make node match the instance tzCYPRESS_CI: true@@ -263,17 +261,13 @@ jobs:- name: Prepare front-end environmentuses: ./.github/actions/prepare-frontend+ - name: Prepare back-end environment+ uses: ./.github/actions/prepare-backend- name: Prepare Cypress environmentid: cypress-prepuses: ./.github/actions/prepare-cypress- - name: Prepare JDK 21- uses: actions/setup-java@v4- with:- java-version: 21- distribution: "temurin"-- name: Run Metabaserun: node e2e/runner/run_cypress_ci.js startdiff --git a/cypress.env.json.example b/cypress.env.json.exampledeleted file mode 100644index db0e35e4a53..00000000000--- a/cypress.env.json.example+++ /dev/null@@ -1,13 +0,0 @@-# Use this file to create a `cypress.env.json` in the root of this project.-# Documentation: https://docs.cypress.io/app/references/environment-variables#Option-2-cypressenvjson--# Remove all lines starting with "#" (including this one)-{- "MB_SNOWPLOW_URL": "http://localhost:9090",- "MB_SNOWPLOW_AVAILABLE": "true",- "MB_ALL_FEATURES_TOKEN": "get it from the password manager",- "MB_STARTER_CLOUD_TOKEN": "get it from the password manager",- "MB_PRO_CLOUD_TOKEN": "get it from the password manager",- "MB_PRO_SELF_HOSTED_TOKEN": "get it from the password manager",- "MB_EDITION": "ee",-}diff --git a/deps.edn b/deps.ednindex 9d3637a7886..06d2e03d449 100644--- a/deps.edn+++ b/deps.edn@@ -347,6 +347,41 @@"-Dmacaw.run.mode=dev""-Djava.awt.headless=true"]} ; prevent Java icon from randomly popping up in macOS dock+ ;; Cypress end-to-end tests require a highly specific setup, which includes both the environment and the H2 database+ ;; initialized with the correct set of settings. This alias orchestrates those pieces.+ ;; Prefer using it when running local backend for Cypress end-to-end tests.+ ;; Two things you can still control via env vars: MB_JETTY_PORT and MB_DB_FILE+ ;;+ ;; clojure -M:dev:drivers:(oss|ee):run:e2e+ :e2e+ {:jvm-opts ["-Dmb.run.mode=e2e"+ "-Dmetastore.dev.server.url=https://token-check.staging.metabase.com"+ ;; prevent Java icon from randomly popping up in macOS dock+ "-Djava.awt.headless=true"+ ;; ignore options that aren't recognized by older versions of Java+ "-XX:+IgnoreUnrecognizedVMOptions"+ ;; test self-signed certificates for testing+ "-Dmail.smtps.ssl.trust=*"+ ;; Writes all logs to a file logs/test.log+ "-Dlog4j.configurationFile=file:frontend/test/__runner__/log4j2.xml"+ "-Duser.timezone=US/Pacific"+ "-Dmb.db.type=h2"+ "-Dmb.enable.test.endpoints=true"+ "-Dmb.dangerous.unsafe.enable.testing.h2.connections.do.not.enable=true"+ ;; Ignore connection URI in favor of the MB_DB_FILE+ "-Dmb.db.connection.uri="+ ;; Ignore config.yml+ "-Dmb.config.file.path=__cypress__"+ ;; We use Snowplow micro in e2e tests+ "-Dmb.snowplow.available=true"+ "-Dmb.snowplow.url=http://localhost:9090"+ ;; See: https://github.com/metabase/metabase/pull/38280+ "-Dmb.last.analytics.checksum=-1"+ "-Dmb.experimental.search.block.on.queue=true"+ "-Dmb.search.engine=appdb"+ ;; We use a local webhook service for testing+ "-Dmb.http.channel.host.strategy=allow-all"]}+;; run the prod server when generating docs;; as some default values differ between dev and prod;;diff --git a/docs/developers-guide/e2e-tests.md b/docs/developers-guide/e2e-tests.mdindex 0a4fac78b8d..f68936b6a61 100644--- a/docs/developers-guide/e2e-tests.md+++ b/docs/developers-guide/e2e-tests.md@@ -29,14 +29,14 @@ Our custom Cypress runner builds its own backend and creates a temporary H2 appTo run all Cypress tests headlessly in the terminal:```sh-OPEN_UI=false yarn run test-cypress+CYPRESS_GUI=false yarn run test-cypress```You can quickly test a single file only by using the official `--spec` flag.This flag can be used to run all specs within a folder, or to run multiple assorted specs. Consult [the official documentation](https://docs.cypress.io/app/references/command-line#cypress-run-spec-lt-spec-gt) for instructions.```sh-OPEN_UI=false yarn test-cypress --spec e2e/test/scenarios/question/new.cy.spec.js+CYPRESS_GUI=false yarn test-cypress --spec e2e/test/scenarios/question/new.cy.spec.js```You can specify a browser to execute Cypress tests in using the `--browser` flag. For more details, please consult [the official documentation](https://docs.cypress.io/guides/guides/launching-browsers).diff --git a/e2e/runner/cypress-node-js-runner.js b/e2e/runner/cypress-node-js-runner.jsindex 5f107195f4b..b77d9f69af3 100644--- a/e2e/runner/cypress-node-js-runner.js+++ b/e2e/runner/cypress-node-js-runner.js@@ -16,7 +16,7 @@ const cypress = require("cypress");* @throws {Error} When Cypress fails to run (e.g., config error) or any tests fail*/const runCypress = async (options) => {- const openMode = process.env.OPEN_UI === "true";+ const openMode = process.env.CYPRESS_GUI === "true";// Open mode is interactive - no results to validateif (openMode) {diff --git a/e2e/runner/cypress-runner-backend.js b/e2e/runner/cypress-runner-backend.jsindex 86598b185ea..5a3f0aeb015 100755--- a/e2e/runner/cypress-runner-backend.js+++ b/e2e/runner/cypress-runner-backend.js@@ -1,130 +1,74 @@#!/usr/bin/env node-const { spawn } = require("child_process");+const { execSync, spawn } = require("child_process");const fs = require("fs");-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 { waitUntilReady, shell } = require("./cypress-runner-utils");-const CypressBackend = {- server: null,- createServer(port = BACKEND_PORT) {- const generateTempDbPath = () =>- path.join(os.tmpdir(), `metabase-test-${process.pid}.db`);+const tempDbPath = path.join(os.tmpdir(), `metabase-test-${process.pid}.db`);++function getJvmOptsFromDepsEdn(alias = "e2e") {+ const cmd = `clojure -Sdeps '{:deps {}}' -M -e '(->> (-> "deps.edn" slurp clojure.edn/read-string :aliases :${alias} :jvm-opts) (clojure.string/join " ") println)'`;+ return execSync(cmd, { encoding: "utf8" }).trim().toString();+}++// Ensure that the only two required env vars have values+process.env.MB_DB_FILE = process.env.MB_DB_FILE || tempDbPath;+process.env.MB_JETTY_PORT = process.env.MB_JETTY_PORT || 4000;- const server = {- dbFile: generateTempDbPath(),- host: `http://localhost:${port}`,- };+if (!process.CI) {+ // Use a temporary copy of the sample db so it won't use and lock the db used for local development+ process.env.MB_INTERNAL_DO_NOT_USE_SAMPLE_DB_DIR = path.resolve(+ __dirname,+ "../../e2e/tmp", // already exists and is .gitignored+ );+}- this.server = server;+const CypressBackend = {+ server: {+ dbFile: process.env.MB_DB_FILE,+ host: `http://localhost:${process.env.MB_JETTY_PORT}`,},- async start(jarPath = "target/uberjar/metabase.jar") {- if (!this.server) {- this.createServer();+ async runFromJar(jarPath = "target/uberjar/metabase.jar") {+ if (!fs.existsSync(jarPath)) {+ console.log("Build the JAR with ./bin/build.sh\n");+ throw new Error(`JAR ${jarPath} does not exist!`);}if (!this.server.process) {- const javaFlags = [- "-XX:+IgnoreUnrecognizedVMOptions", // ignore options not recognized by this Java version (e.g. Java 8 should ignore Java 9 options)- "-Dh2.bindAddress=localhost", // fix H2 randomly not working (?)- "-Djava.awt.headless=true", // when running on macOS prevent little Java icon from popping up in Dock- "-Dmail.smtps.ssl.trust=*", // trust self signed certs for testing- "-Duser.timezone=US/Pacific",- // FIXME @nemanjaglumac 2025-11-28- // This is a bit convoluted because this particular log4j config outputs all logs to a file (logs/test.log)- // See: https://github.com/metabase/metabase/pull/21360- // If we want them in the console, we'd have to unset the log4j config, to let stdio inherit the logs.- // Override in your .env if you need to see the logs in the console locally.- process.env.SHOW_BACKEND_LOGS === "true"- ? null- : `-Dlog4j.configurationFile=file:${__dirname}/../../frontend/test/__runner__/log4j2.xml`,- ].filter(Boolean);-- const metabaseConfig = {- MB_DB_TYPE: "h2",- MB_DB_FILE: this.server.dbFile,- 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",- 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_SNOWPLOW_AVAILABLE: true,- MB_SNOWPLOW_URL: "http://localhost:9090",- };-- this.server.process = spawn("java", [...javaFlags, "-jar", jarPath], {- env: {- ...process.env,- ...metabaseConfig,- },- stdio:- process.env["DISABLE_LOGGING"] ||- process.env["DISABLE_LOGGING_BACKEND"]- ? "ignore"- : "inherit",+ process.env.JDK_JAVA_OPTIONS = getJvmOptsFromDepsEdn();+ this.server.process = spawn("java", ["-jar", jarPath], {+ env: process.env,+ stdio: process.env.CI ? "ignore" : "inherit",detached: true,});- }-- if (!(await isReady(this.server.host))) {- process.stdout.write(- `Waiting for backend (host=${this.server.host}, dbFile=${this.server.dbFile})`,- );- while (!(await isReady(this.server.host))) {- if (!process.env["CI"]) {- // disable for CI since it breaks CircleCI's no_output_timeout- process.stdout.write(".");- }- await delay(500);+ await waitUntilReady(this.server);+ if (process.env.CI) {+ this.server.process.unref(); // detach console}- process.stdout.write("\n");- }-- console.log(- `Backend ready host=${this.server.host}, dbFile=${this.server.dbFile}`,- );-- if (process.env.CI) {- this.server.process.unref(); // detach console}-- async function isReady(host) {- // This is needed until we can use NodeJS native `fetch`.- function request(url) {- return new Promise((resolve, reject) => {- const req = http.get(url, (res) => {- let body = "";-- res.on("data", (chunk) => {- body += chunk;- });-- res.on("end", () => {- resolve(JSON.parse(body));- });- });-- req.on("error", (e) => {- reject(e);- });- });+ },+ async runFromSource() {+ if (!this.server.process) {+ const edition = process.env.MB_EDITION || "ee";++ this.server.process = spawn(+ "clojure",+ [`-M:run:${edition}:dev:dev-start:e2e`, "--hot"],+ {+ env: process.env,+ stdio: process.env.CI ? "ignore" : "inherit",+ detached: true,+ },+ );+ await waitUntilReady(this.server);+ if (process.env.CI) {+ this.server.process.unref(); // detach console}-- try {- const { status } = await request(`${host}/api/health`);- if (status === "ok") {- return true;- }- } catch (e) {}- return false;}},+async stop() {if (this?.server?.process) {this.server.process.kill("SIGKILL");@@ -135,9 +79,15 @@ const CypressBackend = {try {if (this?.server?.dbFile) {fs.unlinkSync(`${this.server.dbFile}.mv.db`);+ fs.unlinkSync(`${this.server.dbFile}.trace.db`);}} catch (e) {}},};-module.exports = CypressBackend;+const isBackendRunning = shell(+ `lsof -ti:${process.env.MB_JETTY_PORT} || echo ""`,+ { quiet: true },+);++module.exports = { ...CypressBackend, isBackendRunning };diff --git a/e2e/runner/cypress-runner-utils.js b/e2e/runner/cypress-runner-utils.jsindex 27fdeb19678..d3b44d9c163 100644--- a/e2e/runner/cypress-runner-utils.js+++ b/e2e/runner/cypress-runner-utils.js@@ -81,6 +81,42 @@ function delay(durationMs) {return new Promise((resolve) => setTimeout(resolve, durationMs));}+async function isReady(host) {+ try {+ const response = await fetch(`${host}/api/health`);+ const { status } = await response.json();+ return status === "ok";+ } catch (e) {+ return false;+ }+}++async function waitUntilReady(backend, attempt = 0) {+ const { dbFile, host } = backend;+ const TIMEOUT_MS = 1000;+ const MAX_MINUTES = 5;+ const MAX_ATTEMPTS = 60 * MAX_MINUTES;++ if (attempt === 0) {+ process.stdout.write(+ `\nWaiting for backend (host=${host}, dbFile=${dbFile})`,+ );+ }++ if (await isReady(host)) {+ console.log(`\nBackend ready host=${host}, dbFile=${dbFile}`);+ return;+ }++ if (attempt >= MAX_ATTEMPTS) {+ throw new Error(`\nBackend failed to start within ${MAX_MINUTES} minutes`);+ }++ process.stdout.write(".");+ await delay(TIMEOUT_MS);+ return waitUntilReady(backend, attempt + 1);+}+module.exports = {booleanify,unBooleanify,@@ -88,4 +124,5 @@ module.exports = {printBold,shell,delay,+ waitUntilReady,};diff --git a/e2e/runner/run_cypress_ci.js b/e2e/runner/run_cypress_ci.jsindex c3adb7572db..2a98037b184 100755--- a/e2e/runner/run_cypress_ci.js+++ b/e2e/runner/run_cypress_ci.js@@ -32,7 +32,7 @@ if (!permittedCommands.includes(command)) {const startServer = async () => {printBold("Starting backend");- await CypressBackend.start();+ await CypressBackend.runFromJar();};const runTests = async (config, cliArguments = []) => {diff --git a/e2e/runner/run_cypress_host_sample_apps.ts b/e2e/runner/run_cypress_host_sample_apps.tsindex de05a4b5bc7..cd504d7fb08 100644--- a/e2e/runner/run_cypress_host_sample_apps.ts+++ b/e2e/runner/run_cypress_host_sample_apps.ts@@ -8,13 +8,13 @@ import { resolveSdkE2EConfig } from "./resolve-sdk-e2e-config";// if you want to change these, set them as environment variables in your shellconst options = {SDK_TEST_SUITE: "vite-6-host-app-e2e", // one of the many sample-app, or host-app Embedding SDK suites- OPEN_UI: false,+ CYPRESS_GUI: false,...booleanify(process.env),};printBold(`Running Cypress with options:- SDK_TEST_SUITE : ${options.SDK_TEST_SUITE}- - OPEN_UI : ${options.OPEN_UI}+ - CYPRESS_GUI : ${options.CYPRESS_GUI}`);const init = async () => {diff --git a/e2e/runner/run_cypress_local.ts b/e2e/runner/run_cypress_local.tsindex 33ca35c28fa..8da1bc1c114 100644--- a/e2e/runner/run_cypress_local.ts+++ b/e2e/runner/run_cypress_local.ts@@ -1,6 +1,3 @@-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";@@ -14,12 +11,11 @@ import {// if you want to change these, set them as environment variables in your shellconst options = {- CYPRESS_TESTING_TYPE: "e2e", // e2e | componentMB_EDITION: "ee", // ee | oss- BUILD_BACKEND: true,- BACKEND_PORT: BACKEND_PORT, // override with MB_JETTY_PORT in your env- OPEN_UI: true,+ CYPRESS_TESTING_TYPE: "e2e", // e2e | component+ CYPRESS_GUI: true,GENERATE_SNAPSHOTS: true,+ JAR_PATH: undefined,...booleanify(process.env),};@@ -39,52 +35,50 @@ if (options.MB_EDITION === "ee" && missingTokens.length > 0) {}printBold(`Running Cypress with options:- - CYPRESS_TESTING_TYPE : ${options.CYPRESS_TESTING_TYPE}- MB_EDITION : ${options.MB_EDITION}- - BACKEND_PORT : ${options.BACKEND_PORT}- - BUILD_BACKEND : ${options.BUILD_BACKEND}+ - CYPRESS_TESTING_TYPE : ${options.CYPRESS_TESTING_TYPE}+ - CYPRESS_GUI : ${options.CYPRESS_GUI}- GENERATE_SNAPSHOTS : ${options.GENERATE_SNAPSHOTS}- - OPEN_UI : ${options.OPEN_UI}+ - JAR_PATH : ${options.JAR_PATH}`);const init = async () => {const cliArguments = process.argv.slice(2);const userOverrides = await parseArguments(cliArguments);+ const { isBackendRunning } = CypressBackend;++ const runningFromJar = !!options.JAR_PATH;+printBold("⏳ Starting containers");shell("docker compose -f ./e2e/test/scenarios/docker-compose.yml up -d");- if (options.BUILD_BACKEND) {- printBold("⏳ Building backend");- shell("./bin/build-backend-for-test");-- const isBackendRunning = shell(- `lsof -ti:${options.BACKEND_PORT} || echo ""`,- { quiet: true },- );+ if (runningFromJar) {if (isBackendRunning) {- printBold(- "⚠️ Your backend is already running, you may want to kill pid " +- isBackendRunning,- );+ printBold("⚠️ Your backend is already running");+ console.log(`You wanted to test against a pre-built Metabase JAR:+ - It will spin up both the backend and the frontend for you+ - Kill the backend pid ${isBackendRunning} and run the script again+ - Alternatively, use a different MB_JETTY_PORT in this shell and try again+ `);+process.exit(FAILURE_EXIT_CODE);+ } else {+ printBold("⏳ Starting Metabase from a JAR");+ await CypressBackend.runFromJar(options.JAR_PATH);}-- // Use a temporary copy of the sample db so it won't use and lock the db used for local development- process.env.MB_INTERNAL_DO_NOT_USE_SAMPLE_DB_DIR = path.resolve(- __dirname,- "../../e2e/tmp", // already exists and is .gitignored- );-- printBold("⏳ Starting backend");- await CypressBackend.start("target/uberjar/metabase-backend.jar");} else {- printBold(- `Not building a jar, expecting metabase to be running on port ${options.BACKEND_PORT}. Make sure your metabase instance is running with an h2 app db and the following environment variables:- - MB_ENABLE_TEST_ENDPOINTS=true- - MB_DANGEROUS_UNSAFE_ENABLE_TESTING_H2_CONNECTIONS_DO_NOT_ENABLE=true- `,- );+ if (isBackendRunning) {+ printBold("⚠️ Your backend is already running");+ console.log(`If tests fail or if something doesn't work:+ - Kill the pid ${isBackendRunning}+ - Run *yarn test-cypress* again+ - This will spin up the live backend with the correct settings for e2e tests+ `);+ } else {+ printBold("⏳ Starting live backend with hot reloading");+ await CypressBackend.runFromSource();+ }}if (options.GENERATE_SNAPSHOTS) {@@ -92,21 +86,25 @@ const init = async () => {shell("rm -f e2e/support/cypress_sample_instance_data.json");printBold("⏳ Generating app db snapshots");- process.env.OPEN_UI = "false";+ process.env.CYPRESS_GUI = "false";await runCypress({configFile: "e2e/support/cypress-snapshots.config.js",...(options.CYPRESS_TESTING_TYPE === "component" && {env: { grepTags: "-@external" }, // component tests do not need QA DB snapshots for now}),});- process.env.OPEN_UI = `${options.OPEN_UI}`;+ process.env.CYPRESS_GUI = `${options.CYPRESS_GUI}`;} 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.CYPRESS_TESTING_TYPE === "e2e") {+ if (+ !isFrontendRunning &&+ options.CYPRESS_TESTING_TYPE === "e2e" &&+ !runningFromJar+ ) {printBold("⚠️⚠️ You don't have your frontend running. You should probably run yarn build-hot ⚠️⚠️",);@@ -129,10 +127,8 @@ const init = async () => {};const cleanup = async (exitCode: string | number = SUCCESS_EXIT_CODE) => {- if (options.BUILD_BACKEND) {- printBold("⏳ Cleaning up...");- await CypressBackend.stop();- }+ printBold("⏳ Cleaning up...");+ await CypressBackend.stop();printBold("🧹 Containers are running in background. If you wish to stop them, run:\n`docker compose -f ./e2e/test/scenarios/docker-compose.yml down`",diff --git a/e2e/support/helpers/e2e-snowplow-helpers.js b/e2e/support/helpers/e2e-snowplow-helpers.jsindex a29e3df3da8..6e2250c0614 100644--- a/e2e/support/helpers/e2e-snowplow-helpers.js+++ b/e2e/support/helpers/e2e-snowplow-helpers.js@@ -1,6 +1,6 @@import { updateSetting } from "e2e/support/helpers";-const SNOWPLOW_URL = Cypress.env("SNOWPLOW_MICRO_URL");+const SNOWPLOW_URL = "http://localhost:9090";const SNOWPLOW_INTERVAL = 100;const SNOWPLOW_TIMEOUT = 1000;