mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-09-14 16:13:57 +00:00
refactor: use global.root_path instead relative paths (#3883)
This commit is contained in:
@@ -3,7 +3,7 @@ const helpers = require("./helpers/global-setup");
|
||||
describe("All font files from roboto.css should be downloadable", () => {
|
||||
const fontFiles = [];
|
||||
// Statements below filters out all 'url' lines in the CSS file
|
||||
const fileContent = require("node:fs").readFileSync(`${__dirname}/../../css/roboto.css`, "utf8");
|
||||
const fileContent = require("node:fs").readFileSync(`${global.root_path}/css/roboto.css`, "utf8");
|
||||
const regex = /\burl\(['"]([^'"]+)['"]\)/g;
|
||||
let match = regex.exec(fileContent);
|
||||
while (match !== null) {
|
||||
|
@@ -13,10 +13,9 @@ app.use(basicAuth);
|
||||
|
||||
// Set available directories
|
||||
const directories = ["/tests/configs", "/tests/mocks"];
|
||||
const rootPath = path.resolve(`${__dirname}/../../../`);
|
||||
|
||||
for (let directory of directories) {
|
||||
app.use(directory, express.static(path.resolve(rootPath + directory)));
|
||||
app.use(directory, express.static(path.resolve(`${global.root_path}/${directory}`)));
|
||||
}
|
||||
|
||||
let server;
|
||||
|
@@ -1,9 +1,13 @@
|
||||
const path = require("node:path");
|
||||
const os = require("node:os");
|
||||
const fs = require("node:fs");
|
||||
const jsdom = require("jsdom");
|
||||
|
||||
const indexFile = `${__dirname}/../../../index.html`;
|
||||
const cssFile = `${__dirname}/../../../css/custom.css`;
|
||||
// global absolute root path
|
||||
global.root_path = path.resolve(`${__dirname}/../../../`);
|
||||
|
||||
const indexFile = `${global.root_path}/index.html`;
|
||||
const cssFile = `${global.root_path}/css/custom.css`;
|
||||
const sampleCss = [
|
||||
".region.row3 {",
|
||||
" top: 0;",
|
||||
@@ -29,7 +33,7 @@ exports.startApplication = async (configFilename, exec) => {
|
||||
process.env.mmTestMode = "true";
|
||||
process.setMaxListeners(0);
|
||||
if (exec) exec;
|
||||
global.app = require("../../../js/app");
|
||||
global.app = require(`${global.root_path}/js/app`);
|
||||
|
||||
return global.app.start();
|
||||
};
|
||||
|
@@ -83,8 +83,7 @@ describe("Newsfeed module", () => {
|
||||
|
||||
describe("Newsfeed module located in config directory", () => {
|
||||
beforeAll(() => {
|
||||
const baseDir = `${__dirname}/../../..`;
|
||||
fs.cpSync(`${baseDir}/modules/default/newsfeed`, `${baseDir}/config/newsfeed`, { recursive: true });
|
||||
fs.cpSync(`${global.root_path}/modules/default/newsfeed`, `${global.root_path}/config/newsfeed`, { recursive: true });
|
||||
process.env.MM_MODULES_DIR = "config";
|
||||
});
|
||||
|
||||
|
@@ -6,7 +6,7 @@ describe("App environment", () => {
|
||||
let serverProcess;
|
||||
beforeAll(async () => {
|
||||
process.env.MM_CONFIG_FILE = "tests/configs/default.js";
|
||||
serverProcess = await require("node:child_process").spawn("npm", ["run", "server"], { env: process.env, detached: true });
|
||||
serverProcess = await require("node:child_process").spawn("node", ["--run", "server"], { env: process.env, detached: true });
|
||||
// we have to wait until the server is started
|
||||
await delay(2000);
|
||||
});
|
||||
|
@@ -9,7 +9,7 @@ describe("Vendors", () => {
|
||||
});
|
||||
|
||||
describe("Get list vendors", () => {
|
||||
const vendors = require(`${__dirname}/../../js/vendor.js`);
|
||||
const vendors = require(`${global.root_path}/js/vendor.js`);
|
||||
|
||||
Object.keys(vendors).forEach((vendor) => {
|
||||
it(`should return 200 HTTP code for vendor "${vendor}"`, async () => {
|
||||
|
@@ -4,7 +4,7 @@ const path = require("node:path");
|
||||
const root_path = path.join(__dirname, "../../..");
|
||||
|
||||
describe("Default modules set in modules/default/defaultmodules.js", () => {
|
||||
const expectedDefaultModules = require("../../../modules/default/defaultmodules");
|
||||
const expectedDefaultModules = require(`${root_path}/modules/default/defaultmodules`);
|
||||
|
||||
for (const defaultModule of expectedDefaultModules) {
|
||||
it(`contains a folder for modules/default/${defaultModule}"`, () => {
|
||||
|
@@ -2,7 +2,7 @@ const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
|
||||
const root_path = path.join(__dirname, "../../..");
|
||||
const version = require(`${__dirname}/../../../package.json`).version;
|
||||
const version = require(`${root_path}/package.json`).version;
|
||||
|
||||
describe("'global.root_path' set in js/app.js", () => {
|
||||
const expectedSubPaths = ["modules", "serveronly", "js", "js/app.js", "js/main.js", "js/electron.js", "config"];
|
||||
|
Reference in New Issue
Block a user