From 9d7666af686ff7ca33488b88d9f46dacee70e878 Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Thu, 27 Jun 2024 15:51:14 -0500 Subject: [PATCH] Add a non-YAML input test for #867 --- test/EleventyTest-CustomDateParsing.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/EleventyTest-CustomDateParsing.js b/test/EleventyTest-CustomDateParsing.js index 75327f0d5..04ca2fba3 100644 --- a/test/EleventyTest-CustomDateParsing.js +++ b/test/EleventyTest-CustomDateParsing.js @@ -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) => { @@ -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);