From 49945d66017f66916b17b3bb7aadb904f2e8b7f8 Mon Sep 17 00:00:00 2001 From: David Anson Date: Sun, 10 Jan 2021 20:46:00 -0800 Subject: [PATCH] Convert from tape test harness to ava, address minor declaration file issue. --- demo/markdownlint-browser.js | 2 +- example/typescript/type-check.ts | 3 + lib/markdownlint.d.ts | 2 +- lib/markdownlint.js | 2 +- package.json | 9 +- test/markdownlint-test-custom-rules.js | 287 +++++---- test/markdownlint-test-extra.js | 21 +- test/markdownlint-test-helpers.js | 90 ++- test/markdownlint-test-repos.js | 31 +- test/markdownlint-test-result-object.js | 129 ++-- test/markdownlint-test-scenarios.js | 22 +- test/markdownlint-test.js | 746 ++++++++++++------------ 12 files changed, 665 insertions(+), 679 deletions(-) diff --git a/demo/markdownlint-browser.js b/demo/markdownlint-browser.js index 6cc24069..9ceb0bce 100644 --- a/demo/markdownlint-browser.js +++ b/demo/markdownlint-browser.js @@ -3945,7 +3945,7 @@ module.exports = rules; /***/ ((module) => { "use strict"; -module.exports = JSON.parse("{\"name\":\"markdownlint\",\"version\":\"0.22.0\",\"description\":\"A Node.js style checker and lint tool for Markdown/CommonMark files.\",\"main\":\"lib/markdownlint.js\",\"types\":\"lib/markdownlint.d.ts\",\"author\":\"David Anson (https://dlaa.me/)\",\"license\":\"MIT\",\"homepage\":\"https://github.com/DavidAnson/markdownlint\",\"repository\":{\"type\":\"git\",\"url\":\"https://github.com/DavidAnson/markdownlint.git\"},\"bugs\":\"https://github.com/DavidAnson/markdownlint/issues\",\"scripts\":{\"build-config-schema\":\"node schema/build-config-schema.js\",\"build-declaration\":\"tsc --allowJs --declaration --emitDeclarationOnly --resolveJsonModule lib/markdownlint.js && rimraf 'lib/{c,md,r}*.d.ts' 'helpers/*.d.ts'\",\"build-demo\":\"cpy node_modules/markdown-it/dist/markdown-it.min.js demo && cd demo && rimraf markdownlint-browser.* && webpack --no-stats\",\"build-example\":\"npm install --no-save --ignore-scripts grunt grunt-cli gulp through2\",\"ci\":\"npm-run-all --continue-on-error --parallel test-cover lint declaration build-config-schema build-demo && git diff --exit-code\",\"clean-test-repos\":\"rimraf test-repos\",\"clone-test-repos\":\"mkdir test-repos && cd test-repos && git clone https://github.com/eslint/eslint eslint-eslint --depth 1 --no-tags --quiet && git clone https://github.com/mkdocs/mkdocs mkdocs-mkdocs --depth 1 --no-tags --quiet && git clone https://github.com/pi-hole/docs pi-hole-docs --depth 1 --no-tags --quiet\",\"clone-test-repos-large\":\"npm run clone-test-repos && cd test-repos && git clone https://github.com/dotnet/docs dotnet-docs --depth 1 --no-tags --quiet\",\"declaration\":\"npm run build-declaration && npm run test-declaration\",\"example\":\"cd example && node standalone.js && grunt markdownlint --force && gulp markdownlint\",\"lint\":\"eslint --max-warnings 0 .\",\"lint-test-repos\":\"node test/markdownlint-test-repos.js\",\"test\":\"tape test/markdownlint-test.js test/markdownlint-test-custom-rules.js test/markdownlint-test-helpers.js test/markdownlint-test-result-object.js test/markdownlint-test-scenarios.js\",\"test-cover\":\"c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 npm test\",\"test-declaration\":\"cd example/typescript && tsc && node type-check.js\",\"test-extra\":\"node test/markdownlint-test-extra.js\"},\"engines\":{\"node\":\">=10\"},\"dependencies\":{\"markdown-it\":\"12.0.2\"},\"devDependencies\":{\"@types/node\":\"~14.14.9\",\"c8\":\"~7.3.5\",\"cpy-cli\":\"~3.1.1\",\"eslint\":\"~7.14.0\",\"eslint-plugin-jsdoc\":\"~30.7.8\",\"eslint-plugin-node\":\"~11.1.0\",\"eslint-plugin-unicorn\":\"~23.0.0\",\"globby\":\"~11.0.1\",\"js-yaml\":\"~3.14.0\",\"markdown-it-for-inline\":\"~0.1.1\",\"markdown-it-sub\":\"~1.0.0\",\"markdown-it-sup\":\"~1.0.0\",\"markdown-it-texmath\":\"~0.8.0\",\"markdownlint-rule-helpers\":\"~0.12.0\",\"npm-run-all\":\"~4.1.5\",\"rimraf\":\"~3.0.2\",\"strip-json-comments\":\"~3.1.1\",\"tape\":\"~5.0.1\",\"tape-player\":\"~0.1.1\",\"toml\":\"~3.0.0\",\"ts-loader\":\"~8.0.14\",\"tv4\":\"~1.3.0\",\"typescript\":\"~4.1.2\",\"webpack\":\"~5.11.1\",\"webpack-cli\":\"~4.3.1\"},\"keywords\":[\"markdown\",\"lint\",\"md\",\"CommonMark\",\"markdownlint\"]}"); +module.exports = JSON.parse("{\"name\":\"markdownlint\",\"version\":\"0.22.0\",\"description\":\"A Node.js style checker and lint tool for Markdown/CommonMark files.\",\"main\":\"lib/markdownlint.js\",\"types\":\"lib/markdownlint.d.ts\",\"author\":\"David Anson (https://dlaa.me/)\",\"license\":\"MIT\",\"homepage\":\"https://github.com/DavidAnson/markdownlint\",\"repository\":{\"type\":\"git\",\"url\":\"https://github.com/DavidAnson/markdownlint.git\"},\"bugs\":\"https://github.com/DavidAnson/markdownlint/issues\",\"scripts\":{\"build-config-schema\":\"node schema/build-config-schema.js\",\"build-declaration\":\"tsc --allowJs --declaration --emitDeclarationOnly --resolveJsonModule lib/markdownlint.js && rimraf 'lib/{c,md,r}*.d.ts' 'helpers/*.d.ts'\",\"build-demo\":\"cpy node_modules/markdown-it/dist/markdown-it.min.js demo && cd demo && rimraf markdownlint-browser.* && webpack --no-stats\",\"build-example\":\"npm install --no-save --ignore-scripts grunt grunt-cli gulp through2\",\"ci\":\"npm-run-all --continue-on-error --parallel test-cover lint declaration build-config-schema build-demo && git diff --exit-code\",\"clean-test-repos\":\"rimraf test-repos\",\"clone-test-repos\":\"mkdir test-repos && cd test-repos && git clone https://github.com/eslint/eslint eslint-eslint --depth 1 --no-tags --quiet && git clone https://github.com/mkdocs/mkdocs mkdocs-mkdocs --depth 1 --no-tags --quiet && git clone https://github.com/pi-hole/docs pi-hole-docs --depth 1 --no-tags --quiet\",\"clone-test-repos-large\":\"npm run clone-test-repos && cd test-repos && git clone https://github.com/dotnet/docs dotnet-docs --depth 1 --no-tags --quiet\",\"declaration\":\"npm run build-declaration && npm run test-declaration\",\"example\":\"cd example && node standalone.js && grunt markdownlint --force && gulp markdownlint\",\"lint\":\"eslint --max-warnings 0 .\",\"lint-test-repos\":\"ava test/markdownlint-test-repos.js\",\"test\":\"ava test/markdownlint-test.js test/markdownlint-test-custom-rules.js test/markdownlint-test-helpers.js test/markdownlint-test-result-object.js test/markdownlint-test-scenarios.js\",\"test-cover\":\"c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 npm test\",\"test-declaration\":\"cd example/typescript && tsc && node type-check.js\",\"test-extra\":\"ava --timeout=3m test/markdownlint-test-extra.js\"},\"engines\":{\"node\":\">=10\"},\"dependencies\":{\"markdown-it\":\"12.0.2\"},\"devDependencies\":{\"@types/node\":\"~14.14.9\",\"ava\":\"~3.15.0\",\"c8\":\"~7.3.5\",\"cpy-cli\":\"~3.1.1\",\"eslint\":\"~7.14.0\",\"eslint-plugin-jsdoc\":\"~30.7.8\",\"eslint-plugin-node\":\"~11.1.0\",\"eslint-plugin-unicorn\":\"~23.0.0\",\"globby\":\"~11.0.1\",\"js-yaml\":\"~3.14.0\",\"markdown-it-for-inline\":\"~0.1.1\",\"markdown-it-sub\":\"~1.0.0\",\"markdown-it-sup\":\"~1.0.0\",\"markdown-it-texmath\":\"~0.8.0\",\"markdownlint-rule-helpers\":\"~0.12.0\",\"npm-run-all\":\"~4.1.5\",\"rimraf\":\"~3.0.2\",\"strip-json-comments\":\"~3.1.1\",\"toml\":\"~3.0.0\",\"ts-loader\":\"~8.0.14\",\"tv4\":\"~1.3.0\",\"typescript\":\"~4.1.2\",\"webpack\":\"~5.11.1\",\"webpack-cli\":\"~4.3.1\"},\"keywords\":[\"markdown\",\"lint\",\"md\",\"CommonMark\",\"markdownlint\"]}"); /***/ }), diff --git a/example/typescript/type-check.ts b/example/typescript/type-check.ts index 83c7bc1b..def7d776 100644 --- a/example/typescript/type-check.ts +++ b/example/typescript/type-check.ts @@ -35,8 +35,11 @@ function assertLintResults(results: markdownlint.LintResults) { assert.equal(results["string"][0].errorContext, null); assert.deepEqual(results["string"][0].errorRange, [ 9, 1 ]); assert(!!results["string"][0].fixInfo); + // @ts-ignore assert.equal(results["string"][0].fixInfo.editColumn, 10); + // @ts-ignore assert(!results["string"][0].fixInfo.deleteCount); + // @ts-ignore assert.equal(results["string"][0].fixInfo.insertText, "\n"); assert.equal(results["../bad.md"].length, 2); // Deliberate assignment to unused variable validates types diff --git a/lib/markdownlint.d.ts b/lib/markdownlint.d.ts index 7ab5a649..7a6199e3 100644 --- a/lib/markdownlint.d.ts +++ b/lib/markdownlint.d.ts @@ -310,7 +310,7 @@ type LintError = { /** * Fix information. */ - fixInfo: FixInfo; + fixInfo?: FixInfo; }; /** * Fix information. diff --git a/lib/markdownlint.js b/lib/markdownlint.js index d5f6270f..19ee17e6 100644 --- a/lib/markdownlint.js +++ b/lib/markdownlint.js @@ -1178,7 +1178,7 @@ module.exports = markdownlint; * @property {string} errorDetail Detail about the error. * @property {string} errorContext Context for the error. * @property {number[]} errorRange Column number (1-based) and length. - * @property {FixInfo} fixInfo Fix information. + * @property {FixInfo} [fixInfo] Fix information. */ /** diff --git a/package.json b/package.json index 53ace2ad..f2c902b4 100644 --- a/package.json +++ b/package.json @@ -24,11 +24,11 @@ "declaration": "npm run build-declaration && npm run test-declaration", "example": "cd example && node standalone.js && grunt markdownlint --force && gulp markdownlint", "lint": "eslint --max-warnings 0 .", - "lint-test-repos": "node test/markdownlint-test-repos.js", - "test": "tape test/markdownlint-test.js test/markdownlint-test-custom-rules.js test/markdownlint-test-helpers.js test/markdownlint-test-result-object.js test/markdownlint-test-scenarios.js", + "lint-test-repos": "ava test/markdownlint-test-repos.js", + "test": "ava test/markdownlint-test.js test/markdownlint-test-custom-rules.js test/markdownlint-test-helpers.js test/markdownlint-test-result-object.js test/markdownlint-test-scenarios.js", "test-cover": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 npm test", "test-declaration": "cd example/typescript && tsc && node type-check.js", - "test-extra": "node test/markdownlint-test-extra.js" + "test-extra": "ava --timeout=3m test/markdownlint-test-extra.js" }, "engines": { "node": ">=10" @@ -38,6 +38,7 @@ }, "devDependencies": { "@types/node": "~14.14.9", + "ava": "~3.15.0", "c8": "~7.3.5", "cpy-cli": "~3.1.1", "eslint": "~7.14.0", @@ -54,8 +55,6 @@ "npm-run-all": "~4.1.5", "rimraf": "~3.0.2", "strip-json-comments": "~3.1.1", - "tape": "~5.0.1", - "tape-player": "~0.1.1", "toml": "~3.0.0", "ts-loader": "~8.0.14", "tv4": "~1.3.0", diff --git a/test/markdownlint-test-custom-rules.js b/test/markdownlint-test-custom-rules.js index 679089bf..5975a64e 100644 --- a/test/markdownlint-test-custom-rules.js +++ b/test/markdownlint-test-custom-rules.js @@ -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(); }); }); diff --git a/test/markdownlint-test-extra.js b/test/markdownlint-test-extra.js index 08b7251d..d6e643df 100644 --- a/test/markdownlint-test-extra.js +++ b/test/markdownlint-test-extra.js @@ -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(); }); }); diff --git a/test/markdownlint-test-helpers.js b/test/markdownlint-test-helpers.js index a7900073..166d6db0 100644 --- a/test/markdownlint-test-helpers.js +++ b/test/markdownlint-test-helpers.js @@ -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 = [ "", "", @@ -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 = [ " -->", " -->", @@ -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 = [ "texttext", "", @@ -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) => { "> ", ">>" ]; - 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(); }); diff --git a/test/markdownlint-test-repos.js b/test/markdownlint-test-repos.js index b8327084..1263d29e 100644 --- a/test/markdownlint-test-repos.js +++ b/test/markdownlint-test-repos.js @@ -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); }); } diff --git a/test/markdownlint-test-result-object.js b/test/markdownlint-test-result-object.js index 23a8aaec..026b6bdd 100644 --- a/test/markdownlint-test-result-object.js +++ b/test/markdownlint-test-result-object.js @@ -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(); }); }); diff --git a/test/markdownlint-test-scenarios.js b/test/markdownlint-test-scenarios.js index f246bd02..98beeaba 100644 --- a/test/markdownlint-test-scenarios.js +++ b/test/markdownlint-test-scenarios.js @@ -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)))); diff --git a/test/markdownlint-test.js b/test/markdownlint-test.js index c8ab1e0d..9fbf9734 100644 --- a/test/markdownlint-test.js +++ b/test/markdownlint-test.js @@ -9,8 +9,7 @@ const pluginInline = require("markdown-it-for-inline"); const pluginSub = require("markdown-it-sub"); const pluginSup = require("markdown-it-sup"); const pluginTexMath = require("markdown-it-texmath"); -const tape = require("tape"); -require("tape-player"); +const test = require("ava").default; const tv4 = require("tv4"); const { homepage, version } = require("../package.json"); const markdownlint = require("../lib/markdownlint"); @@ -29,8 +28,8 @@ const configSchemaStrict = { "additionalProperties": false }; -tape("simpleAsync", (test) => { - test.plan(2); +test.cb("simpleAsync", (t) => { + t.plan(2); const options = { "strings": { "content": "# Heading" @@ -39,14 +38,14 @@ tape("simpleAsync", (test) => { const expected = "content: 1: MD047/single-trailing-newline " + "Files should end with a single newline character"; markdownlint(options, (err, actual) => { - test.ifError(err); - test.equal(actual.toString(), expected, "Unexpected results."); - test.end(); + t.falsy(err); + t.is(actual.toString(), expected, "Unexpected results."); + t.end(); }); }); -tape("simpleSync", (test) => { - test.plan(1); +test("simpleSync", (t) => { + t.plan(1); const options = { "strings": { "content": "# Heading" @@ -55,12 +54,11 @@ tape("simpleSync", (test) => { const expected = "content: 1: MD047/single-trailing-newline " + "Files should end with a single newline character"; const actual = markdownlint.sync(options).toString(); - test.equal(actual, expected, "Unexpected results."); - test.end(); + t.is(actual, expected, "Unexpected results."); }); -tape("simplePromise", (test) => { - test.plan(1); +test("simplePromise", (t) => { + t.plan(1); const options = { "strings": { "content": "# Heading" @@ -68,14 +66,13 @@ tape("simplePromise", (test) => { }; const expected = "content: 1: MD047/single-trailing-newline " + "Files should end with a single newline character"; - markdownlint.promises.markdownlint(options).then((actual) => { - test.equal(actual.toString(), expected, "Unexpected results."); - test.end(); + return markdownlint.promises.markdownlint(options).then((actual) => { + t.is(actual.toString(), expected, "Unexpected results."); }); }); -tape("projectFilesNoInlineConfig", (test) => { - test.plan(2); +test.cb("projectFilesNoInlineConfig", (t) => { + t.plan(2); const options = { "files": [ "README.md", @@ -90,20 +87,20 @@ tape("projectFilesNoInlineConfig", (test) => { } }; markdownlint(options, function callback(err, actual) { - test.ifError(err); + t.falsy(err); const expected = { "README.md": [], "CONTRIBUTING.md": [], "doc/CustomRules.md": [], "helpers/README.md": [] }; - test.deepEqual(actual, expected, "Issue(s) with project files."); - test.end(); + t.deepEqual(actual, expected, "Issue(s) with project files."); + t.end(); }); }); -tape("projectFilesInlineConfig", (test) => { - test.plan(2); +test.cb("projectFilesInlineConfig", (t) => { + t.plan(2); const options = { "files": [ "doc/Rules.md" ], "config": { @@ -112,17 +109,17 @@ tape("projectFilesInlineConfig", (test) => { } }; markdownlint(options, function callback(err, actual) { - test.ifError(err); + t.falsy(err); const expected = { "doc/Rules.md": [] }; - test.deepEqual(actual, expected, "Issue(s) with project files."); - test.end(); + t.deepEqual(actual, expected, "Issue(s) with project files."); + t.end(); }); }); -tape("stringInputLineEndings", (test) => { - test.plan(2); +test.cb("stringInputLineEndings", (t) => { + t.plan(2); const options = { "strings": { "cr": "One\rTwo\r#Three\n", @@ -136,20 +133,21 @@ tape("stringInputLineEndings", (test) => { "resultVersion": 0 }; markdownlint(options, function callback(err, actualResult) { - test.ifError(err); + t.falsy(err); const expectedResult = { "cr": { "MD018": [ 3 ] }, "lf": { "MD018": [ 3 ] }, "crlf": { "MD018": [ 3 ] }, "mixed": { "MD018": [ 3 ] } }; - test.deepEqual(actualResult, expectedResult, "Undetected issues."); - test.end(); + // @ts-ignore + t.deepEqual(actualResult, expectedResult, "Undetected issues."); + t.end(); }); }); -tape("inputOnlyNewline", (test) => { - test.plan(2); +test.cb("inputOnlyNewline", (t) => { + t.plan(2); const options = { "strings": { "cr": "\r", @@ -161,19 +159,19 @@ tape("inputOnlyNewline", (test) => { } }; markdownlint(options, function callback(err, actualResult) { - test.ifError(err); + t.falsy(err); const expectedResult = { "cr": [], "lf": [], "crlf": [] }; - test.deepEqual(actualResult, expectedResult, "Undetected issues."); - test.end(); + t.deepEqual(actualResult, expectedResult, "Undetected issues."); + t.end(); }); }); -tape("defaultTrue", (test) => { - test.plan(2); +test.cb("defaultTrue", (t) => { + t.plan(2); const options = { "files": [ "./test/atx_heading_spacing.md", @@ -185,7 +183,7 @@ tape("defaultTrue", (test) => { "resultVersion": 0 }; markdownlint(options, function callback(err, actualResult) { - test.ifError(err); + t.falsy(err); const expectedResult = { "./test/atx_heading_spacing.md": { "MD018": [ 1 ], @@ -196,13 +194,14 @@ tape("defaultTrue", (test) => { "MD041": [ 1 ] } }; - test.deepEqual(actualResult, expectedResult, "Undetected issues."); - test.end(); + // @ts-ignore + t.deepEqual(actualResult, expectedResult, "Undetected issues."); + t.end(); }); }); -tape("defaultFalse", (test) => { - test.plan(2); +test.cb("defaultFalse", (t) => { + t.plan(2); const options = { "files": [ "./test/atx_heading_spacing.md", @@ -214,18 +213,19 @@ tape("defaultFalse", (test) => { "resultVersion": 0 }; markdownlint(options, function callback(err, actualResult) { - test.ifError(err); + t.falsy(err); const expectedResult = { "./test/atx_heading_spacing.md": {}, "./test/first_heading_bad_atx.md": {} }; - test.deepEqual(actualResult, expectedResult, "Undetected issues."); - test.end(); + // @ts-ignore + t.deepEqual(actualResult, expectedResult, "Undetected issues."); + t.end(); }); }); -tape("defaultUndefined", (test) => { - test.plan(2); +test.cb("defaultUndefined", (t) => { + t.plan(2); const options = { "files": [ "./test/atx_heading_spacing.md", @@ -235,7 +235,7 @@ tape("defaultUndefined", (test) => { "resultVersion": 0 }; markdownlint(options, function callback(err, actualResult) { - test.ifError(err); + t.falsy(err); const expectedResult = { "./test/atx_heading_spacing.md": { "MD018": [ 1 ], @@ -246,13 +246,14 @@ tape("defaultUndefined", (test) => { "MD041": [ 1 ] } }; - test.deepEqual(actualResult, expectedResult, "Undetected issues."); - test.end(); + // @ts-ignore + t.deepEqual(actualResult, expectedResult, "Undetected issues."); + t.end(); }); }); -tape("disableRules", (test) => { - test.plan(2); +test.cb("disableRules", (t) => { + t.plan(2); const options = { "files": [ "./test/atx_heading_spacing.md", @@ -267,20 +268,21 @@ tape("disableRules", (test) => { "resultVersion": 0 }; markdownlint(options, function callback(err, actualResult) { - test.ifError(err); + t.falsy(err); const expectedResult = { "./test/atx_heading_spacing.md": { "MD018": [ 1 ] }, "./test/first_heading_bad_atx.md": {} }; - test.deepEqual(actualResult, expectedResult, "Undetected issues."); - test.end(); + // @ts-ignore + t.deepEqual(actualResult, expectedResult, "Undetected issues."); + t.end(); }); }); -tape("enableRules", (test) => { - test.plan(2); +test.cb("enableRules", (t) => { + t.plan(2); const options = { "files": [ "./test/atx_heading_spacing.md", @@ -294,7 +296,7 @@ tape("enableRules", (test) => { "resultVersion": 0 }; markdownlint(options, function callback(err, actualResult) { - test.ifError(err); + t.falsy(err); const expectedResult = { "./test/atx_heading_spacing.md": { "MD002": [ 3 ], @@ -304,13 +306,14 @@ tape("enableRules", (test) => { "MD002": [ 1 ] } }; - test.deepEqual(actualResult, expectedResult, "Undetected issues."); - test.end(); + // @ts-ignore + t.deepEqual(actualResult, expectedResult, "Undetected issues."); + t.end(); }); }); -tape("enableRulesMixedCase", (test) => { - test.plan(2); +test.cb("enableRulesMixedCase", (t) => { + t.plan(2); const options = { "files": [ "./test/atx_heading_spacing.md", @@ -324,7 +327,7 @@ tape("enableRulesMixedCase", (test) => { "resultVersion": 0 }; markdownlint(options, function callback(err, actualResult) { - test.ifError(err); + t.falsy(err); const expectedResult = { "./test/atx_heading_spacing.md": { "MD002": [ 3 ], @@ -334,13 +337,14 @@ tape("enableRulesMixedCase", (test) => { "MD002": [ 1 ] } }; - test.deepEqual(actualResult, expectedResult, "Undetected issues."); - test.end(); + // @ts-ignore + t.deepEqual(actualResult, expectedResult, "Undetected issues."); + t.end(); }); }); -tape("disableTag", (test) => { - test.plan(2); +test.cb("disableTag", (t) => { + t.plan(2); const options = { "files": [ "./test/atx_heading_spacing.md", @@ -353,7 +357,7 @@ tape("disableTag", (test) => { "resultVersion": 0 }; markdownlint(options, function callback(err, actualResult) { - test.ifError(err); + t.falsy(err); const expectedResult = { "./test/atx_heading_spacing.md": { "MD041": [ 1 ] @@ -362,13 +366,14 @@ tape("disableTag", (test) => { "MD041": [ 1 ] } }; - test.deepEqual(actualResult, expectedResult, "Undetected issues."); - test.end(); + // @ts-ignore + t.deepEqual(actualResult, expectedResult, "Undetected issues."); + t.end(); }); }); -tape("enableTag", (test) => { - test.plan(2); +test.cb("enableTag", (t) => { + t.plan(2); const options = { "files": [ "./test/atx_heading_spacing.md", @@ -382,7 +387,7 @@ tape("enableTag", (test) => { "resultVersion": 0 }; markdownlint(options, function callback(err, actualResult) { - test.ifError(err); + t.falsy(err); const expectedResult = { "./test/atx_heading_spacing.md": { "MD018": [ 1 ], @@ -390,13 +395,14 @@ tape("enableTag", (test) => { }, "./test/first_heading_bad_atx.md": {} }; - test.deepEqual(actualResult, expectedResult, "Undetected issues."); - test.end(); + // @ts-ignore + t.deepEqual(actualResult, expectedResult, "Undetected issues."); + t.end(); }); }); -tape("enableTagMixedCase", (test) => { - test.plan(2); +test.cb("enableTagMixedCase", (t) => { + t.plan(2); const options = { "files": [ "./test/atx_heading_spacing.md", @@ -410,7 +416,7 @@ tape("enableTagMixedCase", (test) => { "resultVersion": 0 }; markdownlint(options, function callback(err, actualResult) { - test.ifError(err); + t.falsy(err); const expectedResult = { "./test/atx_heading_spacing.md": { "MD018": [ 1 ], @@ -418,31 +424,32 @@ tape("enableTagMixedCase", (test) => { }, "./test/first_heading_bad_atx.md": {} }; - test.deepEqual(actualResult, expectedResult, "Undetected issues."); - test.end(); + // @ts-ignore + t.deepEqual(actualResult, expectedResult, "Undetected issues."); + t.end(); }); }); -tape("styleFiles", (test) => { - test.plan(4); +test.cb("styleFiles", (t) => { + t.plan(4); fs.readdir("./style", function readdir(err, files) { - test.ifError(err); + t.falsy(err); files.forEach(function forFile(file) { - test.ok(require(path.join("../style", file)), "Unable to load/parse."); + t.truthy(require(path.join("../style", file)), "Unable to load/parse."); }); - test.end(); + t.end(); }); }); -tape("styleAll", (test) => { - test.plan(2); +test.cb("styleAll", (t) => { + t.plan(2); const options = { "files": [ "./test/break-all-the-rules.md" ], "config": require("../style/all.json"), "resultVersion": 0 }; markdownlint(options, function callback(err, actualResult) { - test.ifError(err); + t.falsy(err); const expectedResult = { "./test/break-all-the-rules.md": { "MD001": [ 3 ], @@ -486,20 +493,21 @@ tape("styleAll", (test) => { "MD048": [ 77 ] } }; - test.deepEqual(actualResult, expectedResult, "Undetected issues."); - test.end(); + // @ts-ignore + t.deepEqual(actualResult, expectedResult, "Undetected issues."); + t.end(); }); }); -tape("styleRelaxed", (test) => { - test.plan(2); +test.cb("styleRelaxed", (t) => { + t.plan(2); const options = { "files": [ "./test/break-all-the-rules.md" ], "config": require("../style/relaxed.json"), "resultVersion": 0 }; markdownlint(options, function callback(err, actualResult) { - test.ifError(err); + t.falsy(err); const expectedResult = { "./test/break-all-the-rules.md": { "MD001": [ 3 ], @@ -528,13 +536,14 @@ tape("styleRelaxed", (test) => { "MD048": [ 77 ] } }; - test.deepEqual(actualResult, expectedResult, "Undetected issues."); - test.end(); + // @ts-ignore + t.deepEqual(actualResult, expectedResult, "Undetected issues."); + t.end(); }); }); -tape("nullFrontMatter", (test) => { - test.plan(2); +test.cb("nullFrontMatter", (t) => { + t.plan(2); markdownlint({ "strings": { "content": "---\n\t\n---\n# Heading\n" @@ -546,17 +555,18 @@ tape("nullFrontMatter", (test) => { }, "resultVersion": 0 }, function callback(err, result) { - test.ifError(err); + t.falsy(err); const expectedResult = { "content": { "MD010": [ 2 ] } }; - test.deepEqual(result, expectedResult, "Undetected issues."); - test.end(); + // @ts-ignore + t.deepEqual(result, expectedResult, "Undetected issues."); + t.end(); }); }); -tape("customFrontMatter", (test) => { - test.plan(2); +test.cb("customFrontMatter", (t) => { + t.plan(2); markdownlint({ "strings": { "content": "\n\t\n\n# Heading\n" @@ -567,17 +577,17 @@ tape("customFrontMatter", (test) => { "MD010": true } }, function callback(err, result) { - test.ifError(err); + t.falsy(err); const expectedResult = { "content": [] }; - test.deepEqual(result, expectedResult, "Did not get empty results."); - test.end(); + t.deepEqual(result, expectedResult, "Did not get empty results."); + t.end(); }); }); -tape("noInlineConfig", (test) => { - test.plan(2); +test.cb("noInlineConfig", (t) => { + t.plan(2); markdownlint({ "strings": { "content": [ @@ -597,19 +607,20 @@ tape("noInlineConfig", (test) => { "noInlineConfig": true, "resultVersion": 0 }, function callback(err, result) { - test.ifError(err); + t.falsy(err); const expectedResult = { "content": { "MD010": [ 3, 7, 11 ] } }; - test.deepEqual(result, expectedResult, "Undetected issues."); - test.end(); + // @ts-ignore + t.deepEqual(result, expectedResult, "Undetected issues."); + t.end(); }); }); -tape("readmeHeadings", (test) => { - test.plan(2); +test.cb("readmeHeadings", (t) => { + t.plan(2); markdownlint({ "files": "README.md", "noInlineConfig": true, @@ -656,29 +667,29 @@ tape("readmeHeadings", (test) => { } } }, function callback(err, result) { - test.ifError(err); + t.falsy(err); const expected = { "README.md": [] }; - test.deepEqual(result, expected, "Unexpected issues."); - test.end(); + t.deepEqual(result, expected, "Unexpected issues."); + t.end(); }); }); -tape("filesArrayNotModified", (test) => { - test.plan(2); +test.cb("filesArrayNotModified", (t) => { + t.plan(2); const files = [ "./test/atx_heading_spacing.md", "./test/first_heading_bad_atx.md" ]; const expectedFiles = files.slice(); markdownlint({ "files": files }, function callback(err) { - test.ifError(err); - test.deepEqual(files, expectedFiles, "Files modified."); - test.end(); + t.falsy(err); + t.deepEqual(files, expectedFiles, "Files modified."); + t.end(); }); }); -tape("filesArrayAsString", (test) => { - test.plan(2); +test.cb("filesArrayAsString", (t) => { + t.plan(2); markdownlint({ "files": "README.md", "noInlineConfig": true, @@ -687,87 +698,87 @@ tape("filesArrayAsString", (test) => { "MD024": false } }, function callback(err, actual) { - test.ifError(err); + t.falsy(err); const expected = { "README.md": [] }; - test.deepEqual(actual, expected, "Unexpected issues."); - test.end(); + t.deepEqual(actual, expected, "Unexpected issues."); + t.end(); }); }); -tape("missingOptions", (test) => { - test.plan(2); +test.cb("missingOptions", (t) => { + t.plan(2); markdownlint(null, function callback(err, result) { - test.ifError(err); - test.deepEqual( + t.falsy(err); + t.deepEqual( result, {}, "Did not get empty result for missing options." ); - test.end(); + t.end(); }); }); -tape("missingFilesAndStrings", (test) => { - test.plan(2); +test.cb("missingFilesAndStrings", (t) => { + t.plan(2); markdownlint({}, function callback(err, result) { - test.ifError(err); - test.ok(result, "Did not get result for missing files/strings."); - test.end(); + t.falsy(err); + t.truthy(result, "Did not get result for missing files/strings."); + t.end(); }); }); -tape("missingCallback", (test) => { - test.plan(0); +test("missingCallback", (t) => { + t.plan(0); // @ts-ignore markdownlint(); - test.end(); }); -tape("badFile", (test) => { - test.plan(4); +test.cb("badFile", (t) => { + t.plan(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."); + t.truthy(err, "Did not get an error for bad file."); + t.true(err instanceof Error, "Error not instance of Error."); // @ts-ignore - test.equal(err.code, "ENOENT", "Error code for bad file not ENOENT."); - test.ok(!result, "Got result for bad file."); - test.end(); + t.is(err.code, "ENOENT", "Error code for bad file not ENOENT."); + t.true(!result, "Got result for bad file."); + t.end(); }); }); -tape("badFileSync", (test) => { - test.plan(1); - test.throws( +test("badFileSync", (t) => { + t.plan(1); + t.throws( function badFileCall() { markdownlint.sync({ "files": [ "./badFile" ] }); }, - /ENOENT/, + { + "message": /ENOENT/ + }, "Did not get correct exception for bad file." ); - test.end(); }); -tape("badFilePromise", (test) => { - test.plan(3); +test.cb("badFilePromise", (t) => { + t.plan(3); markdownlint.promises.markdownlint({ "files": [ "./badFile" ] }).then( null, (error) => { - test.ok(error, "Did not get an error for bad file."); - test.ok(error instanceof Error, "Error not instance of Error."); - test.equal(error.code, "ENOENT", "Error code for bad file not ENOENT."); - test.end(); + t.truthy(error, "Did not get an error for bad file."); + t.true(error instanceof Error, "Error not instance of Error."); + t.is(error.code, "ENOENT", "Error code for bad file not ENOENT."); + t.end(); } ); }); -tape("missingStringValue", (test) => { - test.plan(2); +test.cb("missingStringValue", (t) => { + t.plan(2); markdownlint({ "strings": { "undefined": undefined, @@ -775,19 +786,19 @@ tape("missingStringValue", (test) => { "empty": "" } }, function callback(err, result) { - test.ifError(err); + t.falsy(err); const expectedResult = { "undefined": [], "null": [], "empty": [] }; - test.deepEqual(result, expectedResult, "Did not get empty results."); - test.end(); + t.deepEqual(result, expectedResult, "Did not get empty results."); + t.end(); }); }); -tape("readme", (test) => { - test.plan(115); +test.cb("readme", (t) => { + t.plan(115); const tagToRules = {}; rules.forEach(function forRule(rule) { rule.tags.forEach(function forTag(tag) { @@ -798,7 +809,7 @@ tape("readme", (test) => { }); fs.readFile("README.md", "utf8", function readFile(err, contents) { - test.ifError(err); + t.falsy(err); const rulesLeft = rules.slice(); let seenRelated = false; let seenRules = false; @@ -828,7 +839,7 @@ tape("readme", (test) => { } else if (token.type === "inline") { if (inRules) { const rule = rulesLeft.shift(); - test.ok(rule, + t.truthy(rule, "Missing rule implementation for " + token.content + "."); if (rule) { const ruleName = rule.names[0]; @@ -839,33 +850,33 @@ tape("readme", (test) => { if (deprecatedRuleNames.has(ruleName)) { expected = "~~" + expected + "~~"; } - test.equal(token.content, expected, "Rule mismatch."); + t.is(token.content, expected, "Rule mismatch."); } } else if (inTags) { const parts = token.content.replace(/\*\*/g, "").split(/ - |, |,\n/); const tag = parts.shift(); - test.deepEqual(parts, tagToRules[tag] || [], + t.deepEqual(parts, tagToRules[tag] || [], "Rule mismatch for tag " + tag + "."); delete tagToRules[tag]; } } }); const ruleLeft = rulesLeft.shift(); - test.ok(!ruleLeft, + t.true(!ruleLeft, "Missing rule documentation for " + (ruleLeft || "[NO RULE]").toString() + "."); const tagLeft = Object.keys(tagToRules).shift(); - test.ok(!tagLeft, "Undocumented tag " + tagLeft + "."); - test.end(); + t.true(!tagLeft, "Undocumented tag " + tagLeft + "."); + t.end(); }); }); -tape("rules", (test) => { - test.plan(336); +test.cb("rules", (t) => { + t.plan(336); fs.readFile("doc/Rules.md", "utf8", (err, contents) => { - test.ifError(err); + t.falsy(err); const rulesLeft = rules.slice(); let inHeading = false; let rule = null; @@ -876,11 +887,11 @@ tape("rules", (test) => { // eslint-disable-next-line func-style const testTagsAliasesParams = (r) => { r = r || "[NO RULE]"; - test.ok(ruleHasTags, + t.true(ruleHasTags, "Missing tags for rule " + r.names + "."); - test.ok(ruleHasAliases, + t.true(ruleHasAliases, "Missing aliases for rule " + r.names + "."); - test.ok(!ruleUsesParams, + t.true(!ruleUsesParams, "Missing parameters for rule " + r.names + "."); }; md.parse(contents, {}).forEach(function forToken(token) { @@ -894,14 +905,14 @@ tape("rules", (test) => { rule = rulesLeft.shift(); ruleHasTags = false; ruleHasAliases = false; - test.ok(rule, + t.truthy(rule, "Missing rule implementation for " + token.content + "."); const ruleName = rule.names[0]; let headingContent = ruleName + " - " + rule.description; if (deprecatedRuleNames.has(ruleName)) { headingContent = "~~" + headingContent + "~~"; } - test.equal(token.content, + t.is(token.content, headingContent, "Rule mismatch."); ruleUsesParams = rule.function.toString() @@ -913,11 +924,11 @@ tape("rules", (test) => { ruleUsesParams.sort(); } } else if (token.content.startsWith("Tags: ") && rule) { - test.deepEqual(token.content.split(tagAliasParameterRe).slice(1), + t.deepEqual(token.content.split(tagAliasParameterRe).slice(1), rule.tags, "Tag mismatch for rule " + rule.names + "."); ruleHasTags = true; } else if (token.content.startsWith("Aliases: ") && rule) { - test.deepEqual(token.content.split(tagAliasParameterRe).slice(1), + t.deepEqual(token.content.split(tagAliasParameterRe).slice(1), rule.names.slice(1), "Alias mismatch for rule " + rule.names + "."); ruleHasAliases = true; @@ -930,24 +941,24 @@ tape("rules", (test) => { return !inDetails; }); parameters.sort(); - test.deepEqual(parameters, ruleUsesParams, + t.deepEqual(parameters, ruleUsesParams, "Missing parameter for rule " + rule.names); ruleUsesParams = null; } } }); const ruleLeft = rulesLeft.shift(); - test.ok(!ruleLeft, + t.true(!ruleLeft, "Missing rule documentation for " + (ruleLeft || { "names": "[NO RULE]" }).names + "."); if (rule) { testTagsAliasesParams(rule); } - test.end(); + t.end(); }); }); -tape("validateJsonUsingConfigSchemaStrict", (test) => { +test("validateJsonUsingConfigSchemaStrict", (t) => { const jsonFileRe = /\.json$/i; const resultsFileRe = /\.results\.json$/i; const jsConfigFileRe = /^jsconfig\.json$/i; @@ -964,16 +975,15 @@ tape("validateJsonUsingConfigSchemaStrict", (test) => { path.join(testDirectory, file), "utf8" ); - test.ok( + t.true( // @ts-ignore tv4.validate(JSON.parse(data), configSchemaStrict), file + "\n" + JSON.stringify(tv4.error, null, 2)); }); - test.end(); }); -tape("validateConfigSchemaAllowsUnknownProperties", (test) => { - test.plan(4); +test("validateConfigSchemaAllowsUnknownProperties", (t) => { + t.plan(4); const testCases = [ { "property": true @@ -985,223 +995,220 @@ tape("validateConfigSchemaAllowsUnknownProperties", (test) => { } ]; testCases.forEach((testCase) => { - test.ok( + t.true( // @ts-ignore tv4.validate(testCase, configSchema), "Unknown property blocked by default: " + JSON.stringify(testCase)); - test.notok( + t.false( // @ts-ignore tv4.validate(testCase, configSchemaStrict), "Unknown property allowed when strict: " + JSON.stringify(testCase)); }); - test.end(); }); -tape("configSingle", (test) => { - test.plan(2); +test.cb("configSingle", (t) => { + t.plan(2); markdownlint.readConfig("./test/config/config-child.json", function callback(err, actual) { - test.ifError(err); + t.falsy(err); const expected = require("./config/config-child.json"); - test.deepEqual(actual, expected, "Config object not correct."); - test.end(); + t.deepEqual(actual, expected, "Config object not correct."); + t.end(); }); }); -tape("configAbsolute", (test) => { - test.plan(2); +test.cb("configAbsolute", (t) => { + t.plan(2); markdownlint.readConfig(path.join(__dirname, "config", "config-child.json"), function callback(err, actual) { - test.ifError(err); + t.falsy(err); const expected = require("./config/config-child.json"); - test.deepEqual(actual, expected, "Config object not correct."); - test.end(); + t.deepEqual(actual, expected, "Config object not correct."); + t.end(); }); }); -tape("configMultiple", (test) => { - test.plan(2); +test.cb("configMultiple", (t) => { + t.plan(2); markdownlint.readConfig("./test/config/config-grandparent.json", function callback(err, actual) { - test.ifError(err); + t.falsy(err); const expected = { ...require("./config/config-child.json"), ...require("./config/config-parent.json"), ...require("./config/config-grandparent.json") }; delete expected.extends; - test.deepEqual(actual, expected, "Config object not correct."); - test.end(); + t.deepEqual(actual, expected, "Config object not correct."); + t.end(); }); }); -tape("configMultipleWithRequireResolve", (test) => { - test.plan(2); +test.cb("configMultipleWithRequireResolve", (t) => { + t.plan(2); markdownlint.readConfig("./test/config/config-packageparent.json", function callback(err, actual) { - test.ifError(err); + t.falsy(err); const expected = { ...require("./node_modules/pseudo-package/config-frompackage.json"), ...require("./config/config-packageparent.json") }; delete expected.extends; - test.deepEqual(actual, expected, "Config object not correct."); - test.end(); + t.deepEqual(actual, expected, "Config object not correct."); + t.end(); }); }); -tape("configBadFile", (test) => { - test.plan(4); +test.cb("configBadFile", (t) => { + t.plan(4); markdownlint.readConfig("./test/config/config-badfile.json", 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."); + t.truthy(err, "Did not get an error for bad file."); + t.true(err instanceof Error, "Error not instance of Error."); // @ts-ignore - test.equal(err.code, "ENOENT", "Error code for bad file not ENOENT."); - test.ok(!result, "Got result for bad file."); - test.end(); + t.is(err.code, "ENOENT", "Error code for bad file not ENOENT."); + t.true(!result, "Got result for bad file."); + t.end(); }); }); -tape("configBadChildFile", (test) => { - test.plan(4); +test.cb("configBadChildFile", (t) => { + t.plan(4); markdownlint.readConfig("./test/config/config-badchildfile.json", function callback(err, result) { - test.ok(err, "Did not get an error for bad child file."); - test.ok(err instanceof Error, "Error not instance of Error."); + t.truthy(err, "Did not get an error for bad child file."); + t.true(err instanceof Error, "Error not instance of Error."); // @ts-ignore - test.equal(err.code, "ENOENT", + t.is(err.code, "ENOENT", "Error code for bad child file not ENOENT."); - test.ok(!result, "Got result for bad child file."); - test.end(); + t.true(!result, "Got result for bad child file."); + t.end(); }); }); -tape("configBadChildPackage", (test) => { - test.plan(4); +test.cb("configBadChildPackage", (t) => { + t.plan(4); markdownlint.readConfig("./test/config/config-badchildpackage.json", function callback(err, result) { - test.ok(err, "Did not get an error for bad child package."); - test.ok(err instanceof Error, "Error not instance of Error."); + t.truthy(err, "Did not get an error for bad child package."); + t.true(err instanceof Error, "Error not instance of Error."); // @ts-ignore - test.equal(err.code, "ENOENT", + t.is(err.code, "ENOENT", "Error code for bad child package not ENOENT."); - test.ok(!result, "Got result for bad child package."); - test.end(); + t.true(!result, "Got result for bad child package."); + t.end(); }); }); -tape("configBadJson", (test) => { - test.plan(3); +test.cb("configBadJson", (t) => { + t.plan(3); markdownlint.readConfig("./test/config/config-badjson.json", function callback(err, result) { - test.ok(err, "Did not get an error for bad JSON."); - test.ok(err instanceof Error, "Error not instance of Error."); - test.ok(!result, "Got result for bad JSON."); - test.end(); + t.truthy(err, "Did not get an error for bad JSON."); + t.true(err instanceof Error, "Error not instance of Error."); + t.true(!result, "Got result for bad JSON."); + t.end(); }); }); -tape("configBadChildJson", (test) => { - test.plan(3); +test.cb("configBadChildJson", (t) => { + t.plan(3); markdownlint.readConfig("./test/config/config-badchildjson.json", function callback(err, result) { - test.ok(err, "Did not get an error for bad child JSON."); - test.ok(err instanceof Error, "Error not instance of Error."); - test.ok(!result, "Got result for bad child JSON."); - test.end(); + t.truthy(err, "Did not get an error for bad child JSON."); + t.true(err instanceof Error, "Error not instance of Error."); + t.true(!result, "Got result for bad child JSON."); + t.end(); }); }); -tape("configSingleYaml", (test) => { - test.plan(2); +test.cb("configSingleYaml", (t) => { + t.plan(2); markdownlint.readConfig( "./test/config/config-child.yaml", // @ts-ignore [ require("js-yaml").safeLoad ], function callback(err, actual) { - test.ifError(err); + t.falsy(err); const expected = require("./config/config-child.json"); - test.deepEqual(actual, expected, "Config object not correct."); - test.end(); + t.deepEqual(actual, expected, "Config object not correct."); + t.end(); }); }); -tape("configMultipleYaml", (test) => { - test.plan(2); +test.cb("configMultipleYaml", (t) => { + t.plan(2); markdownlint.readConfig( "./test/config/config-grandparent.yaml", // @ts-ignore [ require("js-yaml").safeLoad ], function callback(err, actual) { - test.ifError(err); + t.falsy(err); const expected = { ...require("./config/config-child.json"), ...require("./config/config-parent.json"), ...require("./config/config-grandparent.json") }; delete expected.extends; - test.deepEqual(actual, expected, "Config object not correct."); - test.end(); + t.deepEqual(actual, expected, "Config object not correct."); + t.end(); }); }); -tape("configMultipleHybrid", (test) => { - test.plan(2); +test.cb("configMultipleHybrid", (t) => { + t.plan(2); markdownlint.readConfig( "./test/config/config-grandparent-hybrid.yaml", // @ts-ignore [ JSON.parse, require("toml").parse, require("js-yaml").safeLoad ], function callback(err, actual) { - test.ifError(err); + t.falsy(err); const expected = { ...require("./config/config-child.json"), ...require("./config/config-parent.json"), ...require("./config/config-grandparent.json") }; delete expected.extends; - test.deepLooseEqual(actual, expected, "Config object not correct."); - test.end(); + t.like(actual, expected, "Config object not correct."); + t.end(); }); }); -tape("configBadHybrid", (test) => { - test.plan(4); +test.cb("configBadHybrid", (t) => { + t.plan(4); markdownlint.readConfig( "./test/config/config-badcontent.txt", // @ts-ignore [ JSON.parse, require("toml").parse, require("js-yaml").safeLoad ], function callback(err, result) { - test.ok(err, "Did not get an error for bad child JSON."); - test.ok(err instanceof Error, "Error not instance of Error."); - test.ok(err.message.match( + t.truthy(err, "Did not get an error for bad child JSON."); + t.true(err instanceof Error, "Error not instance of Error."); + t.truthy(err.message.match( // eslint-disable-next-line max-len /^Unable to parse '[^']*'; Unexpected token \S+ in JSON at position \d+; Expected [^;]+ or end of input but "\S+" found.; end of the stream or a document separator is expected at line \d+, column \d+:[^;]*$/ ), "Error message unexpected."); - test.ok(!result, "Got result for bad child JSON."); - test.end(); + t.true(!result, "Got result for bad child JSON."); + t.end(); }); }); -tape("configSingleSync", (test) => { - test.plan(1); +test("configSingleSync", (t) => { + t.plan(1); const actual = markdownlint.readConfigSync("./test/config/config-child.json"); const expected = require("./config/config-child.json"); - test.deepEqual(actual, expected, "Config object not correct."); - test.end(); + t.deepEqual(actual, expected, "Config object not correct."); }); -tape("configAbsoluteSync", (test) => { - test.plan(1); +test("configAbsoluteSync", (t) => { + t.plan(1); const actual = markdownlint.readConfigSync( path.join(__dirname, "config", "config-child.json")); const expected = require("./config/config-child.json"); - test.deepEqual(actual, expected, "Config object not correct."); - test.end(); + t.deepEqual(actual, expected, "Config object not correct."); }); -tape("configMultipleSync", (test) => { - test.plan(1); +test("configMultipleSync", (t) => { + t.plan(1); const actual = markdownlint.readConfigSync("./test/config/config-grandparent.json"); const expected = { @@ -1210,70 +1217,74 @@ tape("configMultipleSync", (test) => { ...require("./config/config-grandparent.json") }; delete expected.extends; - test.deepEqual(actual, expected, "Config object not correct."); - test.end(); + t.deepEqual(actual, expected, "Config object not correct."); }); -tape("configBadFileSync", (test) => { - test.plan(1); - test.throws( +test("configBadFileSync", (t) => { + t.plan(1); + t.throws( function badFileCall() { markdownlint.readConfigSync("./test/config/config-badfile.json"); }, - /ENOENT/, + { + "message": /ENOENT/ + }, "Did not get correct exception for bad file." ); - test.end(); }); -tape("configBadChildFileSync", (test) => { - test.plan(1); - test.throws( +test("configBadChildFileSync", (t) => { + t.plan(1); + t.throws( function badChildFileCall() { markdownlint.readConfigSync("./test/config/config-badchildfile.json"); }, - /ENOENT/, + { + "message": /ENOENT/ + }, "Did not get correct exception for bad child file." ); - test.end(); }); -tape("configBadJsonSync", (test) => { - test.plan(1); - test.throws( +test("configBadJsonSync", (t) => { + t.plan(1); + t.throws( function badJsonCall() { markdownlint.readConfigSync("./test/config/config-badjson.json"); }, - /Unable to parse '[^']*'; Unexpected token \S+ in JSON at position \d+/, + { + "message": + /Unable to parse '[^']*'; Unexpected token \S+ in JSON at position \d+/ + }, "Did not get correct exception for bad JSON." ); - test.end(); }); -tape("configBadChildJsonSync", (test) => { - test.plan(1); - test.throws( +test("configBadChildJsonSync", (t) => { + t.plan(1); + t.throws( function badChildJsonCall() { markdownlint.readConfigSync("./test/config/config-badchildjson.json"); }, - /Unable to parse '[^']*'; Unexpected token \S+ in JSON at position \d+/, + { + "message": + /Unable to parse '[^']*'; Unexpected token \S+ in JSON at position \d+/ + }, "Did not get correct exception for bad child JSON." ); - test.end(); }); -tape("configSingleYamlSync", (test) => { - test.plan(1); +test("configSingleYamlSync", (t) => { + t.plan(1); const actual = markdownlint.readConfigSync( // @ts-ignore "./test/config/config-child.yaml", [ require("js-yaml").safeLoad ]); const expected = require("./config/config-child.json"); - test.deepEqual(actual, expected, "Config object not correct."); - test.end(); + t.deepEqual(actual, expected, "Config object not correct."); }); -tape("configMultipleYamlSync", (test) => { - test.plan(1); +test("configMultipleYamlSync", (t) => { + t.plan(1); const actual = markdownlint.readConfigSync( // @ts-ignore "./test/config/config-grandparent.yaml", [ require("js-yaml").safeLoad ]); @@ -1283,12 +1294,11 @@ tape("configMultipleYamlSync", (test) => { ...require("./config/config-grandparent.json") }; delete expected.extends; - test.deepEqual(actual, expected, "Config object not correct."); - test.end(); + t.deepEqual(actual, expected, "Config object not correct."); }); -tape("configMultipleHybridSync", (test) => { - test.plan(1); +test("configMultipleHybridSync", (t) => { + t.plan(1); const actual = markdownlint.readConfigSync( "./test/config/config-grandparent-hybrid.yaml", // @ts-ignore @@ -1299,85 +1309,83 @@ tape("configMultipleHybridSync", (test) => { ...require("./config/config-grandparent.json") }; delete expected.extends; - test.deepLooseEqual(actual, expected, "Config object not correct."); - test.end(); + t.like(actual, expected, "Config object not correct."); }); -tape("configBadHybridSync", (test) => { - test.plan(1); - test.throws( +test("configBadHybridSync", (t) => { + t.plan(1); + t.throws( function badHybridCall() { markdownlint.readConfigSync( "./test/config/config-badcontent.txt", // @ts-ignore [ JSON.parse, require("toml").parse, require("js-yaml").safeLoad ]); }, - // eslint-disable-next-line max-len - /Unable to parse '[^']*'; Unexpected token \S+ in JSON at position \d+; Expected [^;]+ or end of input but "\S+" found.; end of the stream or a document separator is expected at line \d+, column \d+:[^;]*/, + { + // eslint-disable-next-line max-len + "message": /Unable to parse '[^']*'; Unexpected token \S+ in JSON at position \d+; Expected [^;]+ or end of input but "\S+" found.; end of the stream or a document separator is expected at line \d+, column \d+:[^;]*/ + }, "Did not get correct exception for bad content." ); - test.end(); }); -tape("configSinglePromise", (test) => { - test.plan(1); +test.cb("configSinglePromise", (t) => { + t.plan(1); markdownlint.promises.readConfig("./test/config/config-child.json") .then((actual) => { const expected = require("./config/config-child.json"); - test.deepEqual(actual, expected, "Config object not correct."); - test.end(); + t.deepEqual(actual, expected, "Config object not correct."); + t.end(); }); }); -tape("configBadFilePromise", (test) => { - test.plan(2); +test.cb("configBadFilePromise", (t) => { + t.plan(2); markdownlint.promises.readConfig("./test/config/config-badfile.json") .then( null, (error) => { - test.ok(error, "Did not get an error for bad JSON."); - test.ok(error instanceof Error, "Error not instance of Error."); - test.end(); + t.truthy(error, "Did not get an error for bad JSON."); + t.true(error instanceof Error, "Error not instance of Error."); + t.end(); } ); }); -tape("allBuiltInRulesHaveValidUrl", (test) => { - test.plan(132); +test("allBuiltInRulesHaveValidUrl", (t) => { + t.plan(132); rules.forEach(function forRule(rule) { - test.ok(rule.information); - test.ok(Object.getPrototypeOf(rule.information) === URL.prototype); + t.truthy(rule.information); + t.true(Object.getPrototypeOf(rule.information) === URL.prototype); const name = rule.names[0].toLowerCase(); - test.equal( + t.is( rule.information.href, `${homepage}/blob/v${version}/doc/Rules.md#${name}` ); }); - test.end(); }); -tape("someCustomRulesHaveValidUrl", (test) => { - test.plan(7); +test("someCustomRulesHaveValidUrl", (t) => { + t.plan(7); customRules.all.forEach(function forRule(rule) { - test.ok(!rule.information || + t.true(!rule.information || (Object.getPrototypeOf(rule.information) === URL.prototype)); if (rule === customRules.anyBlockquote) { - test.equal( + t.is( rule.information.href, `${homepage}/blob/main/test/rules/any-blockquote.js` ); } else if (rule === customRules.lettersEX) { - test.equal( + t.is( rule.information.href, `${homepage}/blob/main/test/rules/letters-E-X.js` ); } }); - test.end(); }); -tape("markdownItPluginsSingle", (test) => { - test.plan(2); +test.cb("markdownItPluginsSingle", (t) => { + t.plan(2); markdownlint({ "strings": { "string": "# Heading\n\nText [ link ](https://example.com)\n" @@ -1393,15 +1401,15 @@ tape("markdownItPluginsSingle", (test) => { ] ] }, function callback(err, actual) { - test.ifError(err); + t.falsy(err); const expected = { "string": [] }; - test.deepEqual(actual, expected, "Unexpected issues."); - test.end(); + t.deepEqual(actual, expected, "Unexpected issues."); + t.end(); }); }); -tape("markdownItPluginsMultiple", (test) => { - test.plan(4); +test.cb("markdownItPluginsMultiple", (t) => { + t.plan(4); markdownlint({ "strings": { "string": "# Heading\n\nText H~2~0 text 29^th^ text\n" @@ -1409,19 +1417,19 @@ tape("markdownItPluginsMultiple", (test) => { "markdownItPlugins": [ [ pluginSub ], [ pluginSup ], - [ pluginInline, "check_sub_plugin", "sub_open", test.ok ], - [ pluginInline, "check_sup_plugin", "sup_open", test.ok ] + [ pluginInline, "check_sub_plugin", "sub_open", () => t.true(true) ], + [ pluginInline, "check_sup_plugin", "sup_open", () => t.true(true) ] ] }, function callback(err, actual) { - test.ifError(err); + t.falsy(err); const expected = { "string": [] }; - test.deepEqual(actual, expected, "Unexpected issues."); - test.end(); + t.deepEqual(actual, expected, "Unexpected issues."); + t.end(); }); }); -tape("markdownItPluginsMathjax", (test) => { - test.plan(2); +test.cb("markdownItPluginsMathjax", (t) => { + t.plan(2); markdownlint({ "strings": { "string": @@ -1437,15 +1445,15 @@ tape("markdownItPluginsMathjax", (test) => { }, "markdownItPlugins": [ [ pluginTexMath, pluginTexMathOptions ] ] }, function callback(err, actual) { - test.ifError(err); + t.falsy(err); const expected = { "string": [] }; - test.deepEqual(actual, expected, "Unexpected issues."); - test.end(); + t.deepEqual(actual, expected, "Unexpected issues."); + t.end(); }); }); -tape("markdownItPluginsMathjaxIssue166", (test) => { - test.plan(2); +test.cb("markdownItPluginsMathjaxIssue166", (t) => { + t.plan(2); markdownlint({ "strings": { "string": @@ -1460,36 +1468,36 @@ $$\n` "markdownItPlugins": [ [ pluginTexMath, pluginTexMathOptions ] ], "resultVersion": 0 }, function callback(err, actual) { - test.ifError(err); + t.falsy(err); const expected = { "string": { "MD041": [ 1 ] } }; - test.deepEqual(actual, expected, "Unexpected issues."); - test.end(); + // @ts-ignore + t.deepEqual(actual, expected, "Unexpected issues."); + t.end(); }); }); -tape("texmath-content-in-lists with texmath plugin", (test) => { - test.plan(2); +test.cb("texmath-content-in-lists with texmath plugin", (t) => { + t.plan(2); markdownlint({ "files": [ "./test/texmath-content-in-lists.md" ], "markdownItPlugins": [ [ pluginTexMath, pluginTexMathOptions ] ] }, function callback(err, actual) { - test.ifError(err); + t.falsy(err); const expected = { "./test/texmath-content-in-lists.md": [] }; - test.deepEqual(actual, expected, "Unexpected issues."); - test.end(); + t.deepEqual(actual, expected, "Unexpected issues."); + t.end(); }); }); -tape("getVersion", (test) => { - test.plan(1); +test("getVersion", (t) => { + t.plan(1); const actual = markdownlint.getVersion(); const expected = version; - test.equal(actual, expected, "Version string not correct."); - test.end(); + t.is(actual, expected, "Version string not correct."); });