mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Convert from tape test harness to ava, address minor declaration file issue.
This commit is contained in:
parent
80069552b4
commit
49945d6601
12 changed files with 665 additions and 679 deletions
|
|
@ -2,16 +2,15 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const tape = require("tape");
|
||||
require("tape-player");
|
||||
const test = require("ava").default;
|
||||
const packageJson = require("../package.json");
|
||||
const markdownlint = require("../lib/markdownlint");
|
||||
const customRules = require("./rules/rules.js");
|
||||
const homepage = packageJson.homepage;
|
||||
const version = packageJson.version;
|
||||
|
||||
tape("customRulesV0", (test) => {
|
||||
test.plan(4);
|
||||
test.cb("customRulesV0", (t) => {
|
||||
t.plan(4);
|
||||
const customRulesMd = "./test/custom-rules.md";
|
||||
const options = {
|
||||
"customRules": customRules.all,
|
||||
|
|
@ -19,7 +18,7 @@ tape("customRulesV0", (test) => {
|
|||
"resultVersion": 0
|
||||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
t.falsy(err);
|
||||
const expectedResult = {};
|
||||
expectedResult[customRulesMd] = {
|
||||
"any-blockquote": [ 12 ],
|
||||
|
|
@ -27,7 +26,7 @@ tape("customRulesV0", (test) => {
|
|||
"first-line": [ 1 ],
|
||||
"letters-E-X": [ 3, 7 ]
|
||||
};
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
let actualMessage = actualResult.toString();
|
||||
let expectedMessage =
|
||||
"./test/custom-rules.md: 12: any-blockquote" +
|
||||
|
|
@ -48,7 +47,7 @@ tape("customRulesV0", (test) => {
|
|||
" Rule that reports an error for lines with the letters 'EX'\n" +
|
||||
"./test/custom-rules.md: 7: letters-E-X" +
|
||||
" Rule that reports an error for lines with the letters 'EX'";
|
||||
test.equal(actualMessage, expectedMessage, "Incorrect message (name).");
|
||||
t.is(actualMessage, expectedMessage, "Incorrect message (name).");
|
||||
// @ts-ignore
|
||||
actualMessage = actualResult.toString(true);
|
||||
expectedMessage =
|
||||
|
|
@ -70,13 +69,13 @@ tape("customRulesV0", (test) => {
|
|||
" Rule that reports an error for lines with the letters 'EX'\n" +
|
||||
"./test/custom-rules.md: 7: letter-E-letter-X" +
|
||||
" Rule that reports an error for lines with the letters 'EX'";
|
||||
test.equal(actualMessage, expectedMessage, "Incorrect message (alias).");
|
||||
test.end();
|
||||
t.is(actualMessage, expectedMessage, "Incorrect message (alias).");
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
tape("customRulesV1", (test) => {
|
||||
test.plan(3);
|
||||
test.cb("customRulesV1", (t) => {
|
||||
t.plan(3);
|
||||
const customRulesMd = "./test/custom-rules.md";
|
||||
const options = {
|
||||
"customRules": customRules.all,
|
||||
|
|
@ -84,7 +83,7 @@ tape("customRulesV1", (test) => {
|
|||
"resultVersion": 1
|
||||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
t.falsy(err);
|
||||
const expectedResult = {};
|
||||
expectedResult[customRulesMd] = [
|
||||
{ "lineNumber": 12,
|
||||
|
|
@ -163,7 +162,7 @@ tape("customRulesV1", (test) => {
|
|||
"errorContext": "text",
|
||||
"errorRange": null }
|
||||
];
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
const actualMessage = actualResult.toString();
|
||||
const expectedMessage =
|
||||
"./test/custom-rules.md: 12: any-blockquote/any-blockquote" +
|
||||
|
|
@ -187,13 +186,13 @@ tape("customRulesV1", (test) => {
|
|||
"./test/custom-rules.md: 7: letters-E-X/letter-E-letter-X" +
|
||||
" Rule that reports an error for lines with the letters 'EX'" +
|
||||
" [Context: \"text\"]";
|
||||
test.equal(actualMessage, expectedMessage, "Incorrect message.");
|
||||
test.end();
|
||||
t.is(actualMessage, expectedMessage, "Incorrect message.");
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
tape("customRulesV2", (test) => {
|
||||
test.plan(3);
|
||||
test.cb("customRulesV2", (t) => {
|
||||
t.plan(3);
|
||||
const customRulesMd = "./test/custom-rules.md";
|
||||
const options = {
|
||||
"customRules": customRules.all,
|
||||
|
|
@ -201,7 +200,7 @@ tape("customRulesV2", (test) => {
|
|||
"resultVersion": 2
|
||||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
t.falsy(err);
|
||||
const expectedResult = {};
|
||||
expectedResult[customRulesMd] = [
|
||||
{ "lineNumber": 12,
|
||||
|
|
@ -271,7 +270,7 @@ tape("customRulesV2", (test) => {
|
|||
"errorContext": "text",
|
||||
"errorRange": null }
|
||||
];
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
const actualMessage = actualResult.toString();
|
||||
const expectedMessage =
|
||||
"./test/custom-rules.md: 12: any-blockquote" +
|
||||
|
|
@ -295,13 +294,13 @@ tape("customRulesV2", (test) => {
|
|||
"./test/custom-rules.md: 7: letters-E-X/letter-E-letter-X/contains-ex" +
|
||||
" Rule that reports an error for lines with the letters 'EX'" +
|
||||
" [Context: \"text\"]";
|
||||
test.equal(actualMessage, expectedMessage, "Incorrect message.");
|
||||
test.end();
|
||||
t.is(actualMessage, expectedMessage, "Incorrect message.");
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
tape("customRulesConfig", (test) => {
|
||||
test.plan(2);
|
||||
test.cb("customRulesConfig", (t) => {
|
||||
t.plan(2);
|
||||
const customRulesMd = "./test/custom-rules.md";
|
||||
const options = {
|
||||
"customRules": customRules.all,
|
||||
|
|
@ -316,7 +315,7 @@ tape("customRulesConfig", (test) => {
|
|||
"resultVersion": 0
|
||||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
t.falsy(err);
|
||||
const expectedResult = {};
|
||||
expectedResult[customRulesMd] = {
|
||||
"any-blockquote": [ 12 ],
|
||||
|
|
@ -324,13 +323,13 @@ tape("customRulesConfig", (test) => {
|
|||
"first-line": [ 1 ],
|
||||
"letters-E-X": [ 7 ]
|
||||
};
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
test.end();
|
||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
tape("customRulesNpmPackage", (test) => {
|
||||
test.plan(2);
|
||||
test("customRulesNpmPackage", (t) => {
|
||||
t.plan(2);
|
||||
const options = {
|
||||
"customRules": [ require("./rules/npm") ],
|
||||
"strings": {
|
||||
|
|
@ -339,18 +338,18 @@ tape("customRulesNpmPackage", (test) => {
|
|||
"resultVersion": 0
|
||||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
t.falsy(err);
|
||||
const expectedResult = {};
|
||||
expectedResult.string = {
|
||||
"sample-rule": [ 3 ]
|
||||
};
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
test.end();
|
||||
// @ts-ignore
|
||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
});
|
||||
});
|
||||
|
||||
tape("customRulesBadProperty", (test) => {
|
||||
test.plan(23);
|
||||
test("customRulesBadProperty", (t) => {
|
||||
t.plan(23);
|
||||
[
|
||||
{
|
||||
"propertyName": "names",
|
||||
|
|
@ -382,22 +381,22 @@ tape("customRulesBadProperty", (test) => {
|
|||
const options = {
|
||||
"customRules": [ badRule ]
|
||||
};
|
||||
test.throws(
|
||||
t.throws(
|
||||
function badRuleCall() {
|
||||
markdownlint.sync(options);
|
||||
},
|
||||
new RegExp(
|
||||
`Property '${propertyName}' of custom rule at index 0 is incorrect.`
|
||||
),
|
||||
{
|
||||
"message":
|
||||
`Property '${propertyName}' of custom rule at index 0 is incorrect.`
|
||||
},
|
||||
"Did not get correct exception for missing property."
|
||||
);
|
||||
});
|
||||
});
|
||||
test.end();
|
||||
});
|
||||
|
||||
tape("customRulesUsedNameName", (test) => {
|
||||
test.plan(4);
|
||||
test("customRulesUsedNameName", (t) => {
|
||||
t.plan(4);
|
||||
markdownlint({
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -408,19 +407,18 @@ tape("customRulesUsedNameName", (test) => {
|
|||
}
|
||||
]
|
||||
}, function callback(err, result) {
|
||||
test.ok(err, "Did not get an error for duplicate name.");
|
||||
test.ok(err instanceof Error, "Error not instance of Error.");
|
||||
test.equal(err.message,
|
||||
t.truthy(err, "Did not get an error for duplicate name.");
|
||||
t.true(err instanceof Error, "Error not instance of Error.");
|
||||
t.is(err.message,
|
||||
"Name 'NO-missing-SPACE-atx' of custom rule at index 0 is " +
|
||||
"already used as a name or tag.",
|
||||
"Incorrect message for duplicate name.");
|
||||
test.ok(!result, "Got result for duplicate name.");
|
||||
test.end();
|
||||
t.true(!result, "Got result for duplicate name.");
|
||||
});
|
||||
});
|
||||
|
||||
tape("customRulesUsedNameTag", (test) => {
|
||||
test.plan(4);
|
||||
test("customRulesUsedNameTag", (t) => {
|
||||
t.plan(4);
|
||||
markdownlint({
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -431,18 +429,17 @@ tape("customRulesUsedNameTag", (test) => {
|
|||
}
|
||||
]
|
||||
}, function callback(err, result) {
|
||||
test.ok(err, "Did not get an error for duplicate name.");
|
||||
test.ok(err instanceof Error, "Error not instance of Error.");
|
||||
test.equal(err.message,
|
||||
t.truthy(err, "Did not get an error for duplicate name.");
|
||||
t.true(err instanceof Error, "Error not instance of Error.");
|
||||
t.is(err.message,
|
||||
"Name 'HtMl' of custom rule at index 0 is already used as a name or tag.",
|
||||
"Incorrect message for duplicate name.");
|
||||
test.ok(!result, "Got result for duplicate name.");
|
||||
test.end();
|
||||
t.true(!result, "Got result for duplicate name.");
|
||||
});
|
||||
});
|
||||
|
||||
tape("customRulesUsedTagName", (test) => {
|
||||
test.plan(4);
|
||||
test("customRulesUsedTagName", (t) => {
|
||||
t.plan(4);
|
||||
markdownlint({
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -459,19 +456,18 @@ tape("customRulesUsedTagName", (test) => {
|
|||
}
|
||||
]
|
||||
}, function callback(err, result) {
|
||||
test.ok(err, "Did not get an error for duplicate tag.");
|
||||
test.ok(err instanceof Error, "Error not instance of Error.");
|
||||
test.equal(err.message,
|
||||
t.truthy(err, "Did not get an error for duplicate tag.");
|
||||
t.true(err instanceof Error, "Error not instance of Error.");
|
||||
t.is(err.message,
|
||||
"Tag 'NO-missing-SPACE-atx' of custom rule at index 1 is " +
|
||||
"already used as a name.",
|
||||
"Incorrect message for duplicate name.");
|
||||
test.ok(!result, "Got result for duplicate tag.");
|
||||
test.end();
|
||||
t.true(!result, "Got result for duplicate tag.");
|
||||
});
|
||||
});
|
||||
|
||||
tape("customRulesThrowForFile", (test) => {
|
||||
test.plan(4);
|
||||
test.cb("customRulesThrowForFile", (t) => {
|
||||
t.plan(4);
|
||||
const exceptionMessage = "Test exception message";
|
||||
markdownlint({
|
||||
"customRules": [
|
||||
|
|
@ -486,19 +482,19 @@ tape("customRulesThrowForFile", (test) => {
|
|||
],
|
||||
"files": [ "./test/custom-rules.md" ]
|
||||
}, function callback(err, result) {
|
||||
test.ok(err, "Did not get an error for function thrown.");
|
||||
test.ok(err instanceof Error, "Error not instance of Error.");
|
||||
test.equal(err.message, exceptionMessage,
|
||||
t.truthy(err, "Did not get an error for function thrown.");
|
||||
t.true(err instanceof Error, "Error not instance of Error.");
|
||||
t.is(err.message, exceptionMessage,
|
||||
"Incorrect message for function thrown.");
|
||||
test.ok(!result, "Got result for function thrown.");
|
||||
test.end();
|
||||
t.true(!result, "Got result for function thrown.");
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
tape("customRulesThrowForFileSync", (test) => {
|
||||
test.plan(1);
|
||||
test("customRulesThrowForFileSync", (t) => {
|
||||
t.plan(1);
|
||||
const exceptionMessage = "Test exception message";
|
||||
test.throws(
|
||||
t.throws(
|
||||
function customRuleThrowsCall() {
|
||||
markdownlint.sync({
|
||||
"customRules": [
|
||||
|
|
@ -514,14 +510,15 @@ tape("customRulesThrowForFileSync", (test) => {
|
|||
"files": [ "./test/custom-rules.md" ]
|
||||
});
|
||||
},
|
||||
new RegExp(exceptionMessage),
|
||||
{
|
||||
"message": exceptionMessage
|
||||
},
|
||||
"Did not get correct exception for function thrown."
|
||||
);
|
||||
test.end();
|
||||
});
|
||||
|
||||
tape("customRulesThrowForString", (test) => {
|
||||
test.plan(4);
|
||||
test("customRulesThrowForString", (t) => {
|
||||
t.plan(4);
|
||||
const exceptionMessage = "Test exception message";
|
||||
markdownlint({
|
||||
"customRules": [
|
||||
|
|
@ -538,17 +535,16 @@ tape("customRulesThrowForString", (test) => {
|
|||
"string": "String"
|
||||
}
|
||||
}, function callback(err, result) {
|
||||
test.ok(err, "Did not get an error for function thrown.");
|
||||
test.ok(err instanceof Error, "Error not instance of Error.");
|
||||
test.equal(err.message, exceptionMessage,
|
||||
t.truthy(err, "Did not get an error for function thrown.");
|
||||
t.true(err instanceof Error, "Error not instance of Error.");
|
||||
t.is(err.message, exceptionMessage,
|
||||
"Incorrect message for function thrown.");
|
||||
test.ok(!result, "Got result for function thrown.");
|
||||
test.end();
|
||||
t.true(!result, "Got result for function thrown.");
|
||||
});
|
||||
});
|
||||
|
||||
tape("customRulesOnErrorNull", (test) => {
|
||||
test.plan(1);
|
||||
test("customRulesOnErrorNull", (t) => {
|
||||
t.plan(1);
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -564,18 +560,19 @@ tape("customRulesOnErrorNull", (test) => {
|
|||
"string": "String"
|
||||
}
|
||||
};
|
||||
test.throws(
|
||||
t.throws(
|
||||
function nullErrorCall() {
|
||||
markdownlint.sync(options);
|
||||
},
|
||||
/Property 'lineNumber' of onError parameter is incorrect./,
|
||||
{
|
||||
"message": "Property 'lineNumber' of onError parameter is incorrect."
|
||||
},
|
||||
"Did not get correct exception for null object."
|
||||
);
|
||||
test.end();
|
||||
});
|
||||
|
||||
tape("customRulesOnErrorBad", (test) => {
|
||||
test.plan(21);
|
||||
test("customRulesOnErrorBad", (t) => {
|
||||
t.plan(21);
|
||||
[
|
||||
{
|
||||
"propertyName": "lineNumber",
|
||||
|
|
@ -652,22 +649,22 @@ tape("customRulesOnErrorBad", (test) => {
|
|||
"string": "String"
|
||||
}
|
||||
};
|
||||
test.throws(
|
||||
t.throws(
|
||||
function badErrorCall() {
|
||||
markdownlint.sync(options);
|
||||
},
|
||||
new RegExp(
|
||||
`Property '${propertyNames}' of onError parameter is incorrect.`
|
||||
),
|
||||
{
|
||||
"message":
|
||||
`Property '${propertyNames}' of onError parameter is incorrect.`
|
||||
},
|
||||
"Did not get correct exception for bad object."
|
||||
);
|
||||
});
|
||||
});
|
||||
test.end();
|
||||
});
|
||||
|
||||
tape("customRulesOnErrorInvalid", (test) => {
|
||||
test.plan(17);
|
||||
test("customRulesOnErrorInvalid", (t) => {
|
||||
t.plan(17);
|
||||
[
|
||||
{
|
||||
"propertyName": "lineNumber",
|
||||
|
|
@ -724,22 +721,22 @@ tape("customRulesOnErrorInvalid", (test) => {
|
|||
"string": "Text\ntext"
|
||||
}
|
||||
};
|
||||
test.throws(
|
||||
t.throws(
|
||||
function invalidErrorCall() {
|
||||
markdownlint.sync(options);
|
||||
},
|
||||
new RegExp(
|
||||
`Property '${propertyNames}' of onError parameter is incorrect.`
|
||||
),
|
||||
{
|
||||
"message":
|
||||
`Property '${propertyNames}' of onError parameter is incorrect.`
|
||||
},
|
||||
"Did not get correct exception for invalid object."
|
||||
);
|
||||
});
|
||||
});
|
||||
test.end();
|
||||
});
|
||||
|
||||
tape("customRulesOnErrorValid", (test) => {
|
||||
test.plan(24);
|
||||
test("customRulesOnErrorValid", (t) => {
|
||||
t.plan(24);
|
||||
[
|
||||
{
|
||||
"propertyName": "lineNumber",
|
||||
|
|
@ -800,14 +797,13 @@ tape("customRulesOnErrorValid", (test) => {
|
|||
}
|
||||
};
|
||||
markdownlint.sync(options);
|
||||
test.ok(true);
|
||||
t.truthy(true);
|
||||
});
|
||||
});
|
||||
test.end();
|
||||
});
|
||||
|
||||
tape("customRulesOnErrorLazy", (test) => {
|
||||
test.plan(2);
|
||||
test("customRulesOnErrorLazy", (t) => {
|
||||
t.plan(2);
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -829,7 +825,7 @@ tape("customRulesOnErrorLazy", (test) => {
|
|||
}
|
||||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
t.falsy(err);
|
||||
const expectedResult = {
|
||||
"string": [
|
||||
{
|
||||
|
|
@ -843,13 +839,12 @@ tape("customRulesOnErrorLazy", (test) => {
|
|||
}
|
||||
]
|
||||
};
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
test.end();
|
||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
});
|
||||
});
|
||||
|
||||
tape("customRulesOnErrorModified", (test) => {
|
||||
test.plan(2);
|
||||
test("customRulesOnErrorModified", (t) => {
|
||||
t.plan(2);
|
||||
const errorObject = {
|
||||
"lineNumber": 1,
|
||||
"detail": "detail",
|
||||
|
|
@ -885,7 +880,7 @@ tape("customRulesOnErrorModified", (test) => {
|
|||
"resultVersion": 3
|
||||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
t.falsy(err);
|
||||
const expectedResult = {
|
||||
"string": [
|
||||
{
|
||||
|
|
@ -904,13 +899,12 @@ tape("customRulesOnErrorModified", (test) => {
|
|||
}
|
||||
]
|
||||
};
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
test.end();
|
||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
});
|
||||
});
|
||||
|
||||
tape("customRulesThrowForFileHandled", (test) => {
|
||||
test.plan(2);
|
||||
test.cb("customRulesThrowForFileHandled", (t) => {
|
||||
t.plan(2);
|
||||
const exceptionMessage = "Test exception message";
|
||||
markdownlint({
|
||||
"customRules": [
|
||||
|
|
@ -926,7 +920,7 @@ tape("customRulesThrowForFileHandled", (test) => {
|
|||
"files": [ "./test/custom-rules.md" ],
|
||||
"handleRuleFailures": true
|
||||
}, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
t.falsy(err);
|
||||
const expectedResult = {
|
||||
"./test/custom-rules.md": [
|
||||
{
|
||||
|
|
@ -941,13 +935,13 @@ tape("customRulesThrowForFileHandled", (test) => {
|
|||
}
|
||||
]
|
||||
};
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
test.end();
|
||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
tape("customRulesThrowForStringHandled", (test) => {
|
||||
test.plan(2);
|
||||
test("customRulesThrowForStringHandled", (t) => {
|
||||
t.plan(2);
|
||||
const exceptionMessage = "Test exception message";
|
||||
const informationUrl = "https://example.com/rule";
|
||||
markdownlint({
|
||||
|
|
@ -967,7 +961,7 @@ tape("customRulesThrowForStringHandled", (test) => {
|
|||
},
|
||||
"handleRuleFailures": true
|
||||
}, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
t.falsy(err);
|
||||
const expectedResult = {
|
||||
"string": [
|
||||
{
|
||||
|
|
@ -993,13 +987,12 @@ tape("customRulesThrowForStringHandled", (test) => {
|
|||
}
|
||||
]
|
||||
};
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
test.end();
|
||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
});
|
||||
});
|
||||
|
||||
tape("customRulesOnErrorInvalidHandled", (test) => {
|
||||
test.plan(2);
|
||||
test("customRulesOnErrorInvalidHandled", (t) => {
|
||||
t.plan(2);
|
||||
markdownlint({
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -1019,7 +1012,7 @@ tape("customRulesOnErrorInvalidHandled", (test) => {
|
|||
},
|
||||
"handleRuleFailures": true
|
||||
}, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
t.falsy(err);
|
||||
const expectedResult = {
|
||||
"string": [
|
||||
{
|
||||
|
|
@ -1034,13 +1027,12 @@ tape("customRulesOnErrorInvalidHandled", (test) => {
|
|||
}
|
||||
]
|
||||
};
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
test.end();
|
||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
});
|
||||
});
|
||||
|
||||
tape("customRulesFileName", (test) => {
|
||||
test.plan(2);
|
||||
test.cb("customRulesFileName", (t) => {
|
||||
t.plan(2);
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -1048,20 +1040,20 @@ tape("customRulesFileName", (test) => {
|
|||
"description": "description",
|
||||
"tags": [ "tag" ],
|
||||
"function": function stringName(params) {
|
||||
test.equal(params.name, "doc/CustomRules.md", "Incorrect file name");
|
||||
t.is(params.name, "doc/CustomRules.md", "Incorrect file name");
|
||||
}
|
||||
}
|
||||
],
|
||||
"files": "doc/CustomRules.md"
|
||||
};
|
||||
markdownlint(options, function callback(err) {
|
||||
test.ifError(err);
|
||||
test.end();
|
||||
t.falsy(err);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
tape("customRulesStringName", (test) => {
|
||||
test.plan(2);
|
||||
test("customRulesStringName", (t) => {
|
||||
t.plan(2);
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -1069,7 +1061,7 @@ tape("customRulesStringName", (test) => {
|
|||
"description": "description",
|
||||
"tags": [ "tag" ],
|
||||
"function": function stringName(params) {
|
||||
test.equal(params.name, "string", "Incorrect string name");
|
||||
t.is(params.name, "string", "Incorrect string name");
|
||||
}
|
||||
}
|
||||
],
|
||||
|
|
@ -1078,34 +1070,33 @@ tape("customRulesStringName", (test) => {
|
|||
}
|
||||
};
|
||||
markdownlint(options, function callback(err) {
|
||||
test.ifError(err);
|
||||
test.end();
|
||||
t.falsy(err);
|
||||
});
|
||||
});
|
||||
|
||||
tape("customRulesDoc", (test) => {
|
||||
test.plan(2);
|
||||
test.cb("customRulesDoc", (t) => {
|
||||
t.plan(2);
|
||||
markdownlint({
|
||||
"files": "doc/CustomRules.md",
|
||||
"files": "./doc/CustomRules.md",
|
||||
"config": {
|
||||
"MD013": { "line_length": 200 }
|
||||
}
|
||||
}, function callback(err, actual) {
|
||||
test.ifError(err);
|
||||
const expected = { "doc/CustomRules.md": [] };
|
||||
test.deepEqual(actual, expected, "Unexpected issues.");
|
||||
test.end();
|
||||
t.falsy(err);
|
||||
const expected = { "./doc/CustomRules.md": [] };
|
||||
t.deepEqual(actual, expected, "Unexpected issues.");
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
tape("customRulesLintJavaScript", (test) => {
|
||||
test.plan(2);
|
||||
test.cb("customRulesLintJavaScript", (t) => {
|
||||
t.plan(2);
|
||||
const options = {
|
||||
"customRules": customRules.lintJavaScript,
|
||||
"files": "test/lint-javascript.md"
|
||||
};
|
||||
markdownlint(options, (err, actual) => {
|
||||
test.ifError(err);
|
||||
t.falsy(err);
|
||||
const expected = {
|
||||
"test/lint-javascript.md": [
|
||||
{
|
||||
|
|
@ -1128,7 +1119,7 @@ tape("customRulesLintJavaScript", (test) => {
|
|||
}
|
||||
]
|
||||
};
|
||||
test.deepEqual(actual, expected, "Unexpected issues.");
|
||||
test.end();
|
||||
t.deepEqual(actual, expected, "Unexpected issues.");
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -5,40 +5,37 @@
|
|||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const globby = require("globby");
|
||||
const tape = require("tape");
|
||||
require("tape-player");
|
||||
const test = require("ava").default;
|
||||
const markdownlint = require("../lib/markdownlint");
|
||||
const { utf8Encoding } = require("../helpers");
|
||||
|
||||
// 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);
|
||||
let content = fs.readFileSync(path.join("./test", file), "utf8");
|
||||
while (content) {
|
||||
strings[content.length.toString()] = content;
|
||||
content = content.slice(0, -1);
|
||||
}
|
||||
tape(`type ${file}`, (test) => {
|
||||
test.plan(1);
|
||||
test(`type ${file}`, (t) => {
|
||||
t.plan(1);
|
||||
markdownlint.sync({
|
||||
// @ts-ignore
|
||||
strings,
|
||||
"resultVersion": 0
|
||||
});
|
||||
test.pass();
|
||||
test.end();
|
||||
t.pass();
|
||||
});
|
||||
});
|
||||
|
||||
// Parses all Markdown files in all package dependencies
|
||||
tape("parseAllFiles", (test) => {
|
||||
test.plan(1);
|
||||
test.cb("parseAllFiles", (t) => {
|
||||
t.plan(1);
|
||||
const options = {
|
||||
"files": globby.sync("**/*.{md,markdown}")
|
||||
};
|
||||
markdownlint(options, (err) => {
|
||||
test.ifError(err);
|
||||
test.end();
|
||||
t.falsy(err);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,12 +3,11 @@
|
|||
"use strict";
|
||||
|
||||
const os = require("os");
|
||||
const tape = require("tape");
|
||||
require("tape-player");
|
||||
const test = require("ava").default;
|
||||
const helpers = require("../helpers");
|
||||
|
||||
tape("clearHtmlCommentTextValid", (test) => {
|
||||
test.plan(1);
|
||||
test("clearHtmlCommentTextValid", (t) => {
|
||||
t.plan(1);
|
||||
const validComments = [
|
||||
"<!-- text -->",
|
||||
"<!--text-->",
|
||||
|
|
@ -85,12 +84,11 @@ tape("clearHtmlCommentTextValid", (test) => {
|
|||
];
|
||||
const actual = helpers.clearHtmlCommentText(validComments.join("\n"));
|
||||
const expected = validResult.join("\n");
|
||||
test.equal(actual, expected);
|
||||
test.end();
|
||||
t.is(actual, expected);
|
||||
});
|
||||
|
||||
tape("clearHtmlCommentTextInvalid", (test) => {
|
||||
test.plan(1);
|
||||
test("clearHtmlCommentTextInvalid", (t) => {
|
||||
t.plan(1);
|
||||
const invalidComments = [
|
||||
"<!>",
|
||||
"<!->",
|
||||
|
|
@ -111,12 +109,11 @@ tape("clearHtmlCommentTextInvalid", (test) => {
|
|||
];
|
||||
const actual = helpers.clearHtmlCommentText(invalidComments.join("\n"));
|
||||
const expected = invalidComments.join("\n");
|
||||
test.equal(actual, expected);
|
||||
test.end();
|
||||
t.is(actual, expected);
|
||||
});
|
||||
|
||||
tape("clearHtmlCommentTextNonGreedy", (test) => {
|
||||
test.plan(1);
|
||||
test("clearHtmlCommentTextNonGreedy", (t) => {
|
||||
t.plan(1);
|
||||
const nonGreedyComments = [
|
||||
"<!-- text --> -->",
|
||||
"<!---text --> -->",
|
||||
|
|
@ -131,12 +128,11 @@ tape("clearHtmlCommentTextNonGreedy", (test) => {
|
|||
];
|
||||
const actual = helpers.clearHtmlCommentText(nonGreedyComments.join("\n"));
|
||||
const expected = nonGreedyResult.join("\n");
|
||||
test.equal(actual, expected);
|
||||
test.end();
|
||||
t.is(actual, expected);
|
||||
});
|
||||
|
||||
tape("clearHtmlCommentTextEmbedded", (test) => {
|
||||
test.plan(1);
|
||||
test("clearHtmlCommentTextEmbedded", (t) => {
|
||||
t.plan(1);
|
||||
const embeddedComments = [
|
||||
"text<!--text-->text",
|
||||
"<!-- markdownlint-disable MD010 -->",
|
||||
|
|
@ -153,12 +149,11 @@ tape("clearHtmlCommentTextEmbedded", (test) => {
|
|||
];
|
||||
const actual = helpers.clearHtmlCommentText(embeddedComments.join("\n"));
|
||||
const expected = embeddedResult.join("\n");
|
||||
test.equal(actual, expected);
|
||||
test.end();
|
||||
t.is(actual, expected);
|
||||
});
|
||||
|
||||
tape("unescapeMarkdown", (test) => {
|
||||
test.plan(7);
|
||||
test("unescapeMarkdown", (t) => {
|
||||
t.plan(7);
|
||||
// Test cases from https://spec.commonmark.org/0.29/#backslash-escapes
|
||||
const testCases = [
|
||||
[
|
||||
|
|
@ -214,13 +209,12 @@ bar`
|
|||
testCases.forEach(function forTestCase(testCase) {
|
||||
const [ markdown, expected, replacement ] = testCase;
|
||||
const actual = helpers.unescapeMarkdown(markdown, replacement);
|
||||
test.equal(actual, expected);
|
||||
t.is(actual, expected);
|
||||
});
|
||||
test.end();
|
||||
});
|
||||
|
||||
tape("isBlankLine", (test) => {
|
||||
test.plan(25);
|
||||
test("isBlankLine", (t) => {
|
||||
t.plan(25);
|
||||
const blankLines = [
|
||||
null,
|
||||
"",
|
||||
|
|
@ -240,7 +234,7 @@ tape("isBlankLine", (test) => {
|
|||
"> <!--text-->",
|
||||
">><!--text-->"
|
||||
];
|
||||
blankLines.forEach((line) => test.ok(helpers.isBlankLine(line), line));
|
||||
blankLines.forEach((line) => t.true(helpers.isBlankLine(line), line || ""));
|
||||
const nonBlankLines = [
|
||||
"text",
|
||||
" text ",
|
||||
|
|
@ -251,12 +245,11 @@ tape("isBlankLine", (test) => {
|
|||
"<!--",
|
||||
"-->"
|
||||
];
|
||||
nonBlankLines.forEach((line) => test.ok(!helpers.isBlankLine(line), line));
|
||||
test.end();
|
||||
nonBlankLines.forEach((line) => t.true(!helpers.isBlankLine(line), line));
|
||||
});
|
||||
|
||||
tape("includesSorted", (test) => {
|
||||
test.plan(154);
|
||||
test("includesSorted", (t) => {
|
||||
t.plan(154);
|
||||
const inputs = [
|
||||
[ ],
|
||||
[ 8 ],
|
||||
|
|
@ -268,14 +261,13 @@ tape("includesSorted", (test) => {
|
|||
];
|
||||
inputs.forEach((input) => {
|
||||
for (let i = 0; i <= 21; i++) {
|
||||
test.equal(helpers.includesSorted(input, i), input.includes(i));
|
||||
t.is(helpers.includesSorted(input, i), input.includes(i));
|
||||
}
|
||||
});
|
||||
test.end();
|
||||
});
|
||||
|
||||
tape("forEachInlineCodeSpan", (test) => {
|
||||
test.plan(99);
|
||||
test("forEachInlineCodeSpan", (t) => {
|
||||
t.plan(99);
|
||||
const testCases =
|
||||
[
|
||||
{
|
||||
|
|
@ -369,18 +361,17 @@ tape("forEachInlineCodeSpan", (test) => {
|
|||
helpers.forEachInlineCodeSpan(input, (code, line, column, ticks) => {
|
||||
const [ expectedCode, expectedLine, expectedColumn, expectedTicks ] =
|
||||
expecteds.shift();
|
||||
test.equal(code, expectedCode, input);
|
||||
test.equal(line, expectedLine, input);
|
||||
test.equal(column, expectedColumn, input);
|
||||
test.equal(ticks, expectedTicks, input);
|
||||
t.is(code, expectedCode, input);
|
||||
t.is(line, expectedLine, input);
|
||||
t.is(column, expectedColumn, input);
|
||||
t.is(ticks, expectedTicks, input);
|
||||
});
|
||||
test.equal(expecteds.length, 0, "length");
|
||||
t.is(expecteds.length, 0, "length");
|
||||
});
|
||||
test.end();
|
||||
});
|
||||
|
||||
tape("getPreferredLineEnding", (test) => {
|
||||
test.plan(17);
|
||||
test("getPreferredLineEnding", (t) => {
|
||||
t.plan(17);
|
||||
const testCases = [
|
||||
[ "", os.EOL ],
|
||||
[ "\r", "\r" ],
|
||||
|
|
@ -403,13 +394,12 @@ tape("getPreferredLineEnding", (test) => {
|
|||
testCases.forEach((testCase) => {
|
||||
const [ input, expected ] = testCase;
|
||||
const actual = helpers.getPreferredLineEnding(input);
|
||||
test.equal(actual, expected, "Incorrect line ending returned.");
|
||||
t.is(actual, expected, "Incorrect line ending returned.");
|
||||
});
|
||||
test.end();
|
||||
});
|
||||
|
||||
tape("applyFix", (test) => {
|
||||
test.plan(4);
|
||||
test("applyFix", (t) => {
|
||||
t.plan(4);
|
||||
const testCases = [
|
||||
[
|
||||
"Hello world.",
|
||||
|
|
@ -452,13 +442,12 @@ tape("applyFix", (test) => {
|
|||
const [ line, fixInfo, lineEnding, expected ] = testCase;
|
||||
// @ts-ignore
|
||||
const actual = helpers.applyFix(line, fixInfo, lineEnding);
|
||||
test.equal(actual, expected, "Incorrect fix applied.");
|
||||
t.is(actual, expected, "Incorrect fix applied.");
|
||||
});
|
||||
test.end();
|
||||
});
|
||||
|
||||
tape("applyFixes", (test) => {
|
||||
test.plan(29);
|
||||
test("applyFixes", (t) => {
|
||||
t.plan(29);
|
||||
const testCases = [
|
||||
[
|
||||
"Hello world.",
|
||||
|
|
@ -909,7 +898,6 @@ tape("applyFixes", (test) => {
|
|||
testCases.forEach((testCase) => {
|
||||
const [ input, errors, expected ] = testCase;
|
||||
const actual = helpers.applyFixes(input, errors);
|
||||
test.equal(actual, expected, "Incorrect fix applied.");
|
||||
t.is(actual, expected, "Incorrect fix applied.");
|
||||
});
|
||||
test.end();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -9,8 +9,7 @@ const { promisify } = require("util");
|
|||
const globby = require("globby");
|
||||
const jsYaml = require("js-yaml");
|
||||
const stripJsonComments = require("strip-json-comments");
|
||||
const tape = require("tape");
|
||||
require("tape-player");
|
||||
const test = require("ava").default;
|
||||
const markdownlint = require("../lib/markdownlint");
|
||||
const markdownlintPromise = promisify(markdownlint);
|
||||
const readConfigPromise = promisify(markdownlint.readConfig);
|
||||
|
|
@ -38,13 +37,14 @@ function yamlParse(yaml) {
|
|||
/**
|
||||
* Lints a test repository.
|
||||
*
|
||||
* @param {Object} test Test instance.
|
||||
* @param {Object} t Test instance.
|
||||
* @param {string[]} globPatterns Array of files to in/exclude.
|
||||
* @param {string} configPath Path to config file.
|
||||
* @returns {Promise} Test result.
|
||||
*/
|
||||
function lintTestRepo(test, globPatterns, configPath) {
|
||||
test.plan(1);
|
||||
Promise.all([
|
||||
function lintTestRepo(t, globPatterns, configPath) {
|
||||
t.plan(1);
|
||||
return Promise.all([
|
||||
globby(globPatterns),
|
||||
// @ts-ignore
|
||||
readConfigPromise(configPath, [ jsoncParse, yamlParse ])
|
||||
|
|
@ -60,22 +60,21 @@ function lintTestRepo(test, globPatterns, configPath) {
|
|||
// eslint-disable-next-line no-console
|
||||
console.log(resultsString);
|
||||
}
|
||||
test.ok(!resultsString.length, "Unexpected linting violations");
|
||||
test.end();
|
||||
t.true(!resultsString.length, "Unexpected linting violations");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Run markdownlint the same way the corresponding repositories do
|
||||
|
||||
tape("https://github.com/eslint/eslint", (test) => {
|
||||
test("https://github.com/eslint/eslint", (t) => {
|
||||
const rootDir = "./test-repos/eslint-eslint";
|
||||
const globPatterns = [ join(rootDir, "docs/**/*.md") ];
|
||||
const configPath = join(rootDir, ".markdownlint.yml");
|
||||
lintTestRepo(test, globPatterns, configPath);
|
||||
return lintTestRepo(t, globPatterns, configPath);
|
||||
});
|
||||
|
||||
tape("https://github.com/mkdocs/mkdocs", (test) => {
|
||||
test("https://github.com/mkdocs/mkdocs", (t) => {
|
||||
const rootDir = "./test-repos/mkdocs-mkdocs";
|
||||
const globPatterns = [
|
||||
join(rootDir, "README.md"),
|
||||
|
|
@ -84,21 +83,21 @@ tape("https://github.com/mkdocs/mkdocs", (test) => {
|
|||
"!" + join(rootDir, "docs/CNAME")
|
||||
];
|
||||
const configPath = join(rootDir, ".markdownlintrc");
|
||||
lintTestRepo(test, globPatterns, configPath);
|
||||
return lintTestRepo(t, globPatterns, configPath);
|
||||
});
|
||||
|
||||
tape("https://github.com/pi-hole/docs", (test) => {
|
||||
test("https://github.com/pi-hole/docs", (t) => {
|
||||
const rootDir = "./test-repos/pi-hole-docs";
|
||||
const globPatterns = [ join(rootDir, "**/*.md") ];
|
||||
const configPath = join(rootDir, ".markdownlint.json");
|
||||
lintTestRepo(test, globPatterns, configPath);
|
||||
return lintTestRepo(t, globPatterns, configPath);
|
||||
});
|
||||
|
||||
// Optional repositories (very large)
|
||||
|
||||
const dotnetDocsDir = "./test-repos/dotnet-docs";
|
||||
if (existsSync(dotnetDocsDir)) {
|
||||
tape("https://github.com/dotnet/docs", (test) => {
|
||||
test("https://github.com/dotnet/docs", (t) => {
|
||||
const rootDir = dotnetDocsDir;
|
||||
const globPatterns = [
|
||||
join(rootDir, "**/*.md"),
|
||||
|
|
@ -111,6 +110,6 @@ if (existsSync(dotnetDocsDir)) {
|
|||
)
|
||||
];
|
||||
const configPath = join(rootDir, ".markdownlint.json");
|
||||
lintTestRepo(test, globPatterns, configPath);
|
||||
return lintTestRepo(t, globPatterns, configPath);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,32 +2,31 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const tape = require("tape");
|
||||
require("tape-player");
|
||||
const test = require("ava").default;
|
||||
const packageJson = require("../package.json");
|
||||
const markdownlint = require("../lib/markdownlint");
|
||||
const homepage = packageJson.homepage;
|
||||
const version = packageJson.version;
|
||||
|
||||
tape("resultObjectToStringNotEnumerable", (test) => {
|
||||
test.plan(2);
|
||||
test.cb("resultObjectToStringNotEnumerable", (t) => {
|
||||
t.plan(2);
|
||||
const options = {
|
||||
"strings": {
|
||||
"string": "# Heading"
|
||||
}
|
||||
};
|
||||
markdownlint(options, function callback(err, result) {
|
||||
test.ifError(err);
|
||||
t.falsy(err);
|
||||
// eslint-disable-next-line guard-for-in
|
||||
for (const property in result) {
|
||||
test.notEqual(property, "toString", "Function should not enumerate.");
|
||||
t.not(property, "toString", "Function should not enumerate.");
|
||||
}
|
||||
test.end();
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
tape("resultFormattingV0", (test) => {
|
||||
test.plan(4);
|
||||
test.cb("resultFormattingV0", (t) => {
|
||||
t.plan(4);
|
||||
const options = {
|
||||
"files": [
|
||||
"./test/atx_heading_spacing.md",
|
||||
|
|
@ -40,7 +39,7 @@ tape("resultFormattingV0", (test) => {
|
|||
"resultVersion": 0
|
||||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
t.falsy(err);
|
||||
const expectedResult = {
|
||||
"./test/atx_heading_spacing.md": {
|
||||
"MD002": [ 3 ],
|
||||
|
|
@ -51,7 +50,8 @@ tape("resultFormattingV0", (test) => {
|
|||
"MD002": [ 1 ]
|
||||
}
|
||||
};
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
// @ts-ignore
|
||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
let actualMessage = actualResult.toString();
|
||||
let expectedMessage =
|
||||
"./test/atx_heading_spacing.md: 3: MD002" +
|
||||
|
|
@ -64,7 +64,7 @@ tape("resultFormattingV0", (test) => {
|
|||
" Multiple spaces after hash on atx style heading\n" +
|
||||
"./test/first_heading_bad_atx.md: 1: MD002" +
|
||||
" First heading should be a top-level heading";
|
||||
test.equal(actualMessage, expectedMessage, "Incorrect message (name).");
|
||||
t.is(actualMessage, expectedMessage, "Incorrect message (name).");
|
||||
// @ts-ignore
|
||||
actualMessage = actualResult.toString(true);
|
||||
expectedMessage =
|
||||
|
|
@ -78,13 +78,13 @@ tape("resultFormattingV0", (test) => {
|
|||
" Multiple spaces after hash on atx style heading\n" +
|
||||
"./test/first_heading_bad_atx.md: 1: first-heading-h1" +
|
||||
" First heading should be a top-level heading";
|
||||
test.equal(actualMessage, expectedMessage, "Incorrect message (alias).");
|
||||
test.end();
|
||||
t.is(actualMessage, expectedMessage, "Incorrect message (alias).");
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
tape("resultFormattingSyncV0", (test) => {
|
||||
test.plan(3);
|
||||
test("resultFormattingSyncV0", (t) => {
|
||||
t.plan(3);
|
||||
const options = {
|
||||
"files": [
|
||||
"./test/atx_heading_spacing.md",
|
||||
|
|
@ -107,7 +107,8 @@ tape("resultFormattingSyncV0", (test) => {
|
|||
"MD002": [ 1 ]
|
||||
}
|
||||
};
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
// @ts-ignore
|
||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
let actualMessage = actualResult.toString();
|
||||
let expectedMessage =
|
||||
"./test/atx_heading_spacing.md: 3: MD002" +
|
||||
|
|
@ -120,7 +121,7 @@ tape("resultFormattingSyncV0", (test) => {
|
|||
" Multiple spaces after hash on atx style heading\n" +
|
||||
"./test/first_heading_bad_atx.md: 1: MD002" +
|
||||
" First heading should be a top-level heading";
|
||||
test.equal(actualMessage, expectedMessage, "Incorrect message (name).");
|
||||
t.is(actualMessage, expectedMessage, "Incorrect message (name).");
|
||||
// @ts-ignore
|
||||
actualMessage = actualResult.toString(true);
|
||||
expectedMessage =
|
||||
|
|
@ -134,12 +135,11 @@ tape("resultFormattingSyncV0", (test) => {
|
|||
" Multiple spaces after hash on atx style heading\n" +
|
||||
"./test/first_heading_bad_atx.md: 1: first-heading-h1" +
|
||||
" First heading should be a top-level heading";
|
||||
test.equal(actualMessage, expectedMessage, "Incorrect message (alias).");
|
||||
test.end();
|
||||
t.is(actualMessage, expectedMessage, "Incorrect message (alias).");
|
||||
});
|
||||
|
||||
tape("resultFormattingV1", (test) => {
|
||||
test.plan(3);
|
||||
test.cb("resultFormattingV1", (t) => {
|
||||
t.plan(3);
|
||||
const options = {
|
||||
"strings": {
|
||||
"truncate":
|
||||
|
|
@ -156,7 +156,7 @@ tape("resultFormattingV1", (test) => {
|
|||
"resultVersion": 1
|
||||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
t.falsy(err);
|
||||
const expectedResult = {
|
||||
"truncate": [
|
||||
{ "lineNumber": 1,
|
||||
|
|
@ -214,7 +214,8 @@ tape("resultFormattingV1", (test) => {
|
|||
"errorRange": null }
|
||||
]
|
||||
};
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
// @ts-ignore
|
||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
const actualMessage = actualResult.toString();
|
||||
const expectedMessage =
|
||||
"./test/atx_heading_spacing.md: 3: MD002/first-heading-h1" +
|
||||
|
|
@ -235,13 +236,13 @@ tape("resultFormattingV1", (test) => {
|
|||
"truncate: 1: MD021/no-multiple-space-closed-atx" +
|
||||
" Multiple spaces inside hashes on closed atx style heading" +
|
||||
" [Context: \"# Multiple spa...tyle heading #\"]";
|
||||
test.equal(actualMessage, expectedMessage, "Incorrect message.");
|
||||
test.end();
|
||||
t.is(actualMessage, expectedMessage, "Incorrect message.");
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
tape("resultFormattingV2", (test) => {
|
||||
test.plan(3);
|
||||
test.cb("resultFormattingV2", (t) => {
|
||||
t.plan(3);
|
||||
const options = {
|
||||
"strings": {
|
||||
"truncate":
|
||||
|
|
@ -257,7 +258,7 @@ tape("resultFormattingV2", (test) => {
|
|||
}
|
||||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
t.falsy(err);
|
||||
const expectedResult = {
|
||||
"truncate": [
|
||||
{ "lineNumber": 1,
|
||||
|
|
@ -309,7 +310,7 @@ tape("resultFormattingV2", (test) => {
|
|||
"errorRange": null }
|
||||
]
|
||||
};
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
const actualMessage = actualResult.toString();
|
||||
const expectedMessage =
|
||||
"./test/atx_heading_spacing.md: 3:" +
|
||||
|
|
@ -332,13 +333,13 @@ tape("resultFormattingV2", (test) => {
|
|||
"truncate: 1: MD021/no-multiple-space-closed-atx" +
|
||||
" Multiple spaces inside hashes on closed atx style heading" +
|
||||
" [Context: \"# Multiple spa...tyle heading #\"]";
|
||||
test.equal(actualMessage, expectedMessage, "Incorrect message.");
|
||||
test.end();
|
||||
t.is(actualMessage, expectedMessage, "Incorrect message.");
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
tape("resultFormattingV3", (test) => {
|
||||
test.plan(3);
|
||||
test.cb("resultFormattingV3", (t) => {
|
||||
t.plan(3);
|
||||
const options = {
|
||||
"strings": {
|
||||
"input":
|
||||
|
|
@ -350,7 +351,7 @@ tape("resultFormattingV3", (test) => {
|
|||
"resultVersion": 3
|
||||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
t.falsy(err);
|
||||
const expectedResult = {
|
||||
"input": [
|
||||
{
|
||||
|
|
@ -423,7 +424,7 @@ tape("resultFormattingV3", (test) => {
|
|||
}
|
||||
]
|
||||
};
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
const actualMessage = actualResult.toString();
|
||||
const expectedMessage =
|
||||
"input: 1: MD009/no-trailing-spaces" +
|
||||
|
|
@ -436,13 +437,13 @@ tape("resultFormattingV3", (test) => {
|
|||
" Spaces inside emphasis markers [Context: \"* emphasis *\"]\n" +
|
||||
"input: 4: MD047/single-trailing-newline" +
|
||||
" Files should end with a single newline character";
|
||||
test.equal(actualMessage, expectedMessage, "Incorrect message.");
|
||||
test.end();
|
||||
t.is(actualMessage, expectedMessage, "Incorrect message.");
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
tape("onePerLineResultVersion0", (test) => {
|
||||
test.plan(2);
|
||||
test.cb("onePerLineResultVersion0", (t) => {
|
||||
t.plan(2);
|
||||
const options = {
|
||||
"strings": {
|
||||
"input": "# Heading\theading\t\theading\n"
|
||||
|
|
@ -450,19 +451,20 @@ tape("onePerLineResultVersion0", (test) => {
|
|||
"resultVersion": 0
|
||||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
t.falsy(err);
|
||||
const expectedResult = {
|
||||
"input": {
|
||||
"MD010": [ 1 ]
|
||||
}
|
||||
};
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
test.end();
|
||||
// @ts-ignore
|
||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
tape("onePerLineResultVersion1", (test) => {
|
||||
test.plan(2);
|
||||
test.cb("onePerLineResultVersion1", (t) => {
|
||||
t.plan(2);
|
||||
const options = {
|
||||
"strings": {
|
||||
"input": "# Heading\theading\t\theading\n"
|
||||
|
|
@ -470,7 +472,7 @@ tape("onePerLineResultVersion1", (test) => {
|
|||
"resultVersion": 1
|
||||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
t.falsy(err);
|
||||
const expectedResult = {
|
||||
"input": [
|
||||
{
|
||||
|
|
@ -486,13 +488,14 @@ tape("onePerLineResultVersion1", (test) => {
|
|||
}
|
||||
]
|
||||
};
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
test.end();
|
||||
// @ts-ignore
|
||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
tape("onePerLineResultVersion2", (test) => {
|
||||
test.plan(2);
|
||||
test.cb("onePerLineResultVersion2", (t) => {
|
||||
t.plan(2);
|
||||
const options = {
|
||||
"strings": {
|
||||
"input": "# Heading\theading\t\theading\n"
|
||||
|
|
@ -500,7 +503,7 @@ tape("onePerLineResultVersion2", (test) => {
|
|||
"resultVersion": 2
|
||||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
t.falsy(err);
|
||||
const expectedResult = {
|
||||
"input": [
|
||||
{
|
||||
|
|
@ -515,13 +518,13 @@ tape("onePerLineResultVersion2", (test) => {
|
|||
}
|
||||
]
|
||||
};
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
test.end();
|
||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
tape("manyPerLineResultVersion3", (test) => {
|
||||
test.plan(2);
|
||||
test.cb("manyPerLineResultVersion3", (t) => {
|
||||
t.plan(2);
|
||||
const options = {
|
||||
"strings": {
|
||||
"input": "# Heading\theading\t\theading\n"
|
||||
|
|
@ -529,7 +532,7 @@ tape("manyPerLineResultVersion3", (test) => {
|
|||
"resultVersion": 3
|
||||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
t.falsy(err);
|
||||
const expectedResult = {
|
||||
"input": [
|
||||
{
|
||||
|
|
@ -564,13 +567,13 @@ tape("manyPerLineResultVersion3", (test) => {
|
|||
}
|
||||
]
|
||||
};
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
test.end();
|
||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
tape("frontMatterResultVersion3", (test) => {
|
||||
test.plan(2);
|
||||
test.cb("frontMatterResultVersion3", (t) => {
|
||||
t.plan(2);
|
||||
const options = {
|
||||
"strings": {
|
||||
"input": "---\n---\n# Heading\nText\n"
|
||||
|
|
@ -578,7 +581,7 @@ tape("frontMatterResultVersion3", (test) => {
|
|||
"resultVersion": 3
|
||||
};
|
||||
markdownlint(options, function callback(err, actualResult) {
|
||||
test.ifError(err);
|
||||
t.falsy(err);
|
||||
const expectedResult = {
|
||||
"input": [
|
||||
{
|
||||
|
|
@ -598,7 +601,7 @@ tape("frontMatterResultVersion3", (test) => {
|
|||
}
|
||||
]
|
||||
};
|
||||
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
test.end();
|
||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -5,8 +5,7 @@
|
|||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { promisify } = require("util");
|
||||
const tape = require("tape");
|
||||
require("tape-player");
|
||||
const test = require("ava").default;
|
||||
const { version } = require("../package.json");
|
||||
const markdownlint = require("../lib/markdownlint");
|
||||
const helpers = require("../helpers");
|
||||
|
|
@ -19,9 +18,9 @@ const helpers = require("../helpers");
|
|||
*/
|
||||
function createTestForFile(file) {
|
||||
const markdownlintPromise = promisify(markdownlint);
|
||||
return function testForFile(test) {
|
||||
return function testForFile(t) {
|
||||
const detailedResults = /[/\\]detailed-results-/.test(file);
|
||||
test.plan(detailedResults ? 3 : 2);
|
||||
t.plan(detailedResults ? 3 : 2);
|
||||
const resultsFile = file.replace(/\.md$/, ".results.json");
|
||||
const fixedFile = file.replace(/\.md$/, ".md.fixed");
|
||||
const configFile = file.replace(/\.md$/, ".json");
|
||||
|
|
@ -66,8 +65,7 @@ function createTestForFile(file) {
|
|||
const actual = helpers.applyFixes(content, errors);
|
||||
// Uncomment the following line to update *.md.fixed files
|
||||
// fs.writeFileSync(fixedFile, actual, "utf8");
|
||||
test.equal(actual, expected,
|
||||
"Unexpected output from applyFixes.");
|
||||
t.is(actual, expected, "Unexpected output from applyFixes.");
|
||||
return resultVersion2or3;
|
||||
}) :
|
||||
resultVersion2or3;
|
||||
|
|
@ -128,18 +126,18 @@ function createTestForFile(file) {
|
|||
});
|
||||
return sortedResults;
|
||||
});
|
||||
Promise.all([ actualPromise, expectedPromise ])
|
||||
return Promise.all([ actualPromise, expectedPromise ])
|
||||
.then(
|
||||
function compareResults(fulfillments) {
|
||||
const [ [ actual0, actual2or3 ], expected ] = fulfillments;
|
||||
const actual = detailedResults ? actual2or3 : actual0;
|
||||
test.deepEqual(actual, expected, "Line numbers are not correct.");
|
||||
t.deepEqual(actual, expected, "Line numbers are not correct.");
|
||||
return actual2or3;
|
||||
})
|
||||
.then(
|
||||
function verifyFixes(errors) {
|
||||
if (detailedResults) {
|
||||
return test.ok(true);
|
||||
return t.true(true);
|
||||
}
|
||||
return fs.promises.readFile(file, "utf8")
|
||||
.then(
|
||||
|
|
@ -157,16 +155,16 @@ function createTestForFile(file) {
|
|||
function checkFixes(newErrors) {
|
||||
const unfixed = newErrors.input
|
||||
.filter((error) => !!error.fixInfo);
|
||||
test.deepEqual(unfixed, [], "Fixable error was not fixed.");
|
||||
t.deepEqual(unfixed, [], "Fixable error was not fixed.");
|
||||
}
|
||||
);
|
||||
})
|
||||
.catch()
|
||||
.then(test.done);
|
||||
.then(t.done);
|
||||
};
|
||||
}
|
||||
|
||||
fs.readdirSync("./test")
|
||||
.filter((file) => /\.md$/.test(file))
|
||||
// @ts-ignore
|
||||
.forEach((file) => tape(file, createTestForFile(path.join("./test", file))));
|
||||
.forEach((file) => test(file, createTestForFile(path.join("./test", file))));
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue