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");
|
2020-05-08 15:28:38 -07:00
|
|
|
const globby = require("globby");
|
2021-01-10 20:46:00 -08:00
|
|
|
const test = require("ava").default;
|
2018-04-27 22:05:34 -07:00
|
|
|
const markdownlint = require("../lib/markdownlint");
|
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 = {};
|
2021-01-10 20:46:00 -08:00
|
|
|
let content = fs.readFileSync(path.join("./test", file), "utf8");
|
2020-01-06 22:09:07 -08:00
|
|
|
while (content) {
|
|
|
|
|
strings[content.length.toString()] = content;
|
|
|
|
|
content = content.slice(0, -1);
|
|
|
|
|
}
|
2021-01-10 20:46:00 -08:00
|
|
|
test(`type ${file}`, (t) => {
|
|
|
|
|
t.plan(1);
|
2020-01-06 22:09:07 -08:00
|
|
|
markdownlint.sync({
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
strings,
|
2017-07-05 21:53:21 -07:00
|
|
|
"resultVersion": 0
|
2016-10-06 21:44:39 -07:00
|
|
|
});
|
2021-01-10 20:46:00 -08:00
|
|
|
t.pass();
|
2020-01-08 22:13:51 -08:00
|
|
|
});
|
2020-01-06 22:09:07 -08:00
|
|
|
});
|
2016-10-06 21:44:39 -07:00
|
|
|
|
2020-01-06 22:09:07 -08:00
|
|
|
// Parses all Markdown files in all package dependencies
|
2021-01-10 20:46:00 -08:00
|
|
|
test.cb("parseAllFiles", (t) => {
|
|
|
|
|
t.plan(1);
|
2020-05-08 15:28:38 -07:00
|
|
|
const options = {
|
|
|
|
|
"files": globby.sync("**/*.{md,markdown}")
|
2016-10-06 21:44:39 -07:00
|
|
|
};
|
2020-05-08 15:28:38 -07:00
|
|
|
markdownlint(options, (err) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
|
|
|
|
t.end();
|
2016-10-06 21:44:39 -07:00
|
|
|
});
|
2020-01-08 22:13:51 -08:00
|
|
|
});
|