forked from approvals/Approvals.NodeJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadmeTests.js
95 lines (83 loc) · 3.03 KB
/
readmeTests.js
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
var path = require("path");
var fs = require("fs");
var StringWriter = require("../lib/StringWriter").StringWriter;
var approvals = require("../lib/Approvals");
var jsdoc2md = require("jsdoc-to-markdown");
describe("Readme", function () {
it("Should not allow the readme docs to get out of sync", function () {
var currentReadme = fs
.readFileSync(path.join(__dirname, "../", "readme.md"))
.toString();
var cliDocsRaw = fs
.readFileSync(path.join(__dirname, "../bin", "help.md"))
.toString();
cliDocsRaw = cliDocsRaw.replace(/ /g, " ").replace(/\*\*/g, "");
var approvalsSource = fs
.readFileSync(path.join(__dirname, "../lib", "Approvals.js"))
.toString();
var jsdocsOutput = jsdoc2md.renderSync({
source: approvalsSource,
"no-cache": true,
});
jsdocsOutput = jsdocsOutput
.split("\n")
.map(function (line) {
return line.replace(/\s+$/, "");
})
.join("\n");
var 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-->";
var 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-->";
var 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(__dirname, "../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-->";
var 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,
);
var config = approvals.getConfig();
config.EOL = "\n";
config.normalizeLineEndingsTo = "\n";
console.log(config);
var writer = new StringWriter(
config,
resultingReadme.replace(/(?:\r\n|\r|\n)/g, "\n"),
);
var namer = {
getReceivedFile: function () {
return path.join(__dirname, "..", "readme.received.md");
},
getApprovedFile: function () {
return path.join(__dirname, "..", "readme.md");
},
};
approvals.verifyWithControl(namer, writer, null, config);
});
});