2019-10-30 20:37:06 -07:00
|
|
|
// @ts-check
|
|
|
|
|
|
2016-10-06 21:44:39 -07:00
|
|
|
"use strict";
|
|
|
|
|
|
2018-04-27 22:05:34 -07:00
|
|
|
const fs = require("fs");
|
|
|
|
|
const path = require("path");
|
|
|
|
|
const glob = require("glob");
|
|
|
|
|
const markdownlint = require("../lib/markdownlint");
|
2020-01-06 22:09:07 -08:00
|
|
|
const { utf8Encoding } = require("../helpers");
|
2016-10-06 21:44:39 -07:00
|
|
|
|
2020-01-06 22:09:07 -08:00
|
|
|
// Simulates typing each test file to validate handling of partial input
|
|
|
|
|
const files = fs.readdirSync("./test");
|
|
|
|
|
files.filter((file) => /\.md$/.test(file)).forEach((file) => {
|
|
|
|
|
const strings = {};
|
|
|
|
|
let content = fs.readFileSync(path.join("./test", file), utf8Encoding);
|
|
|
|
|
while (content) {
|
|
|
|
|
strings[content.length.toString()] = content;
|
|
|
|
|
content = content.slice(0, -1);
|
|
|
|
|
}
|
|
|
|
|
module.exports[`type ${file}`] = (test) => {
|
|
|
|
|
markdownlint.sync({
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
strings,
|
2017-07-05 21:53:21 -07:00
|
|
|
"resultVersion": 0
|
2016-10-06 21:44:39 -07:00
|
|
|
});
|
2020-01-06 22:09:07 -08:00
|
|
|
test.done();
|
|
|
|
|
};
|
|
|
|
|
});
|
2016-10-06 21:44:39 -07:00
|
|
|
|
2020-01-06 22:09:07 -08:00
|
|
|
// Parses all Markdown files in all package dependencies
|
|
|
|
|
module.exports.parseAllFiles = (test) => {
|
2018-04-27 22:05:34 -07:00
|
|
|
const globOptions = {
|
2016-10-06 21:44:39 -07:00
|
|
|
// "cwd": "/",
|
|
|
|
|
"realpath": true
|
|
|
|
|
};
|
2020-01-06 22:09:07 -08:00
|
|
|
glob("**/*.{md,markdown}", globOptions, (err, matches) => {
|
2016-10-06 21:44:39 -07:00
|
|
|
test.ifError(err);
|
2018-04-27 22:05:34 -07:00
|
|
|
const markdownlintOptions = {
|
2016-10-06 21:44:39 -07:00
|
|
|
"files": matches
|
|
|
|
|
};
|
2020-01-06 22:09:07 -08:00
|
|
|
markdownlint(markdownlintOptions, (errr) => {
|
2016-10-06 21:44:39 -07:00
|
|
|
test.ifError(errr);
|
|
|
|
|
test.done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|