mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Add synchronous version of the API, with tests and documentation.
This commit is contained in:
parent
200dddf3d1
commit
e557f3a97f
6 changed files with 132 additions and 18 deletions
|
@ -65,7 +65,7 @@ function createTestForFile(file) {
|
|||
};
|
||||
}
|
||||
|
||||
fs.readdirSync("./test").forEach(function forFile(file) { // eslint-disable-line
|
||||
fs.readdirSync("./test").forEach(function forFile(file) {
|
||||
if (file.match(/\.md$/)) {
|
||||
module.exports[file] = createTestForFile(path.join("./test", file));
|
||||
}
|
||||
|
@ -122,6 +122,42 @@ module.exports.resultFormatting = function resultFormatting(test) {
|
|||
});
|
||||
};
|
||||
|
||||
module.exports.resultFormattingSync = function resultFormattingSync(test) {
|
||||
test.expect(2);
|
||||
var options = {
|
||||
"files": [
|
||||
"./test/atx_header_spacing.md",
|
||||
"./test/first_header_bad_atx.md"
|
||||
]
|
||||
};
|
||||
var actualResult = markdownlint.sync(options);
|
||||
var expectedResult = {
|
||||
"./test/atx_header_spacing.md": {
|
||||
"MD002": [ 3 ],
|
||||
"MD018": [ 1 ],
|
||||
"MD019": [ 3, 5 ]
|
||||
},
|
||||
"./test/first_header_bad_atx.md": {
|
||||
"MD002": [ 1 ]
|
||||
}
|
||||
};
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
var actualMessage = actualResult.toString();
|
||||
var expectedMessage =
|
||||
"./test/atx_header_spacing.md: 3: MD002" +
|
||||
" First header should be a h1 header\n" +
|
||||
"./test/atx_header_spacing.md: 1: MD018" +
|
||||
" No space after hash on atx style header\n" +
|
||||
"./test/atx_header_spacing.md: 3: MD019" +
|
||||
" Multiple spaces after hash on atx style header\n" +
|
||||
"./test/atx_header_spacing.md: 5: MD019" +
|
||||
" Multiple spaces after hash on atx style header\n" +
|
||||
"./test/first_header_bad_atx.md: 1: MD002" +
|
||||
" First header should be a h1 header";
|
||||
test.equal(actualMessage, expectedMessage, "Incorrect message.");
|
||||
test.done();
|
||||
};
|
||||
|
||||
module.exports.defaultTrue = function defaultTrue(test) {
|
||||
test.expect(2);
|
||||
var options = {
|
||||
|
@ -435,17 +471,32 @@ module.exports.missingCallback = function missingCallback(test) {
|
|||
};
|
||||
|
||||
module.exports.badFile = function badFile(test) {
|
||||
test.expect(3);
|
||||
test.expect(4);
|
||||
markdownlint({
|
||||
"files": [ "./badFile" ]
|
||||
}, function callback(err, result) {
|
||||
test.ok(err, "Did not get an error for bad file.");
|
||||
test.ok(err instanceof Error, "Error not instance of Error.");
|
||||
test.equal(err.code, "ENOENT", "Error code for bad file not ENOENT.");
|
||||
test.ok(!result, "Got result for bad file.");
|
||||
test.done();
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.badFileSync = function badFileSync(test) {
|
||||
test.expect(3);
|
||||
test.throws(function badFileCall() {
|
||||
markdownlint.sync({
|
||||
"files": [ "./badFile" ]
|
||||
});
|
||||
}, function testError(err) {
|
||||
test.ok(err instanceof Error, "Error not instance of Error.");
|
||||
test.equal(err.code, "ENOENT", "Error code for bad file not ENOENT.");
|
||||
return true;
|
||||
}, "Did not get exception for bad file.");
|
||||
test.done();
|
||||
};
|
||||
|
||||
module.exports.readme = function readme(test) {
|
||||
test.expect(143);
|
||||
fs.readFile("README.md", shared.utf8Encoding,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue