Skip to content

Commit

Permalink
Add a non-YAML input test for #867
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jun 27, 2024
1 parent 97ce2bf commit 9d7666a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/EleventyTest-CustomDateParsing.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import test from "ava";
import { DateTime } from "luxon";
import Eleventy from "../src/Eleventy.js";

test("Custom date parsing callback (return string), Issue #867", async (t) => {
Expand All @@ -22,6 +23,29 @@ test("Custom date parsing callback (return string), Issue #867", async (t) => {
t.deepEqual(result.data.page.date, new Date(Date.UTC(2001,0,1,12)));
});

test("Custom date parsing callback (input a non-YAML date format), Issue #867", async (t) => {
t.plan(2);

let elev = new Eleventy("./test/stubs-virtual/", "./test/stubs-virtual/", {
config: eleventyConfig => {
eleventyConfig.addTemplate("test.html", `---
date: 2019-08-31 23:59:56 America/New_York
---
# Markdown`);
eleventyConfig.dataFilterSelectors.add("page.date");

eleventyConfig.addDateParsing(function(dateValue) {
t.is(dateValue, "2019-08-31 23:59:56 America/New_York");
return DateTime.fromFormat(dateValue, "yyyy-MM-dd hh:mm:ss z");
});
}
});
elev.disableLogger();

let [result] = await elev.toJSON();
t.deepEqual(result.data.page.date, new Date(Date.UTC(2019,8,1,3,59,56)));
});

test("Custom date parsing callback (return Date), Issue #867", async (t) => {
t.plan(3);

Expand Down

0 comments on commit 9d7666a

Please sign in to comment.