mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 14:30: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",
|
"test-extra": "nodeunit test/markdownlint-test-extra.js",
|
||||||
"debug": "node debug node_modules/nodeunit/bin/nodeunit",
|
"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",
|
"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-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-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",
|
"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 path = require("path");
|
||||||
const glob = require("glob");
|
const glob = require("glob");
|
||||||
const markdownlint = require("../lib/markdownlint");
|
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
|
||||||
// Simulates typing each test file to validate handling of partial input
|
const files = fs.readdirSync("./test");
|
||||||
function validate(file, content) {
|
files.filter((file) => /\.md$/.test(file)).forEach((file) => {
|
||||||
const results = markdownlint.sync({
|
const strings = {};
|
||||||
"strings": {
|
let content = fs.readFileSync(path.join("./test", file), utf8Encoding);
|
||||||
"content": content
|
while (content) {
|
||||||
},
|
strings[content.length.toString()] = content;
|
||||||
|
content = content.slice(0, -1);
|
||||||
|
}
|
||||||
|
module.exports[`type ${file}`] = (test) => {
|
||||||
|
markdownlint.sync({
|
||||||
|
// @ts-ignore
|
||||||
|
strings,
|
||||||
"resultVersion": 0
|
"resultVersion": 0
|
||||||
});
|
});
|
||||||
const contentLineCount = content.split(newLineRe).length;
|
test.done();
|
||||||
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);
|
|
||||||
while (content) {
|
|
||||||
validate(file, content);
|
|
||||||
content = content.slice(0, -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
test.done();
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.parseAllFiles = function parseAllFiles(test) {
|
// Parses all Markdown files in all package dependencies
|
||||||
// Parses all Markdown files in all dependencies
|
module.exports.parseAllFiles = (test) => {
|
||||||
const globOptions = {
|
const globOptions = {
|
||||||
// "cwd": "/",
|
// "cwd": "/",
|
||||||
"realpath": true
|
"realpath": true
|
||||||
};
|
};
|
||||||
glob("**/*.{md,markdown}", globOptions, function globCallback(err, matches) {
|
glob("**/*.{md,markdown}", globOptions, (err, matches) => {
|
||||||
test.ifError(err);
|
test.ifError(err);
|
||||||
const markdownlintOptions = {
|
const markdownlintOptions = {
|
||||||
"files": matches
|
"files": matches
|
||||||
};
|
};
|
||||||
markdownlint(markdownlintOptions, function markdownlintCallback(errr) {
|
markdownlint(markdownlintOptions, (errr) => {
|
||||||
test.ifError(errr);
|
test.ifError(errr);
|
||||||
test.done();
|
test.done();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -2823,12 +2823,12 @@ module.exports.someCustomRulesHaveValidUrl =
|
||||||
(Object.getPrototypeOf(rule.information) === URL.prototype));
|
(Object.getPrototypeOf(rule.information) === URL.prototype));
|
||||||
if (rule === customRules.anyBlockquote) {
|
if (rule === customRules.anyBlockquote) {
|
||||||
test.equal(
|
test.equal(
|
||||||
rule.information,
|
rule.information.href,
|
||||||
`${homepage}/blob/master/test/rules/any-blockquote.js`
|
`${homepage}/blob/master/test/rules/any-blockquote.js`
|
||||||
);
|
);
|
||||||
} else if (rule === customRules.lettersEX) {
|
} else if (rule === customRules.lettersEX) {
|
||||||
test.equal(
|
test.equal(
|
||||||
rule.information,
|
rule.information.href,
|
||||||
`${homepage}/blob/master/test/rules/letters-E-X.js`
|
`${homepage}/blob/master/test/rules/letters-E-X.js`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue