Skip to content

Commit

Permalink
New line consistency in tests (again) #1206
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Dec 16, 2023
1 parent b1820c6 commit eb13d06
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 21 deletions.
17 changes: 6 additions & 11 deletions test/EleventyTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import TemplateMap from "../src/TemplateMap.js";
import TemplateConfig from "../src/TemplateConfig.js";
import DateGitFirstAdded from "../src/Util/DateGitFirstAdded.js";
import DateGitLastUpdated from "../src/Util/DateGitLastUpdated.js";
import normalizeNewLines from "./Util/normalizeNewLines.js";
import { normalizeNewLines, normalizeNewLinesInObject } from "./Util/normalizeNewLines.js";

const fsp = fs.promises;
const lodashGet = lodash.get;
Expand Down Expand Up @@ -226,8 +226,7 @@ test("Eleventy to json", async (t) => {
url: "/test/",
inputPath: "./test/stubs--to/test.md",
outputPath: "_site/test/index.html",
rawInput: `# hi
`,
rawInput: "# hi\n",
content: "<h1>hi</h1>\n",
},
]
Expand Down Expand Up @@ -262,8 +261,7 @@ test("Eleventy to ndjson", async (t) => {
url: "/test/",
inputPath: "./test/stubs--to/test.md",
outputPath: "_site/test/index.html",
rawInput: `# hi
`,
rawInput: "# hi\n",
content: "<h1>hi</h1>\n",
});
}
Expand Down Expand Up @@ -300,8 +298,7 @@ test("Eleventy to ndjson (returns a stream)", async (t) => {
url: "/test/",
inputPath: "./test/stubs--to/test.md",
outputPath: "_site/test/index.html",
rawInput: `# hi
`,
rawInput: "# hi\n",
content: "<h1>hi</h1>\n",
});
}
Expand Down Expand Up @@ -367,8 +364,7 @@ test("Eleventy programmatic API without init", async (t) => {
url: "/test/",
inputPath: "./test/stubs--to/test.md",
outputPath: "_site/test/index.html",
rawInput: `# hi
`,
rawInput: "# hi\n",
content: "<h1>hi</h1>\n",
},
]
Expand Down Expand Up @@ -400,8 +396,7 @@ test("Can Eleventy run two executeBuilds in parallel?", async (t) => {
url: "/test/",
inputPath: "./test/stubs--to/test.md",
outputPath: "_site/test/index.html",
rawInput: `# hi
`,
rawInput: "# hi\n",
content: "<h1>hi</h1>\n",
},
];
Expand Down
2 changes: 1 addition & 1 deletion test/HtmlBasePluginTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import test from "ava";

import { default as HtmlBasePlugin, applyBaseToUrl } from "../src/Plugins/HtmlBasePlugin.js";
import Eleventy from "../src/Eleventy.js";
import normalizeNewLines from "./Util/normalizeNewLines.js";
import { normalizeNewLines } from "./Util/normalizeNewLines.js";

