diff --git a/test/customRules-pre-imported/.markdownlint-cli2.cjs b/test/customRules-pre-imported/.markdownlint-cli2.cjs index 98fa5da8..5ba88bee 100644 --- a/test/customRules-pre-imported/.markdownlint-cli2.cjs +++ b/test/customRules-pre-imported/.markdownlint-cli2.cjs @@ -2,7 +2,7 @@ "use strict"; -const anyBlockquote = require("./rules/any-blockquote.js"); +const anyBlockquote = require("./rules/any-blockquote.cjs"); module.exports = { "customRules": [ diff --git a/test/customRules-pre-imported/rules/any-blockquote.js b/test/customRules-pre-imported/rules/any-blockquote.cjs similarity index 100% rename from test/customRules-pre-imported/rules/any-blockquote.js rename to test/customRules-pre-imported/rules/any-blockquote.cjs diff --git a/test/customRules-throws/.markdownlint-cli2.jsonc b/test/customRules-throws/.markdownlint-cli2.jsonc index 59e833f9..5d41a132 100644 --- a/test/customRules-throws/.markdownlint-cli2.jsonc +++ b/test/customRules-throws/.markdownlint-cli2.jsonc @@ -1,5 +1,5 @@ { "customRules": [ - "./rules/throws.js" + "./rules/throws.cjs" ] } diff --git a/test/customRules-throws/rules/throws.js b/test/customRules-throws/rules/throws.cjs similarity index 100% rename from test/customRules-throws/rules/throws.js rename to test/customRules-throws/rules/throws.cjs diff --git a/test/customRules/.markdownlint-cli2.jsonc b/test/customRules/.markdownlint-cli2.jsonc index 1350bd58..599aee08 100644 --- a/test/customRules/.markdownlint-cli2.jsonc +++ b/test/customRules/.markdownlint-cli2.jsonc @@ -1,8 +1,8 @@ { "customRules": [ - "./rules/any-blockquote.js", - "./rules/every-n-lines.js", - "./rules/first-line.js" + "./rules/any-blockquote.cjs", + "./rules/every-n-lines.cjs", + "./rules/first-line.cjs" ], "config": { "every-n-lines": { diff --git a/test/customRules/dir/subdir/.markdownlint-cli2.jsonc b/test/customRules/dir/subdir/.markdownlint-cli2.jsonc index ab641367..66c3cb4b 100644 --- a/test/customRules/dir/subdir/.markdownlint-cli2.jsonc +++ b/test/customRules/dir/subdir/.markdownlint-cli2.jsonc @@ -1,6 +1,6 @@ { "customRules": [ - "../../rules/first-line.js", + "../../rules/first-line.cjs", "../../node_modules/markdownlint-rule-sample-commonjs", "../../node_modules/markdownlint-rule-sample-module/sample-rule.mjs", "markdownlint-rule-extended-ascii" diff --git a/test/customRules/dir3/.markdownlint-cli2.jsonc b/test/customRules/dir3/.markdownlint-cli2.jsonc index 0fed617e..e9a71c6c 100644 --- a/test/customRules/dir3/.markdownlint-cli2.jsonc +++ b/test/customRules/dir3/.markdownlint-cli2.jsonc @@ -1,6 +1,6 @@ { "customRules": [ - "../rules/all-rules", + "../rules/all-rules.cjs", "../node_modules/markdownlint-rule-sample-commonjs", "../node_modules/markdownlint-rule-sample-module/sample-rule.mjs" ] diff --git a/test/customRules/rules/all-rules.cjs b/test/customRules/rules/all-rules.cjs new file mode 100644 index 00000000..b333a173 --- /dev/null +++ b/test/customRules/rules/all-rules.cjs @@ -0,0 +1,10 @@ +// @ts-check + +"use strict"; + +module.exports = [ + require("./any-blockquote.cjs"), + require("./every-n-lines.cjs"), + require("./first-line.cjs"), + require("./second-line.cjs") +]; diff --git a/test/customRules/rules/all-rules.js b/test/customRules/rules/all-rules.js deleted file mode 100644 index 32817133..00000000 --- a/test/customRules/rules/all-rules.js +++ /dev/null @@ -1,10 +0,0 @@ -// @ts-check - -"use strict"; - -module.exports = [ - require("./any-blockquote"), - require("./every-n-lines"), - require("./first-line"), - require("./second-line") -]; diff --git a/test/customRules/rules/any-blockquote.js b/test/customRules/rules/any-blockquote.cjs similarity index 100% rename from test/customRules/rules/any-blockquote.js rename to test/customRules/rules/any-blockquote.cjs diff --git a/test/customRules/rules/every-n-lines.js b/test/customRules/rules/every-n-lines.cjs similarity index 100% rename from test/customRules/rules/every-n-lines.js rename to test/customRules/rules/every-n-lines.cjs diff --git a/test/customRules/rules/second-line.js b/test/customRules/rules/second-line.cjs similarity index 100% rename from test/customRules/rules/second-line.js rename to test/customRules/rules/second-line.cjs diff --git a/test/import-with-type-json.mjs b/test/import-with-type-json.mjs new file mode 100644 index 00000000..7b2cc924 --- /dev/null +++ b/test/import-with-type-json.mjs @@ -0,0 +1,7 @@ +// @ts-check + +import fs from "node:fs/promises"; +import path from "node:path"; + +// Avoids "ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time" +export default async (file) => JSON.parse(await fs.readFile(path.resolve(import.meta.dirname, file), "utf8")); diff --git a/test/markdownlint-cli2-test-cases.js b/test/markdownlint-cli2-test-cases.js index 11fdfad6..b4c34534 100644 --- a/test/markdownlint-cli2-test-cases.js +++ b/test/markdownlint-cli2-test-cases.js @@ -1,11 +1,9 @@ // @ts-check -"use strict"; - -const fs = require("node:fs").promises; -const os = require("node:os"); -const path = require("node:path"); -const test = require("ava").default; +import fs from "node:fs/promises"; +import os from "node:os"; +import path from "node:path"; +import test from "ava"; const noop = () => null; const empty = () => ""; @@ -13,7 +11,7 @@ const sanitize = (str) => str. replace(/\r/gu, ""). replace(/\bv\d+\.\d+\.\d+\b/gu, "vX.Y.Z"). replace(/ :.+[/\\]sentinel/gu, " :[PATH]"); -const sameFileSystem = (path.relative(os.homedir(), __dirname) !== __dirname); +const sameFileSystem = (path.relative(os.homedir(), import.meta.dirname) !== import.meta.dirname); const isModule = (file) => file.endsWith(".cjs") || file.endsWith(".mjs"); const testCases = ({ @@ -57,7 +55,7 @@ const testCases = ({ } test(`${name} (${host})`, (t) => { t.plan(3); - const directory = path.join(__dirname, cwd || name); + const directory = path.join(import.meta.dirname, cwd || name); return ((pre || noop)(name, shadow) || Promise.resolve()). then(invoke(directory, args, noRequire, env, script)). then((result) => Promise.all([ @@ -143,13 +141,13 @@ const testCases = ({ const copyDirectory = (dir, alt) => import("cpy").then((cpy) => ( cpy.default( - path.join(__dirname, (alt || dir), "**"), - path.join(__dirname, directoryName(dir)) + path.join(import.meta.dirname, (alt || dir), "**"), + path.join(import.meta.dirname, directoryName(dir)) ) )); const deleteDirectory = (dir) => import("del").then((del) => ( - del.deleteAsync(path.join(__dirname, directoryName(dir))) + del.deleteAsync(path.join(import.meta.dirname, directoryName(dir))) )); testCase({ @@ -588,7 +586,7 @@ const testCases = ({ }); const literalFilesAbsoluteFile = absolute( - path.join(__dirname, "literal-files"), + path.join(import.meta.dirname, "literal-files"), "sentinel/dir(1)/(view)me.md" ). split(path.sep). @@ -670,7 +668,7 @@ const testCases = ({ "name": `config-files-${configFile}-absolute-arg`, "args": [ "--config", - path.join(__dirname, "config-files", `cfg/${configFile}`), + path.join(import.meta.dirname, "config-files", `cfg/${configFile}`), "**/*.md" ], "exitCode": 1, @@ -1161,4 +1159,4 @@ const testCases = ({ }; -module.exports = testCases; +export default testCases; diff --git a/test/markdownlint-cli2-test-exec.js b/test/markdownlint-cli2-test-exec.js index 394262f5..c1671ba3 100644 --- a/test/markdownlint-cli2-test-exec.js +++ b/test/markdownlint-cli2-test-exec.js @@ -1,14 +1,12 @@ // @ts-check -"use strict"; - -const fs = require("node:fs/promises"); -const path = require("node:path"); -const test = require("ava").default; -const testCases = require("./markdownlint-cli2-test-cases"); +import fs from "node:fs/promises"; +import path from "node:path"; +import test from "ava"; +import testCases from "./markdownlint-cli2-test-cases.js"; const absolute = (rootDir, file) => path.join(rootDir, file); -const repositoryPath = (name) => path.join(__dirname, "..", name); +const repositoryPath = (name) => path.join(import.meta.dirname, "..", name); const invoke = (directory, args, noRequire, env, script) => async () => { await fs.access(directory); @@ -160,7 +158,7 @@ test("- parameter uses base directory configuration", (t) => { return invokeStdin( [ "-" ], invalidInput, - path.join(__dirname, "stdin") + path.join(import.meta.dirname, "stdin") ). then(() => t.fail()). catch((error) => { @@ -174,7 +172,7 @@ test("- parameter not treated as stdin in configuration file globs", (t) => { return invokeStdin( [], invalidInput, - path.join(__dirname, "stdin-globs") + path.join(import.meta.dirname, "stdin-globs") ). then(() => t.pass()). catch(() => t.fail()); diff --git a/test/markdownlint-cli2-test-exports.js b/test/markdownlint-cli2-test-exports.js index 7fd6b0bc..84f948f6 100644 --- a/test/markdownlint-cli2-test-exports.js +++ b/test/markdownlint-cli2-test-exports.js @@ -1,7 +1,8 @@ // @ts-check import test from "ava"; -import packageJson from "../package.json" with { type: "json" }; +import importWithTypeJson from "./import-with-type-json.mjs"; +const packageJson = await importWithTypeJson("../package.json"); import { createRequire } from "node:module"; const require = createRequire(import.meta.url); diff --git a/test/markdownlint-cli2-test-fs.js b/test/markdownlint-cli2-test-fs.js index d2b703af..35bc42eb 100644 --- a/test/markdownlint-cli2-test-fs.js +++ b/test/markdownlint-cli2-test-fs.js @@ -1,11 +1,9 @@ // @ts-check -"use strict"; - -const path = require("node:path"); -const { "main": markdownlintCli2 } = require("../markdownlint-cli2.js"); -const testCases = require("./markdownlint-cli2-test-cases"); -const FsMock = require("./fs-mock"); +import path from "node:path"; +import { "main" as markdownlintCli2 } from "../markdownlint-cli2.js"; +import testCases from "./markdownlint-cli2-test-cases.js"; +import FsMock from "./fs-mock.js"; const mockDirectory = "/mock"; const linesEndingWithNewLine = diff --git a/test/markdownlint-cli2-test-main.js b/test/markdownlint-cli2-test-main.js index 80e61ca7..cbe93e84 100644 --- a/test/markdownlint-cli2-test-main.js +++ b/test/markdownlint-cli2-test-main.js @@ -1,10 +1,8 @@ // @ts-check -"use strict"; - -const path = require("node:path"); -const { "main": markdownlintCli2 } = require("../markdownlint-cli2.js"); -const testCases = require("./markdownlint-cli2-test-cases"); +import path from "node:path"; +import { "main" as markdownlintCli2 } from "../markdownlint-cli2.js"; +import testCases from "./markdownlint-cli2-test-cases.js"; const linesEndingWithNewLine = (lines) => lines.map((line) => `${line}\n`).join(""); diff --git a/test/markdownlint-cli2-test.js b/test/markdownlint-cli2-test.js index fda92323..bb068e5c 100644 --- a/test/markdownlint-cli2-test.js +++ b/test/markdownlint-cli2-test.js @@ -1,14 +1,13 @@ // @ts-check -"use strict"; - import nodeFs from "node:fs"; import fs from "node:fs/promises"; import path from "node:path"; import Ajv from "ajv"; import test from "ava"; import { globby } from "globby"; -import packageJson from "../package.json" with { type: "json" }; +import importWithTypeJson from "./import-with-type-json.mjs"; +const packageJson = await importWithTypeJson("../package.json"); import { "main" as markdownlintCli2 } from "../markdownlint-cli2.js"; import jsoncParse from "../parsers/jsonc-parse.js"; import yamlParse from "../parsers/yaml-parse.js"; @@ -17,8 +16,8 @@ import FsVirtual from "../webworker/fs-virtual.js"; import firstLine from "./customRules/rules/first-line.cjs"; const schemaIdVersionRe = /^.*v(?\d+\.\d+\.\d+).*$/u; -import markdownlintConfigSchemaDefinition from "../schema/markdownlint-config-schema.json" with { type: "json" }; -import markdownlintCli2ConfigSchemaDefinition from "../schema/markdownlint-cli2-config-schema.json" with { type: "json" }; +const markdownlintConfigSchemaDefinition = await importWithTypeJson("../schema/markdownlint-config-schema.json"); +const markdownlintCli2ConfigSchemaDefinition = await importWithTypeJson("../schema/markdownlint-cli2-config-schema.json"); const outputFormatterLengthIs = (t, length) => (options) => { const { results } = options; diff --git a/test/nested-options-config/config-options-disjoint-empty/dir/dir/.markdownlint-cli2.jsonc b/test/nested-options-config/config-options-disjoint-empty/dir/dir/.markdownlint-cli2.jsonc index 3b0219dc..9f3778dd 100644 --- a/test/nested-options-config/config-options-disjoint-empty/dir/dir/.markdownlint-cli2.jsonc +++ b/test/nested-options-config/config-options-disjoint-empty/dir/dir/.markdownlint-cli2.jsonc @@ -1,5 +1,5 @@ { "customRules": [ - "../../../first-line.js" + "../../../first-line.cjs" ] } diff --git a/test/nested-options-config/config-options-disjoint/dir/dir/.markdownlint-cli2.jsonc b/test/nested-options-config/config-options-disjoint/dir/dir/.markdownlint-cli2.jsonc index 3b0219dc..9f3778dd 100644 --- a/test/nested-options-config/config-options-disjoint/dir/dir/.markdownlint-cli2.jsonc +++ b/test/nested-options-config/config-options-disjoint/dir/dir/.markdownlint-cli2.jsonc @@ -1,5 +1,5 @@ { "customRules": [ - "../../../first-line.js" + "../../../first-line.cjs" ] } diff --git a/test/nested-options-config/config-options-overlap-empty/dir/dir/.markdownlint-cli2.jsonc b/test/nested-options-config/config-options-overlap-empty/dir/dir/.markdownlint-cli2.jsonc index 4569433e..c8e78b72 100644 --- a/test/nested-options-config/config-options-overlap-empty/dir/dir/.markdownlint-cli2.jsonc +++ b/test/nested-options-config/config-options-overlap-empty/dir/dir/.markdownlint-cli2.jsonc @@ -1,6 +1,6 @@ { "customRules": [ - "../../../first-line.js" + "../../../first-line.cjs" ], "config": { "no-space-in-code": false diff --git a/test/nested-options-config/config-options-overlap/dir/dir/.markdownlint-cli2.jsonc b/test/nested-options-config/config-options-overlap/dir/dir/.markdownlint-cli2.jsonc index 4569433e..c8e78b72 100644 --- a/test/nested-options-config/config-options-overlap/dir/dir/.markdownlint-cli2.jsonc +++ b/test/nested-options-config/config-options-overlap/dir/dir/.markdownlint-cli2.jsonc @@ -1,6 +1,6 @@ { "customRules": [ - "../../../first-line.js" + "../../../first-line.cjs" ], "config": { "no-space-in-code": false diff --git a/test/nested-options-config/first-line.js b/test/nested-options-config/first-line.cjs similarity index 100% rename from test/nested-options-config/first-line.js rename to test/nested-options-config/first-line.cjs diff --git a/test/nested-options-config/options-config-disjoint-empty/.markdownlint-cli2.jsonc b/test/nested-options-config/options-config-disjoint-empty/.markdownlint-cli2.jsonc index 37174581..07bd66bb 100644 --- a/test/nested-options-config/options-config-disjoint-empty/.markdownlint-cli2.jsonc +++ b/test/nested-options-config/options-config-disjoint-empty/.markdownlint-cli2.jsonc @@ -1,5 +1,5 @@ { "customRules": [ - "../first-line.js" + "../first-line.cjs" ] } diff --git a/test/nested-options-config/options-config-disjoint/.markdownlint-cli2.jsonc b/test/nested-options-config/options-config-disjoint/.markdownlint-cli2.jsonc index 37174581..07bd66bb 100644 --- a/test/nested-options-config/options-config-disjoint/.markdownlint-cli2.jsonc +++ b/test/nested-options-config/options-config-disjoint/.markdownlint-cli2.jsonc @@ -1,5 +1,5 @@ { "customRules": [ - "../first-line.js" + "../first-line.cjs" ] } diff --git a/test/nested-options-config/options-config-overlap-empty/.markdownlint-cli2.jsonc b/test/nested-options-config/options-config-overlap-empty/.markdownlint-cli2.jsonc index 8c0936d0..ee852567 100644 --- a/test/nested-options-config/options-config-overlap-empty/.markdownlint-cli2.jsonc +++ b/test/nested-options-config/options-config-overlap-empty/.markdownlint-cli2.jsonc @@ -1,6 +1,6 @@ { "customRules": [ - "../first-line.js" + "../first-line.cjs" ], "config": { "no-space-in-code": false diff --git a/test/nested-options-config/options-config-overlap/.markdownlint-cli2.jsonc b/test/nested-options-config/options-config-overlap/.markdownlint-cli2.jsonc index 8c0936d0..ee852567 100644 --- a/test/nested-options-config/options-config-overlap/.markdownlint-cli2.jsonc +++ b/test/nested-options-config/options-config-overlap/.markdownlint-cli2.jsonc @@ -1,6 +1,6 @@ { "customRules": [ - "../first-line.js" + "../first-line.cjs" ], "config": { "no-space-in-code": false