import test from "ava"; import TemplateRender from "../src/TemplateRender"; // EJS test("EJS", t => { t.is(new TemplateRender("ejs").getEngineName(), "ejs"); t.is(new TemplateRender("./test/stubs/filename.ejs").getEngineName(), "ejs"); }); test("EJS Render", async t => { let fn = await new TemplateRender("ejs").getCompiledTemplate( "
<%= name %>
" ); t.is(await fn({ name: "Zach" }), "Zach
"); }); test("EJS Render Absolute Include, Preprocessor Directive", async t => { // includes require a full filename passed in let fn = await new TemplateRender( "./test/stubs/filename.ejs", "./test/stubs/" ).getCompiledTemplate("<% include /included %>
"); t.is(await fn(), "This is an include.
"); }); test("EJS Render Absolute Include, Fxn no Data", async t => { // includes require a full filename passed in let fn = await new TemplateRender( "./test/stubs/filename.ejs", "./test/stubs/" ).getCompiledTemplate("<%- include('/included') %>
"); t.is(await fn(), "This is an include.
"); }); test("EJS Render Absolute Include, Fxn with Data", async t => { // includes require a full filename passed in let fn = await new TemplateRender( "./test/stubs/filename.ejs", "./test/stubs/" ).getCompiledTemplate( "<%- include('/includedvar', { name: 'Bill' }) %>
" ); t.is(await fn(), "This is an Bill.
"); }); test("EJS Render Relative Include (no leading dot-slash for current dir), Preprocessor Directive", async t => { // includes require a full filename passed in let fn = await new TemplateRender( "./test/stubs/relative-ejs/dir/filename.ejs", "./test/stubs/" ).getCompiledTemplate("<% include included %>
"); t.is(await fn(), "This is an include.
"); }); test("EJS Render Relative Include Current dir to Subdir, Preprocessor Directive", async t => { // includes require a full filename passed in let fn = await new TemplateRender( "./test/stubs/relative-ejs/filename.ejs", "./test/stubs/" ).getCompiledTemplate("<% include ./dir/included %>
"); t.is(await fn(), "This is an include.
"); }); test("EJS Render Relative Include Parent dir to Subdir, Preprocessor Directive", async t => { // includes require a full filename passed in let fn = await new TemplateRender( "./test/stubs/relative-ejs/dir/filename.ejs", "./test/stubs/" ).getCompiledTemplate("<% include ../dir/included %>
"); t.is(await fn(), "This is an include.
"); }); test("EJS Render Relative Include, Fxn no Data", async t => { // includes require a full filename passed in let fn = await new TemplateRender( "./test/stubs/filename.ejs", "./test/stubs/" ).getCompiledTemplate("<%- include('_includes/included', {}) %>
"); t.is(await fn(), "This is an include.
"); }); test("EJS Render Relative Include current dir to subdir, Fxn no Data", async t => { // includes require a full filename passed in let fn = await new TemplateRender( "./test/stubs/relative-ejs/filename.ejs", "./test/stubs/" ).getCompiledTemplate("<%- include('./dir/included', {}) %>
"); t.is(await fn(), "This is an include.
"); }); test("EJS Render Relative Include, Fxn with Data", async t => { // includes require a full filename passed in let fn = await new TemplateRender( "./test/stubs/filename.ejs", "./test/stubs/" ).getCompiledTemplate( "<%- include('_includes/includedvar', { name: 'Bill' }) %>
" ); t.is(await fn(), "This is an Bill.
"); }); test("EJS Render: with Library Override", async t => { let tr = new TemplateRender("ejs"); let lib = require("ejs"); tr.engine.setLibrary(lib); let fn = await tr.getCompiledTemplate("<%= name %>
"); t.is(await fn({ name: "Zach" }), "Zach
"); });