function getContentFor(results, filename) {
let content = results.filter((entry) => entry.outputPath.endsWith(filename))[0].content;
Expand Down
2 changes: 1 addition & 1 deletion test/I18nPluginTest.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test from "ava";
import { Comparator, LangUtils, default as I18nPlugin } from "../src/Plugins/I18nPlugin.js";
import Eleventy from "../src/Eleventy.js";
import normalizeNewLines from "./Util/normalizeNewLines.js";
import { normalizeNewLines } from "./Util/normalizeNewLines.js";

test("Comparator.isLangCode", (t) => {
t.is(Comparator.isLangCode(null), false);
Expand Down
2 changes: 1 addition & 1 deletion test/TemplateMapTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import TemplateMap from "../src/TemplateMap.js";
import TemplateCollection from "../src/TemplateCollection.js";
import UsingCircularTemplateContentReferenceError from "../src/Errors/UsingCircularTemplateContentReferenceError.js";
import TemplateContentUnrenderedTemplateError from "../src/Errors/TemplateContentUnrenderedTemplateError.js";
import normalizeNewLines from "./Util/normalizeNewLines.js";
import { normalizeNewLines } from "./Util/normalizeNewLines.js";
import TemplateConfig from "../src/TemplateConfig.js";
import getNewTemplateForTests from "./_getNewTemplateForTests.js";
import { getRenderedTemplates as getRenderedTmpls, renderTemplate } from "./_getRenderedTemplates.js";
Expand Down
2 changes: 1 addition & 1 deletion test/TemplateRenderMarkdownTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import TemplateConfig from "../src/TemplateConfig.js";
import Liquid from "../src/Engines/Liquid.js";
import Nunjucks from "../src/Engines/Nunjucks.js";
import EleventyExtensionMap from "../src/EleventyExtensionMap.js";
import normalizeNewLines from "./Util/normalizeNewLines.js";
import { normalizeNewLines } from "./Util/normalizeNewLines.js";

async function getNewTemplateRender(name, inputDir, eleventyConfig) {
if (!eleventyConfig) {
Expand Down
2 changes: 1 addition & 1 deletion test/TemplateRenderNunjucksTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Nunjucks from "nunjucks";
import TemplateRender from "../src/TemplateRender.js";
import TemplateConfig from "../src/TemplateConfig.js";
import EleventyExtensionMap from "../src/EleventyExtensionMap.js";
import normalizeNewLines from "./Util/normalizeNewLines.js";
import { normalizeNewLines } from "./Util/normalizeNewLines.js";

async function getNewTemplateRender(name, inputDir, eleventyConfig) {
if (!eleventyConfig) {
Expand Down
2 changes: 1 addition & 1 deletion test/TemplateRenderPluginTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
RenderManager,
} from "../src/Plugins/RenderPlugin.js";
import Eleventy from "../src/Eleventy.js";
import normalizeNewLines from "./Util/normalizeNewLines.js";
import { normalizeNewLines } from "./Util/normalizeNewLines.js";

async function getTestOutput(input, configCallback = function () {}) {
let elev = new Eleventy(input, "./_site/", {
Expand Down
2 changes: 1 addition & 1 deletion test/TemplateTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import FileSystemSearch from "../src/FileSystemSearch.js";
import EleventyExtensionMap from "../src/EleventyExtensionMap.js";
import EleventyErrorUtil from "../src/EleventyErrorUtil.js";
import TemplateContentPrematureUseError from "../src/Errors/TemplateContentPrematureUseError.js";
import normalizeNewLines from "./Util/normalizeNewLines.js";
import { normalizeNewLines } from "./Util/normalizeNewLines.js";
import eventBus from "../src/EventBus.js";
import getNewTemplate from "./_getNewTemplateForTests.js";
import { getRenderedTemplates as getRenderedTmpls, renderLayout, renderTemplate } from "./_getRenderedTemplates.js";
Expand Down
2 changes: 1 addition & 1 deletion test/TemplateWriterTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import EleventyFiles from "../src/EleventyFiles.js";
import EleventyExtensionMap from "../src/EleventyExtensionMap.js";
import TemplateWriter from "../src/TemplateWriter.js";
import TemplateConfig from "../src/TemplateConfig.js";
import normalizeNewLines from "./Util/normalizeNewLines.js";
import { normalizeNewLines } from "./Util/normalizeNewLines.js";
import { getRenderedTemplates as getRenderedTmpls } from "./_getRenderedTemplates.js";

// TODO make sure if output is a subdir of input dir that they don’t conflict.
Expand Down
2 changes: 1 addition & 1 deletion test/TestUtilityTest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from "ava";
import normalizeNewLines from "./Util/normalizeNewLines.js";
import { normalizeNewLines } from "./Util/normalizeNewLines.js";

test("normalizeNewLines", (t) => {
t.is(normalizeNewLines("\n"), "\n");
Expand Down
13 changes: 12 additions & 1 deletion test/Util/normalizeNewLines.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,15 @@ function normalizeNewLines(str) {
return str.replace(/\r\n/g, "\n");
}

export default normalizeNewLines;
function normalizeNewLinesInObject(obj) {
for(let key in obj) {
if(typeof obj[key] === "string") {
obj[key] = normalizeNewLines(obj[key]);
}
}
}

export {
normalizeNewLines,
normalizeNewLinesInObject,
};

0 comments on commit eb13d06

Please sign in to comment.