Skip to content

Commit

Permalink
ci: improves test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dresende committed Feb 5, 2024
1 parent bfa4a54 commit e384bf8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
24 changes: 18 additions & 6 deletions test/Features.js
Original file line number Diff line number Diff line change
@@ -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("<h3>Hello world\n</h3>");
view({ name: "world" }).should.equal("<h3>\n\tHello world\n</h3>");
});

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

view().should.equal("<h3>\n\t<error>Include not found: notfound</error>\n</h3>");
});

it("<%= %>, <%- %> and <%# %>", async () => {
const view = await keikan.compilePath(import.meta.dirname + "/views/escaping");

view().should.equal("<ul><li>This is a &quot;quoted&quot; string</li><li>This is not a \"quoted\" string</li><li></li></ul>");
view().should.equal("<ul>\n\t<li>This is a &quot;quoted&quot; string</li>\n\t<li>This is not a \"quoted\" string</li>\n\t<li></li>\n</ul>");
});

it("supports code like conditions, loops, ..", async () => {
const view = await keikan.compilePath(import.meta.dirname + "/views/condition");

view({ condition: true }).should.equal("<h3>Hello\n</h3>");
view({ condition: false }).should.equal("<h3></h3>");
view({ condition: true }).should.equal("<h3>\n\tHello\n</h3>");
view({ condition: false }).should.equal("<h3>\n</h3>");
});

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

view().should.equal("<h3><strong>Hello\n</strong></h3>");
view().should.equal("<h3>\n\t<strong>\n\t\tHello\n\t</strong>\n</h3>");
});

it("handles more complex views", async () => {
const view = await keikan.compilePath(import.meta.dirname + "/views/complex");

view().should.equal("<ul>\n\t<li>(odd) 1. 1</li>\n\t<li>(even) 2. 2</li>\n\t<li>(odd) 3. 3</li>\n</ul>");
});
});
9 changes: 9 additions & 0 deletions test/views/complex.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<ul>
<% [ 1, 2, 3 ].map(i => { %>
<% if (i % 2 == 0) { %>
<li>(even) <%= i %>. <%- i %></li>
<% } else { %>
<li>(odd) <%= i %>. <%- i %></li>
<% } %>
<% }) %>
</ul>
3 changes: 3 additions & 0 deletions test/views/has-bad-include.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h3>
<% include notfound({ name }) %>
</h3>

0 comments on commit e384bf8

Please sign in to comment.