Skip to content

Commit

Permalink
Adds test for #3418
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Aug 30, 2024
1 parent 75d01f9 commit 03d1cfd
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 82 deletions.
103 changes: 103 additions & 0 deletions test/EleventyTest-Preprocessors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import test from "ava";
import Eleventy from "../src/Eleventy.js";

test("#188: Content preprocessing (dot in file extension)", async (t) => {
let elev = new Eleventy("./test/stubs-virtual/", undefined, {
config: eleventyConfig => {
eleventyConfig.addPreprocessor("drafts", ".njk", (data, content) => {
if(data.draft) {
return false;
}
return `Hello ${content}`;
});

eleventyConfig.addTemplate("index.njk", "Before");
eleventyConfig.addTemplate("draft.njk", "Before", { draft: true });
}
});

let results = await elev.toJSON();
t.is(results.length, 1);
t.is(results[0].content, `Hello Before`);
});

test("#188: Content preprocessing (no dot in file extension)", async (t) => {
let elev = new Eleventy("./test/stubs-virtual/", undefined, {
config: eleventyConfig => {
eleventyConfig.addPreprocessor("drafts", "njk", (data, content) => {
if(data.draft) {
return false;
}
return `Hello ${content}`;
});

eleventyConfig.addTemplate("index.njk", "Before");
eleventyConfig.addTemplate("draft.njk", "Before", { draft: true });
}
});

let results = await elev.toJSON();
t.is(results.length, 1);
t.is(results[0].content, `Hello Before`);
});


test("#188: Content preprocessing (array, no dot in file extension)", async (t) => {
let elev = new Eleventy("./test/stubs-virtual/", undefined, {
config: eleventyConfig => {
eleventyConfig.addPreprocessor("drafts", ["njk"], (data, content) => {
if(data.draft) {
return false;
}
return `Hello ${content}`;
});

eleventyConfig.addTemplate("index.njk", "Before");
eleventyConfig.addTemplate("draft.njk", "Before", { draft: true });
}
});

let results = await elev.toJSON();
t.is(results.length, 1);
t.is(results[0].content, `Hello Before`);
});

test("#188: Content preprocessing (array, dot in file extension)", async (t) => {
let elev = new Eleventy("./test/stubs-virtual/", undefined, {
config: eleventyConfig => {
eleventyConfig.addPreprocessor("drafts", [".njk"], (data, content) => {
if(data.draft) {
return false;
}
return `Hello ${content}`;
});

eleventyConfig.addTemplate("index.njk", "Before");
eleventyConfig.addTemplate("draft.njk", "Before", { draft: true });
}
});

let results = await elev.toJSON();
t.is(results.length, 1);
t.is(results[0].content, `Hello Before`);
});

test("#188: Content preprocessing (wildcard)", async (t) => {
let elev = new Eleventy("./test/stubs-virtual/", undefined, {
config: eleventyConfig => {
eleventyConfig.addPreprocessor("drafts", "*", (data, content) => {
if(data.draft) {
return false;
}
return `Hello ${content}`;
});

eleventyConfig.addTemplate("index.njk", "Before");
eleventyConfig.addTemplate("draft.njk", "Before", { draft: true });
}
});

let results = await elev.toJSON();
t.is(results.length, 1);
t.is(results[0].content, `Hello Before`);
});
82 changes: 0 additions & 82 deletions test/EleventyTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1481,88 +1481,6 @@ test("#1419: Shortcode in a permalink", async (t) => {
t.is(results[0].url, `/url-slug/`);
});

test("#188: Content preprocessing (dot in file extension)", async (t) => {
let elev = new Eleventy("./test/stubs-virtual/", undefined, {
config: eleventyConfig => {
eleventyConfig.addPreprocessor("drafts", ".njk", (data, content) => {
if(data.draft) {
return false;
}
return `Hello ${content}`;
});

eleventyConfig.addTemplate("index.njk", "Before");
eleventyConfig.addTemplate("draft.njk", "Before", { draft: true });
}
});

let results = await elev.toJSON();
t.is(results.length, 1);
t.is(results[0].content, `Hello Before`);
});

test("#188: Content preprocessing (no dot in file extension)", async (t) => {
let elev = new Eleventy("./test/stubs-virtual/", undefined, {
config: eleventyConfig => {
eleventyConfig.addPreprocessor("drafts", "njk", (data, content) => {
if(data.draft) {
return false;
}
return `Hello ${content}`;
});

eleventyConfig.addTemplate("index.njk", "Before");
eleventyConfig.addTemplate("draft.njk", "Before", { draft: true });
}
});

let results = await elev.toJSON();
t.is(results.length, 1);
t.is(results[0].content, `Hello Before`);
});


test("#188: Content preprocessing (array, no dot in file extension)", async (t) => {
let elev = new Eleventy("./test/stubs-virtual/", undefined, {
config: eleventyConfig => {
eleventyConfig.addPreprocessor("drafts", ["njk"], (data, content) => {
if(data.draft) {
return false;
}
return `Hello ${content}`;
});

eleventyConfig.addTemplate("index.njk", "Before");
eleventyConfig.addTemplate("draft.njk", "Before", { draft: true });
}
});

let results = await elev.toJSON();
t.is(results.length, 1);
t.is(results[0].content, `Hello Before`);
});

test("#188: Content preprocessing (array, dot in file extension)", async (t) => {
let elev = new Eleventy("./test/stubs-virtual/", undefined, {
config: eleventyConfig => {
eleventyConfig.addPreprocessor("drafts", [".njk"], (data, content) => {
if(data.draft) {
return false;
}
return `Hello ${content}`;
});

eleventyConfig.addTemplate("index.njk", "Before");
eleventyConfig.addTemplate("draft.njk", "Before", { draft: true });
}
});

let results = await elev.toJSON();
t.is(results.length, 1);
t.is(results[0].content, `Hello Before`);
});


test("#3373: Throw an error when explicit config path is not found.", async (t) => {
let elev = new Eleventy("./test/stubs-virtual/", undefined, {
configPath: "this-file-is-not-found.js"
Expand Down

0 comments on commit 03d1cfd

Please sign in to comment.