Skip to content

Commit

Permalink
ci: updates tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dresende committed Feb 2, 2024
1 parent 6ce89ac commit 9f8e461
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
8 changes: 6 additions & 2 deletions core/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ export class Renderer {

if (!filename) return null;

const data = await readFile(filename);
try {
const data = await readFile(filename);

return await this.compileData(data, level);
return await this.compileData(data, level);
} catch (err) {
return null;
}
}

async compileData(data, level = 0) {
Expand Down
22 changes: 20 additions & 2 deletions test/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,30 @@ describe("Renderer", () => {
});

it("compileData returns a Promise", () => {
const p = keikan.compileData("hello world");
const view = keikan.compileData("hello world");

p.should.be.instanceOf(Promise);
view.should.be.instanceOf(Promise);
});

it("exposes a compilePath method", () => {
keikan.compilePath.should.be.of.type("function");
});

it("compilePath returns a Promise", () => {
const view = keikan.compilePath("views/simple");

view.should.be.instanceOf(Promise);
});

it("compilePath returns null if file is not found", async () => {
const view = await keikan.compilePath("notfound");

should(view).be.null();
});

it("compilePath returns a view that can then be renderer", async () => {
const view = await keikan.compilePath(import.meta.dirname + "/views/simple");

view({ name: "world" }).should.equal("<h3>Hello world</h3>");
});
});
2 changes: 1 addition & 1 deletion test/views/simple.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<h3>Hello {name}</h3>
<h3>Hello <%= name %></h3>

0 comments on commit 9f8e461

Please sign in to comment.