mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 21:00:57 +00:00
do logger mocking in logger.js, remove sandbox stuff from unit tests
This commit is contained in:
@@ -1,49 +1,14 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const vm = require("vm");
|
||||
|
||||
const basedir = path.join(__dirname, "../../..");
|
||||
const root_path = path.join(__dirname, "../../..");
|
||||
|
||||
describe("Default modules set in modules/default/defaultmodules.js", function () {
|
||||
let sandbox = null;
|
||||
|
||||
beforeAll(function () {
|
||||
const fileName = "js/app.js";
|
||||
const filePath = path.join(basedir, fileName);
|
||||
const code = fs.readFileSync(filePath);
|
||||
|
||||
sandbox = {
|
||||
module: {},
|
||||
__dirname: path.dirname(filePath),
|
||||
global: {},
|
||||
process: {
|
||||
on: function () {},
|
||||
env: {}
|
||||
}
|
||||
};
|
||||
|
||||
sandbox.require = function (filename) {
|
||||
// This modifies the global slightly,
|
||||
// but supplies vm with essential code
|
||||
if (filename === "logger") {
|
||||
return require("../mocks/logger.js");
|
||||
} else {
|
||||
try {
|
||||
return require(filename);
|
||||
} catch (ignore) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
vm.runInNewContext(code, sandbox, fileName);
|
||||
});
|
||||
|
||||
const expectedDefaultModules = require("../../../modules/default/defaultmodules");
|
||||
|
||||
for (const defaultModule of expectedDefaultModules) {
|
||||
it(`contains a folder for modules/default/${defaultModule}"`, function () {
|
||||
expect(fs.existsSync(path.join(sandbox.global.root_path, "modules/default", defaultModule))).toBe(true);
|
||||
expect(fs.existsSync(path.join(root_path, "modules/default", defaultModule))).toBe(true);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user