mirror of
https://github.com/MagicMirrorOrg/MagicMirror.git
synced 2026-03-12 17:51:41 +08:00
replace template_spec test with config_variables test (#4034)
After introducing new config loading this PR replaces the obsolete template test with a config test.
This commit is contained in:
@@ -248,6 +248,7 @@
|
||||
"Reis",
|
||||
"rejas",
|
||||
"relativehumidity",
|
||||
"resultstring",
|
||||
"Resig",
|
||||
"roboto",
|
||||
"rohitdharavath",
|
||||
@@ -288,6 +289,7 @@
|
||||
"TESTMODE",
|
||||
"testpass",
|
||||
"testuser",
|
||||
"teststring",
|
||||
"thomasrockhu",
|
||||
"thumbslider",
|
||||
"timeformat",
|
||||
|
||||
@@ -9,7 +9,7 @@ import stylistic from "@stylistic/eslint-plugin";
|
||||
import vitest from "@vitest/eslint-plugin";
|
||||
|
||||
export default defineConfig([
|
||||
globalIgnores(["config/**", "modules/**/*", "js/positions.js", "tests/configs/port_variable.js"]),
|
||||
globalIgnores(["config/**", "modules/**/*", "js/positions.js", "tests/configs/config_variables.js"]),
|
||||
{
|
||||
files: ["**/*.js"],
|
||||
languageOptions: {
|
||||
|
||||
7
tests/configs/config_variables.env
Normal file
7
tests/configs/config_variables.env
Normal file
@@ -0,0 +1,7 @@
|
||||
MM_LANGUAGE=de
|
||||
MM_TIME_FORMAT=12
|
||||
MM_LOG_INFO=INFO
|
||||
MM_LOG_ERROR=ERROR
|
||||
SECRET_IP1="127.0.0.1"
|
||||
SECRET_IP2="::ffff:127.0.0.1"
|
||||
SECRET_IP3=1
|
||||
12
tests/configs/config_variables.js
Normal file
12
tests/configs/config_variables.js
Normal file
@@ -0,0 +1,12 @@
|
||||
let config = require(`${process.cwd()}/tests/configs/default.js`).configFactory({
|
||||
language: "${MM_LANGUAGE}",
|
||||
logLevel: ["${MM_LOG_ERROR}", "LOG", "WARN", "${MM_LOG_INFO}"],
|
||||
timeFormat: ${MM_TIME_FORMAT},
|
||||
hideConfigSecrets: true,
|
||||
ipWhitelist: ["${SECRET_IP2}", "::${SECRET_IP3}", "${SECRET_IP1}"]
|
||||
});
|
||||
|
||||
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
||||
if (typeof module !== "undefined") {
|
||||
module.exports = config;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
MM_PORT=8090
|
||||
@@ -1,8 +0,0 @@
|
||||
let config = require(`${process.cwd()}/tests/configs/default.js`).configFactory({
|
||||
port: ${MM_PORT}
|
||||
});
|
||||
|
||||
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
||||
if (typeof module !== "undefined") {
|
||||
module.exports = config;
|
||||
}
|
||||
34
tests/e2e/config_variables_spec.js
Normal file
34
tests/e2e/config_variables_spec.js
Normal file
@@ -0,0 +1,34 @@
|
||||
const helpers = require("./helpers/global-setup");
|
||||
|
||||
describe("config with variables and secrets", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/config_variables.js");
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
it("config.language should be \"de\"", async () => {
|
||||
expect(config.language).toBe("de");
|
||||
});
|
||||
|
||||
it("config.loglevel should be [\"ERROR\", \"LOG\", \"WARN\", \"INFO\"]", async () => {
|
||||
expect(config.logLevel).toStrictEqual(["ERROR", "LOG", "WARN", "INFO"]);
|
||||
});
|
||||
|
||||
it("config.ipWhitelist should be [\"::ffff:127.0.0.1\", \"::1\", \"127.0.0.1\"]", async () => {
|
||||
expect(config.ipWhitelist).toStrictEqual(["::ffff:127.0.0.1", "::1", "127.0.0.1"]);
|
||||
});
|
||||
|
||||
it("config.timeFormat should be 12", async () => {
|
||||
expect(config.timeFormat).toBe(12); // default is 24
|
||||
});
|
||||
|
||||
it("/config endpoint should show redacted secrets", async () => {
|
||||
const res = await fetch(`http://localhost:${config.port}/config`);
|
||||
expect(res.status).toBe(200);
|
||||
const cfg = await res.json();
|
||||
expect(cfg.ipWhitelist).toStrictEqual(["**SECRET_IP2**", "::**SECRET_IP3**", "**SECRET_IP1**"]);
|
||||
});
|
||||
});
|
||||
@@ -1,23 +0,0 @@
|
||||
const fs = require("node:fs");
|
||||
const helpers = require("./helpers/global-setup");
|
||||
|
||||
describe("templated config with port variable", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/port_variable.js");
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
try {
|
||||
fs.unlinkSync("tests/configs/port_variable.js");
|
||||
} catch (err) {
|
||||
// do nothing
|
||||
}
|
||||
});
|
||||
|
||||
it("should return 200", async () => {
|
||||
const port = global.testPort || 8080;
|
||||
const res = await fetch(`http://localhost:${port}`);
|
||||
expect(res.status).toBe(200);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user