-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathreadmeTests.mts
95 lines (84 loc) · 3.11 KB
/
readmeTests.mts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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 = "<!--BEGIN-API-DOCS-->";
newDocs += "\n<!-- GENERATED - DO NOT MODIFY API DOCS IN THIS README -->";
newDocs += "\n<!-- Update docs in the source ./lib/Approvals.js -->";
newDocs += "\n\n" + jsdocsOutput;
newDocs += "\n\n<!--END-API-DOCS-->";
let cliDocs = "<!--BEGIN-CLI-DOCS-->";
cliDocs += "\n<!-- GENERATED - DO NOT MODIFY API DOCS IN THIS README -->";
cliDocs += "\n<!-- Update docs in the source ./bin/help.md -->";
cliDocs += "\n```";
cliDocs += "\n\n" + cliDocsRaw;
cliDocs += "\n```";
cliDocs += "\n\n<!--END-CLI-DOCS-->";
let reporterList = "<!--BEGIN-REPORTERS-LIST-->";
reporterList += "\n<!-- GENERATED - DO NOT MODIFY THIS LIST -->";
reporterList +=
"\n<!-- Auto-Generated from folder of reporters in ./lib/Reporting/Reporters/* -->";
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<!--END-REPORTERS-LIST-->";
const resultingReadme = currentReadme
.replace(/<!--BEGIN-API-DOCS-->[\s\S]*<!--END-API-DOCS-->/gm, newDocs)
.replace(/<!--BEGIN-CLI-DOCS-->[\s\S]*<!--END-CLI-DOCS-->/gm, cliDocs)
.replace(
/<!--BEGIN-REPORTERS-LIST-->[\s\S]*<!--END-REPORTERS-LIST-->/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);
});
});