From e384bf8cbbdfa7791d1ef750c9bb8e96f9f12eab Mon Sep 17 00:00:00 2001 From: Diogo Resende Date: Mon, 5 Feb 2024 14:31:27 +0000 Subject: [PATCH] ci: improves test coverage --- test/Features.js | 24 ++++++++++++++++++------ test/views/complex.html | 9 +++++++++ test/views/has-bad-include.html | 3 +++ 3 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 test/views/complex.html create mode 100644 test/views/has-bad-include.html diff --git a/test/Features.js b/test/Features.js index 6a37e49..bd811af 100644 --- a/test/Features.js +++ b/test/Features.js @@ -1,31 +1,43 @@ import { Renderer } from "../index.js" import should from "should" -const keikan = new Renderer(); +const keikan = new Renderer({ debug: true }); describe("Features", () => { it("<% include %> can be used to load another view", async () => { const view = await keikan.compilePath(import.meta.dirname + "/views/has-include"); - view({ name: "world" }).should.equal("

Hello world\n

"); + view({ name: "world" }).should.equal("

\n\tHello world\n

"); + }); + + it("<% include %> will return an if not found", async () => { + const view = await keikan.compilePath(import.meta.dirname + "/views/has-bad-include"); + + view().should.equal("

\n\tInclude not found: notfound\n

"); }); it("<%= %>, <%- %> and <%# %>", async () => { const view = await keikan.compilePath(import.meta.dirname + "/views/escaping"); - view().should.equal(""); + view().should.equal(""); }); it("supports code like conditions, loops, ..", async () => { const view = await keikan.compilePath(import.meta.dirname + "/views/condition"); - view({ condition: true }).should.equal("

Hello\n

"); - view({ condition: false }).should.equal("

"); + view({ condition: true }).should.equal("

\n\tHello\n

"); + view({ condition: false }).should.equal("

\n

"); }); it("removes unnecessary whitespace", async () => { const view = await keikan.compilePath(import.meta.dirname + "/views/long"); - view().should.equal("

Hello\n

"); + view().should.equal("

\n\t\n\t\tHello\n\t\n

"); + }); + + it("handles more complex views", async () => { + const view = await keikan.compilePath(import.meta.dirname + "/views/complex"); + + view().should.equal(""); }); }); diff --git a/test/views/complex.html b/test/views/complex.html new file mode 100644 index 0000000..9853ed4 --- /dev/null +++ b/test/views/complex.html @@ -0,0 +1,9 @@ + diff --git a/test/views/has-bad-include.html b/test/views/has-bad-include.html new file mode 100644 index 0000000..801589c --- /dev/null +++ b/test/views/has-bad-include.html @@ -0,0 +1,3 @@ +

+ <% include notfound({ name }) %> +