Skip to content

Commit

Permalink
ci: improves tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dresende committed Feb 5, 2024
1 parent daea0e1 commit dc4f54f
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 5 deletions.
12 changes: 12 additions & 0 deletions test/Errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Renderer } from "../index.js"
import should from "should"

const keikan = new Renderer();

describe("Errors", () => {
it("should handle incomplete view", async () => {
const view = await keikan.compilePath(import.meta.dirname + "/views/incomplete");

view().should.equal("<h3>Hello <error>Invalid block</error>");
});
});
18 changes: 18 additions & 0 deletions test/Features.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Renderer } from "../index.js"
import should from "should"

const keikan = new Renderer();

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>");
});

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>");
});
});
8 changes: 3 additions & 5 deletions test/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ describe("Renderer", () => {

view({ name: "world" }).should.equal("<h3>Hello world</h3>");
});
});

describe("Features", () => {
it("<% include %> can be used to load another view", async () => {
const view = await keikan.compilePath(import.meta.dirname + "/views/complex");
it("compilePath will use process cwd when base is explicitly passed as null", async () => {
const view = await keikan.compilePath("test/views/simple", null);

view({ name: "world" }).should.equal("<h3>Hello world\n</h3>");
view({ name: "world" }).should.equal("<h3>Hello world</h3>");
});
});
5 changes: 5 additions & 0 deletions test/views/escaping.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ul>
<li><%= "This is a \"quoted\" string" %></li>
<li><%- "This is not a \"quoted\" string" %></li>
<li><%# "This is a comment" %></li>
</ul>
File renamed without changes.
2 changes: 2 additions & 0 deletions test/views/incomplete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h3>
Hello <%= name

0 comments on commit dc4f54f

Please sign in to comment.