diff --git a/core/Renderer.js b/core/Renderer.js index 03532f8..0de27b4 100644 --- a/core/Renderer.js +++ b/core/Renderer.js @@ -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) { diff --git a/test/Renderer.js b/test/Renderer.js index de64cea..6c04e8e 100644 --- a/test/Renderer.js +++ b/test/Renderer.js @@ -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("