mirror of
https://github.com/bringout/oca-ocb-core.git
synced 2026-04-20 00:32:03 +02:00
vanilla 19.0
This commit is contained in:
parent
991d2234ca
commit
d1963a3c3a
3066 changed files with 1651266 additions and 922560 deletions
|
|
@ -0,0 +1,38 @@
|
|||
import { describe, expect, test } from "@odoo/hoot";
|
||||
|
||||
/**
|
||||
* @param {string} folder folder that can only import from `allowedFolders`
|
||||
* @param {string[]} allowedFolders folders from which `folder` can import
|
||||
* @returns {{[key: string]: string[]}} an object where the keys are modules and
|
||||
* the values are an array of imports that the module is not allowed to import
|
||||
*/
|
||||
function invalidImportsFrom(folder, allowedFolders) {
|
||||
// modules within a folder can always depend on one another
|
||||
allowedFolders.push(folder);
|
||||
const modulesToCheck = Array.from(odoo.loader.modules.keys()).filter((module) =>
|
||||
module.startsWith(`@web/${folder}/`)
|
||||
);
|
||||
const invalidDeps = {};
|
||||
for (const module of modulesToCheck) {
|
||||
const invalid = odoo.loader.factories.get(module).deps.filter((dep) => {
|
||||
// owl and @web/session are allowed everywhere
|
||||
if (dep === "@odoo/owl" || dep === "@web/session") {
|
||||
return false;
|
||||
}
|
||||
return !allowedFolders.some((allowed) => dep.startsWith(`@web/${allowed}/`));
|
||||
});
|
||||
if (invalid.length) {
|
||||
invalidDeps[module] = invalid;
|
||||
}
|
||||
}
|
||||
return invalidDeps;
|
||||
}
|
||||
|
||||
describe.current.tags("headless");
|
||||
|
||||
test("modules only import from allowed folders", () => {
|
||||
expect(invalidImportsFrom("core", [])).toEqual({});
|
||||
expect(invalidImportsFrom("search", ["core"])).toEqual({});
|
||||
expect(invalidImportsFrom("model", ["core", "search"])).toEqual({});
|
||||
expect(invalidImportsFrom("views", ["core", "search", "model"])).toEqual({});
|
||||
});
|
||||
|
|
@ -0,0 +1,126 @@
|
|||
import { beforeEach, expect, getFixture, test } from "@odoo/hoot";
|
||||
import { microTick, tick } from "@odoo/hoot-dom";
|
||||
import { patchWithCleanup } from "@web/../tests/web_test_helpers";
|
||||
|
||||
beforeEach(() => {
|
||||
patchWithCleanup(document.head, {
|
||||
appendChild: (el) => expect.step(["APPENDCHILD", el.tagName, el.className]),
|
||||
});
|
||||
patchWithCleanup(console, {
|
||||
error: (...args) => expect.step(["ERROR", ...args]),
|
||||
});
|
||||
});
|
||||
|
||||
/** @type {typeof OdooModuleLoader} */
|
||||
const ModuleLoader = Object.getPrototypeOf(odoo.loader.constructor);
|
||||
|
||||
test.tags("headless");
|
||||
test("define: simple case", async () => {
|
||||
const loader = new ModuleLoader();
|
||||
loader.debug = false;
|
||||
|
||||
const modA = {};
|
||||
const modC = {};
|
||||
|
||||
expect(loader.factories).toBeEmpty();
|
||||
expect(loader.modules).toBeEmpty();
|
||||
expect(loader.checkErrorProm).toBe(null);
|
||||
|
||||
loader.define("b", ["c"], (req) => req("c"));
|
||||
loader.define("c", [], () => modC);
|
||||
loader.define("a", ["b"], () => modA);
|
||||
|
||||
expect(loader.factories).toHaveLength(3);
|
||||
expect(loader.modules).toHaveLength(3);
|
||||
expect(loader.failed).toBeEmpty();
|
||||
expect(loader.jobs).toBeEmpty();
|
||||
|
||||
expect(loader.modules.get("a")).toBe(modA);
|
||||
expect(loader.modules.get("b")).toBe(modC);
|
||||
expect(loader.modules.get("c")).toBe(modC);
|
||||
|
||||
Promise.resolve(loader.checkErrorProm).then(() => expect.step("check done"));
|
||||
|
||||
expect.verifySteps([]);
|
||||
|
||||
await tick();
|
||||
|
||||
expect.verifySteps(["check done"]);
|
||||
});
|
||||
|
||||
test.tags("headless");
|
||||
test("define: invalid module error handling", async () => {
|
||||
const loader = new ModuleLoader(getFixture());
|
||||
loader.debug = false;
|
||||
|
||||
expect(() => loader.define(null, null, null)).toThrow(/Module name should be a string/);
|
||||
expect(() => loader.define("a", null, null)).toThrow(
|
||||
/Module dependencies should be a list of strings/
|
||||
);
|
||||
expect(() => loader.define("a", [], null)).toThrow(/Module factory should be a function/);
|
||||
|
||||
expect(loader.checkErrorProm).toBe(null);
|
||||
});
|
||||
|
||||
test.tags("headless");
|
||||
test("define: duplicate name", async () => {
|
||||
const loader = new ModuleLoader(getFixture());
|
||||
loader.debug = false;
|
||||
|
||||
loader.define("a", [], () => ":)");
|
||||
loader.define("a", [], () => {
|
||||
throw new Error("This factory should be ignored");
|
||||
});
|
||||
|
||||
await microTick();
|
||||
|
||||
expect(loader.modules.get("a")).toBe(":)");
|
||||
});
|
||||
|
||||
test("define: missing module", async () => {
|
||||
const loader = new ModuleLoader(getFixture());
|
||||
loader.debug = false;
|
||||
|
||||
loader.define("b", ["a"], () => {});
|
||||
loader.define("c", ["a"], () => {});
|
||||
|
||||
await microTick();
|
||||
|
||||
expect.verifySteps([
|
||||
[
|
||||
"ERROR",
|
||||
"The following modules are needed by other modules but have not been defined, they may not be present in the correct asset bundle:",
|
||||
["a"],
|
||||
],
|
||||
[
|
||||
"ERROR",
|
||||
"The following modules could not be loaded because they have unmet dependencies, this is a secondary error which is likely caused by one of the above problems:",
|
||||
["b", "c"],
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
test("define: dependency cycle", async () => {
|
||||
const loader = new ModuleLoader(getFixture());
|
||||
loader.debug = true;
|
||||
|
||||
loader.define("a", ["b"], () => {});
|
||||
loader.define("b", ["c"], () => {});
|
||||
loader.define("c", ["a"], () => {});
|
||||
|
||||
await microTick();
|
||||
|
||||
expect.verifySteps([
|
||||
[
|
||||
"ERROR",
|
||||
"The following modules could not be loaded because they form a dependency cycle:",
|
||||
`"a" => "b" => "c" => "a"`,
|
||||
],
|
||||
[
|
||||
"ERROR",
|
||||
"The following modules could not be loaded because they have unmet dependencies, this is a secondary error which is likely caused by one of the above problems:",
|
||||
["a", "b", "c"],
|
||||
],
|
||||
["APPENDCHILD", "STYLE", "o_module_error_banner"],
|
||||
]);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue