work.suroh.tk/node_modules/@11ty/eleventy/test/TemplateRenderHTMLTest.js

52 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import test from "ava";
import TemplateRender from "../src/TemplateRender";
// HTML
test("HTML", t => {
t.is(new TemplateRender("html").getEngineName(), "html");
});
test("HTML Render", async t => {
let fn = await new TemplateRender("html").getCompiledTemplate(
"<p>Paragraph</p>"
);
t.is(await fn(), "<p>Paragraph</p>");
t.is(await fn({}), "<p>Paragraph</p>");
});
test("HTML Render: Parses HTML using liquid engine (default, with data)", async t => {
let fn = await new TemplateRender("html").getCompiledTemplate(
"<h1>{{title}}</h1>"
);
t.is((await fn({ title: "My Title" })).trim(), "<h1>My Title</h1>");
});
test("HTML Render: Parses HTML using ejs engine", async t => {
let tr = new TemplateRender("html");
tr.setHtmlEngine("ejs");
let fn = await tr.getCompiledTemplate("<h1><%=title %></h1>");
t.is((await fn({ title: "My Title" })).trim(), "<h1>My Title</h1>");
});
test("HTML Render: Set HTML engine to false, dont parse", async t => {
let tr = new TemplateRender("html");
tr.setHtmlEngine(false);
let fn = await tr.getCompiledTemplate("<h1>{{title}}</h1>");
t.is((await fn()).trim(), "<h1>{{title}}</h1>");
});
test("HTML Render: Pass in an override (ejs)", async t => {
let tr = new TemplateRender("html");
tr.setHtmlEngine("ejs");
let fn = await tr.getCompiledTemplate("<h1><%= title %></h1>");
t.is((await fn({ title: "My Title" })).trim(), "<h1>My Title</h1>");
});
test("HTML Render: Pass in an override (liquid)", async t => {
let tr = new TemplateRender("html");
tr.setHtmlEngine("liquid");
let fn = await tr.getCompiledTemplate("<h1>{{title}}</h1>");
t.is((await fn({ title: "My Title" })).trim(), "<h1>My Title</h1>");
});