[IMP] runtime: do not check template equality outside dev mode

When defining a template with a name that the template set already
contains, we currently always check whether the template is the same and
throw an error when it's not. This is potentially expensive as it can
involve serializing a pretty large XML document. This check is only
supposed to help during development so this commit disables this check
outside dev mode.
This commit is contained in:
Samuel Degueldre
2023-08-25 09:03:39 +02:00
committed by Bruno Boi
parent 610ed02373
commit c78e070636
2 changed files with 13 additions and 2 deletions
+9 -2
View File
@@ -11,8 +11,8 @@ describe("basic validation", () => {
expect(() => context.getTemplate("invalidname")).toThrow("Missing template");
});
test("cannot add a different template with the same name", () => {
const context = new TemplateSet();
test("cannot add a different template with the same name in dev mode", () => {
const context = new TemplateSet({ dev: true });
context.addTemplate("test", `<t/>`);
// Same template with the same name is fine
expect(() => context.addTemplate("test", "<t/>")).not.toThrow();
@@ -20,6 +20,13 @@ describe("basic validation", () => {
expect(() => context.addTemplate("test", "<div/>")).toThrow("already defined");
});
test("adding different template with same name outside dev mode silently ignores it", () => {
const context = new TemplateSet({ dev: false });
context.addTemplate("test", `<t/>`);
expect(() => context.addTemplate("test", "<div/>")).not.toThrow();
expect(context.rawTemplates.test).toBe("<t/>");
});
test("invalid xml", () => {
const template = "<div>";
expect(() => snapshotTemplate(template)).toThrow("Invalid XML in template");