|
| 1 | +import {expect} from "chai"; |
| 2 | +import {renderFile} from "ejs"; |
| 3 | +import {dirname} from "node:path"; |
| 4 | +import {getEngineFixture} from "../../test/getEngineFixture"; |
| 5 | +import {EtaEngine} from "./EtaEngine"; |
| 6 | + |
| 7 | +describe("EtaEngine", () => { |
| 8 | + it("should render the given content", async () => { |
| 9 | + const {render, locals, $compile, template} = await getEngineFixture({ |
| 10 | + token: EtaEngine |
| 11 | + }); |
| 12 | + |
| 13 | + await render(); |
| 14 | + |
| 15 | + expect(await render()).to.eq("<p>Tobi</p>\n"); |
| 16 | + expect($compile()).to.have.been.callCount(2); |
| 17 | + expect($compile()).to.have.been.calledWithExactly(template, {...locals, cache: false}); |
| 18 | + }); |
| 19 | + |
| 20 | + it("should render the given content (by string - no cache)", async () => { |
| 21 | + const {render, locals, $compile, template} = await getEngineFixture({token: EtaEngine}); |
| 22 | + await render(); |
| 23 | + |
| 24 | + expect(await render()).to.eq("<p>Tobi</p>\n"); |
| 25 | + expect($compile()).to.have.been.callCount(2); |
| 26 | + expect($compile()).to.have.been.calledWithExactly(template, {...locals, cache: false}); |
| 27 | + }); |
| 28 | + it("should render the given content (by string - with cache)", async () => { |
| 29 | + const {render, locals, $compile, template} = await getEngineFixture({token: EtaEngine, cache: true}); |
| 30 | + await render(); |
| 31 | + |
| 32 | + expect(await render()).to.eq("<p>Tobi</p>\n"); |
| 33 | + expect($compile()).to.have.been.callCount(2); |
| 34 | + expect($compile()).to.have.been.calledWithExactly(template, {...locals, cache: true}); |
| 35 | + }); |
| 36 | + it("should render the given content (by file - no cache)", async () => { |
| 37 | + const {renderFile, locals, $compileFile, path, template} = await getEngineFixture({token: EtaEngine, useTemplateName: true}); |
| 38 | + |
| 39 | + await renderFile({ |
| 40 | + views: dirname(path) |
| 41 | + }); |
| 42 | + |
| 43 | + const content = await renderFile({ |
| 44 | + views: dirname(path) |
| 45 | + }); |
| 46 | + |
| 47 | + expect(content).to.eq("<p>Tobi</p>\n"); |
| 48 | + expect($compileFile()).to.have.been.callCount(2); |
| 49 | + expect($compileFile()).to.have.been.calledWithExactly("user", { |
| 50 | + ...locals, |
| 51 | + partials: undefined, |
| 52 | + filename: "user", |
| 53 | + cache: false, |
| 54 | + views: dirname(path) |
| 55 | + }); |
| 56 | + }); |
| 57 | + it("should render the given content (by file - with cache)", async () => { |
| 58 | + const {renderFile, locals, $compileFile, path, template} = await getEngineFixture({ |
| 59 | + token: EtaEngine, |
| 60 | + useTemplateName: true, |
| 61 | + cache: true |
| 62 | + }); |
| 63 | + |
| 64 | + await renderFile({ |
| 65 | + views: dirname(path) |
| 66 | + }); |
| 67 | + const content = await renderFile(); |
| 68 | + |
| 69 | + expect(content).to.eq("<p>Tobi</p>\n"); |
| 70 | + expect($compileFile()).to.have.been.callCount(1); |
| 71 | + expect($compileFile()).to.have.been.calledWithExactly("user", { |
| 72 | + ...locals, |
| 73 | + partials: undefined, |
| 74 | + filename: "user", |
| 75 | + cache: true, |
| 76 | + views: dirname(path) |
| 77 | + }); |
| 78 | + }); |
| 79 | +}); |
0 commit comments