import path from "path"; import fs from "fs"; import { StringWriter } from "../lib/StringWriter.js"; import * as approvals from "../lib/Approvals.js"; import jsdoc2md from "jsdoc-to-markdown"; import { testDirectory } from "./testPaths.mjs"; describe("Readme", function () { it("Should not allow the readme docs to get out of sync", async function () { const currentReadme = fs .readFileSync(path.join(testDirectory, "../", "readme.md")) .toString(); let cliDocsRaw = fs .readFileSync(path.join(testDirectory, "../bin", "help.md")) .toString(); cliDocsRaw = cliDocsRaw.replace(/ /g, " ").replace(/\*\*/g, ""); const approvalsSource = fs .readFileSync(path.join(testDirectory, "../lib", "Approvals.js")) .toString(); let jsdocsOutput = await jsdoc2md.render({ source: approvalsSource, "no-cache": true, }); jsdocsOutput = jsdocsOutput .split("\n") .map(function (line) { return line.replace(/\s+$/, ""); }) .join("\n"); let newDocs = ""; newDocs += "\n"; newDocs += "\n"; newDocs += "\n\n" + jsdocsOutput; newDocs += "\n\n"; let cliDocs = ""; cliDocs += "\n"; cliDocs += "\n"; cliDocs += "\n```"; cliDocs += "\n\n" + cliDocsRaw; cliDocs += "\n```"; cliDocs += "\n\n"; let reporterList = ""; reporterList += "\n"; reporterList += "\n"; reporterList += "\n```"; reporterList += "\n["; reporterList += '\n "' + fs .readdirSync(path.join(testDirectory, "../lib/Reporting/Reporters")) .map(function (item) { return item.substr(0, item.indexOf("Reporter.js")); }) .join('",\n "') + '"'; reporterList += "\n]"; reporterList += "\n```"; reporterList += "\n"; const resultingReadme = currentReadme .replace(/[\s\S]*/gm, newDocs) .replace(/[\s\S]*/gm, cliDocs) .replace( /[\s\S]*/gm, reporterList, ); const config = approvals.getConfig(); config.EOL = "\n"; config.normalizeLineEndingsTo = "\n"; console.log(config); const writer = new StringWriter( config, resultingReadme.replace(/(?:\r\n|\r|\n)/g, "\n"), ); const namer = { getReceivedFile: function () { return path.join(testDirectory, "..", "readme.received.md"); }, getApprovedFile: function () { return path.join(testDirectory, "..", "readme.md"); }, }; approvals.verifyWithControl(namer, writer, null, config); }); });