Skip to content

Commit

Permalink
Move a few tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jul 1, 2021
1 parent 8a6b7bf commit 89fd4a2
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 64 deletions.
64 changes: 0 additions & 64 deletions test/TemplateTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,70 +593,6 @@ test("Clone the template", async (t) => {
t.is(cloned.extensionMap, tmpl.extensionMap);
});

test("Permalink with variables!", async (t) => {
let tmpl = getNewTemplate(
"./test/stubs/permalinkdata.njk",
"./test/stubs/",
"./dist"
);

t.is(await tmpl.getOutputPath(), "./dist/subdir/slug-candidate/index.html");
});

test("Permalink with variables and JS front matter!", async (t) => {
let tmpl = getNewTemplate(
"./test/stubs/permalinkdata-jsfn.njk",
"./test/stubs/",
"./dist"
);

t.is(await tmpl.getOutputPath(), "./dist/subdir/slug/index.html");
});

// This is broken right now, permalink must use the same template language as the template
test.skip("Use a JavaScript function for permalink in any template language", async (t) => {
let tmpl = getNewTemplate(
"./test/stubs/permalinkdata-jspermalinkfn.njk",
"./test/stubs/",
"./dist"
);

t.is(await tmpl.getOutputPath(), "./dist/subdir/slug/index.html");
});

test("Permalink with dates!", async (t) => {
let tmpl = getNewTemplate(
"./test/stubs/permalinkdate.liquid",
"./test/stubs/",
"./dist"
);

t.is(await tmpl.getOutputPath(), "./dist/2016/01/01/index.html");
});

test("Permalink with dates on file name regex!", async (t) => {
let tmpl = getNewTemplate(
"./test/stubs/2016-02-01-permalinkdate.liquid",
"./test/stubs/",
"./dist"
);

t.is(await tmpl.getOutputPath(), "./dist/2016/02/01/index.html");
});

test("Reuse permalink in directory specific data file", async (t) => {
let eleventyConfig = new TemplateConfig();
let dataObj = new TemplateData("./test/stubs/", eleventyConfig);
let tmpl = getNewTemplate(
"./test/stubs/reuse-permalink/test1.liquid",
"./test/stubs/",
"./dist",
dataObj
);

t.is(await tmpl.getOutputPath(), "./dist/2016/01/01/index.html");
});

test("mapDataAsRenderedTemplates", async (t) => {
let tmpl = getNewTemplate(
"./test/stubs/default.ejs",
Expand Down
68 changes: 68 additions & 0 deletions test/TemplateTest_Permalink.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const test = require("ava");
const fs = require("fs");
const TemplateConfig = require("../src/TemplateConfig");
const TemplateData = require("../src/TemplateData");

const getNewTemplate = require("./_getNewTemplateForTests");

Expand Down Expand Up @@ -122,3 +124,69 @@ test("Disable dynamic permalinks", async (t) => {
t.is(await tmpl.getOutputLink(), "/{{justastring}}/index.html");
t.is(await tmpl.getOutputHref(), "/{{justastring}}/");
});


test("Permalink with variables!", async (t) => {
let tmpl = getNewTemplate(
"./test/stubs/permalinkdata.njk",
"./test/stubs/",
"./dist"
);

t.is(await tmpl.getOutputPath(), "./dist/subdir/slug-candidate/index.html");
});

test("Permalink with variables and JS front matter!", async (t) => {
let tmpl = getNewTemplate(
"./test/stubs/permalinkdata-jsfn.njk",
"./test/stubs/",
"./dist"
);

t.is(await tmpl.getOutputPath(), "./dist/subdir/slug/index.html");
});

// This is broken right now, permalink must use the same template language as the template
test.skip("Use a JavaScript function for permalink in any template language", async (t) => {
let tmpl = getNewTemplate(
"./test/stubs/permalinkdata-jspermalinkfn.njk",
"./test/stubs/",
"./dist"
);

t.is(await tmpl.getOutputPath(), "./dist/subdir/slug/index.html");
});

test("Permalink with dates!", async (t) => {
let tmpl = getNewTemplate(
"./test/stubs/permalinkdate.liquid",
"./test/stubs/",
"./dist"
);

t.is(await tmpl.getOutputPath(), "./dist/2016/01/01/index.html");
});

test("Permalink with dates on file name regex!", async (t) => {
let tmpl = getNewTemplate(
"./test/stubs/2016-02-01-permalinkdate.liquid",
"./test/stubs/",
"./dist"
);

t.is(await tmpl.getOutputPath(), "./dist/2016/02/01/index.html");
});

test("Reuse permalink in directory specific data file", async (t) => {
let eleventyConfig = new TemplateConfig();
let dataObj = new TemplateData("./test/stubs/", eleventyConfig);
let tmpl = getNewTemplate(
"./test/stubs/reuse-permalink/test1.liquid",
"./test/stubs/",
"./dist",
dataObj
);

t.is(await tmpl.getOutputPath(), "./dist/2016/01/01/index.html");
});

0 comments on commit 89fd4a2

Please sign in to comment.