mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Test case improvements for correctness, detail, and performance.
This commit is contained in:
parent
5ce30c6156
commit
61e0ac314c
3 changed files with 24 additions and 37 deletions
|
|
@ -19,7 +19,7 @@
|
|||
"test-extra": "nodeunit test/markdownlint-test-extra.js",
|
||||
"debug": "node debug node_modules/nodeunit/bin/nodeunit",
|
||||
"lint": "eslint lib helpers test schema && eslint --env browser --global markdownit --global markdownlint --rule \"no-unused-vars: 0, no-extend-native: 0, max-statements: 0, no-console: 0, no-var: 0\" demo && eslint --rule \"no-console: 0, no-invalid-this: 0, no-shadow: 0, object-property-newline: 0\" example",
|
||||
"ci": "npm run test && npm run lint && npm run test-cover && npm run test-declaration",
|
||||
"ci": "npm run test-cover && npm run lint && npm run test-declaration",
|
||||
"build-config-schema": "node schema/build-config-schema.js",
|
||||
"build-declaration": "tsc --allowJs --declaration --outDir declaration --resolveJsonModule lib/markdownlint.js && cpy declaration/lib/markdownlint.d.ts lib && rimraf declaration",
|
||||
"build-demo": "cpy node_modules/markdown-it/dist/markdown-it.min.js demo && cd demo && rimraf markdownlint-browser.* && cpy file-header.js . --rename=markdownlint-browser.js && tsc --allowJs --resolveJsonModule --outDir ../lib-es3 ../lib/markdownlint.js && cpy ../helpers/package.json ../lib-es3/helpers && browserify ../lib-es3/lib/markdownlint.js --standalone markdownlint >> markdownlint-browser.js && uglifyjs markdownlint-browser.js --compress --mangle --comments --output markdownlint-browser.min.js",
|
||||
|
|
|
|||
|
|
@ -6,52 +6,39 @@ const fs = require("fs");
|
|||
const path = require("path");
|
||||
const glob = require("glob");
|
||||
const markdownlint = require("../lib/markdownlint");
|
||||
const { newLineRe, utf8Encoding } = require("../helpers");
|
||||
const { utf8Encoding } = require("../helpers");
|
||||
|
||||
module.exports.typeTestFiles = function typeTestFiles(test) {
|
||||
// Simulates typing each test file to validate handling of partial input
|
||||
function validate(file, content) {
|
||||
const results = markdownlint.sync({
|
||||
"strings": {
|
||||
"content": content
|
||||
},
|
||||
"resultVersion": 0
|
||||
});
|
||||
const contentLineCount = content.split(newLineRe).length;
|
||||
Object.keys(results.content).forEach(function forKey(ruleName) {
|
||||
results.content[ruleName].forEach(function forLine(line) {
|
||||
test.ok((line >= 1) && (line <= contentLineCount),
|
||||
"Line number out of range: " + line +
|
||||
" (" + file + ", " + content.length + ", " + ruleName + ")");
|
||||
});
|
||||
});
|
||||
}
|
||||
const files = fs.readdirSync("./test");
|
||||
files.forEach(function forFile(file) {
|
||||
if (/\.md$/.test(file)) {
|
||||
let content = fs.readFileSync(
|
||||
path.join("./test", file), utf8Encoding);
|
||||
// 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) {
|
||||
validate(file, content);
|
||||
strings[content.length.toString()] = content;
|
||||
content = content.slice(0, -1);
|
||||
}
|
||||
}
|
||||
module.exports[`type ${file}`] = (test) => {
|
||||
markdownlint.sync({
|
||||
// @ts-ignore
|
||||
strings,
|
||||
"resultVersion": 0
|
||||
});
|
||||
test.done();
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
module.exports.parseAllFiles = function parseAllFiles(test) {
|
||||
// Parses all Markdown files in all dependencies
|
||||
// Parses all Markdown files in all package dependencies
|
||||
module.exports.parseAllFiles = (test) => {
|
||||
const globOptions = {
|
||||
// "cwd": "/",
|
||||
"realpath": true
|
||||
};
|
||||
glob("**/*.{md,markdown}", globOptions, function globCallback(err, matches) {
|
||||
glob("**/*.{md,markdown}", globOptions, (err, matches) => {
|
||||
test.ifError(err);
|
||||
const markdownlintOptions = {
|
||||
"files": matches
|
||||
};
|
||||
markdownlint(markdownlintOptions, function markdownlintCallback(errr) {
|
||||
markdownlint(markdownlintOptions, (errr) => {
|
||||
test.ifError(errr);
|
||||
test.done();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2823,12 +2823,12 @@ module.exports.someCustomRulesHaveValidUrl =
|
|||
(Object.getPrototypeOf(rule.information) === URL.prototype));
|
||||
if (rule === customRules.anyBlockquote) {
|
||||
test.equal(
|
||||
rule.information,
|
||||
rule.information.href,
|
||||
`${homepage}/blob/master/test/rules/any-blockquote.js`
|
||||
);
|
||||
} else if (rule === customRules.lettersEX) {
|
||||
test.equal(
|
||||
rule.information,
|
||||
rule.information.href,
|
||||
`${homepage}/blob/master/test/rules/letters-E-X.js`
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue