Skip to content
Snippets Groups Projects
Unverified Commit c2b4c5cb authored by Nemanja Glumac's avatar Nemanja Glumac Committed by GitHub
Browse files

Refactor `backend.js` #3 - legibility (#24084)

* Define all Java flags separately for readability

* Separate database and snowplow configs

* Explicitly say that we are generating a temporary DB file

* Extract `userDefaults` and warn about it

* Rename `databaseConfig` to `metabaseConfig`

* Rename temporary database path generator
parent f2d4fd05
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@ const { spawn } = require("child_process");
const fetch = require("isomorphic-fetch");
let testDbId = 0;
const getDbFile = () =>
const generateTempDbPath = () =>
path.join(os.tmpdir(), `metabase-test-${process.pid}-${testDbId++}.db`);
let port = 4000;
......@@ -16,7 +16,7 @@ const getPort = () => port++;
const BackendResource = createSharedResource("BackendResource", {
create({ dbKey }) {
const dbFile = getDbFile();
const dbFile = generateTempDbPath();
const absoluteDbKey = dbKey ? __dirname + dbKey : dbFile;
const e2eHost = process.env["E2E_HOST"];
if (e2eHost) {
......@@ -41,39 +41,58 @@ const BackendResource = createSharedResource("BackendResource", {
fs.copyFileSync(`${server.dbKey}.mv.db`, `${server.dbFile}.mv.db`);
}
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
"-Duser.timezone=US/Pacific",
`-Dlog4j.configurationFile=file:${__dirname}/log4j2.xml`,
];
const metabaseConfig = {
MB_DB_TYPE: "h2",
MB_DB_FILE: server.dbFile,
MB_JETTY_HOST: "0.0.0.0",
MB_JETTY_PORT: server.port,
MB_ENABLE_TEST_ENDPOINTS: "true",
MB_PREMIUM_EMBEDDING_TOKEN:
(process.env["MB_EDITION"] === "ee" &&
process.env["ENTERPRISE_TOKEN"]) ||
undefined,
};
/**
* This ENV is used for Cloud instances only, and is subject to change.
* As such, it is not documented anywhere in the code base!
*
* WARNING:
* Changing values here will break the related E2E test.
*/
const userDefaults = {
MB_USER_DEFAULTS: JSON.stringify({
token: "123456",
user: {
first_name: "Testy",
last_name: "McTestface",
email: "testy@metabase.test",
site_name: "Epic Team",
},
}),
};
const snowplowConfig = {
MB_SNOWPLOW_AVAILABLE: process.env["MB_SNOWPLOW_AVAILABLE"],
MB_SNOWPLOW_URL: process.env["MB_SNOWPLOW_URL"],
};
server.process = spawn(
"java",
[
"-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
"-Duser.timezone=US/Pacific",
`-Dlog4j.configurationFile=file:${__dirname}/log4j2.xml`,
"-jar",
"target/uberjar/metabase.jar",
],
[...javaFlags, "-jar", "target/uberjar/metabase.jar"],
{
env: {
MB_DB_TYPE: "h2",
MB_DB_FILE: server.dbFile,
MB_JETTY_HOST: "0.0.0.0",
MB_JETTY_PORT: server.port,
MB_ENABLE_TEST_ENDPOINTS: "true",
MB_PREMIUM_EMBEDDING_TOKEN:
(process.env["MB_EDITION"] === "ee" &&
process.env["ENTERPRISE_TOKEN"]) ||
undefined,
MB_USER_DEFAULTS: JSON.stringify({
token: "123456",
user: {
first_name: "Testy",
last_name: "McTestface",
email: "testy@metabase.test",
site_name: "Epic Team",
},
}),
MB_SNOWPLOW_AVAILABLE: process.env["MB_SNOWPLOW_AVAILABLE"],
MB_SNOWPLOW_URL: process.env["MB_SNOWPLOW_URL"],
...metabaseConfig,
...userDefaults,
...snowplowConfig,
PATH: process.env.PATH,
},
stdio:
......
......@@ -211,6 +211,7 @@ describe("scenarios > setup", () => {
cy.location("pathname").should("eq", "/");
});
// Values in this test are set through MB_USER_DEFAULTS environment variable!
// Please see https://github.com/metabase/metabase/pull/18763 for details
it("should allow pre-filling user details", () => {
cy.visit(`/setup#123456`);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment