Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAnson committed Nov 21, 2024
1 parent 6df9c4e commit a41ba34
Show file tree
Hide file tree
Showing 28 changed files with 64 additions and 65 deletions.
2 changes: 1 addition & 1 deletion test/customRules-pre-imported/.markdownlint-cli2.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

"use strict";

const anyBlockquote = require("./rules/any-blockquote.js");
const anyBlockquote = require("./rules/any-blockquote.cjs");

module.exports = {
"customRules": [
Expand Down
2 changes: 1 addition & 1 deletion test/customRules-throws/.markdownlint-cli2.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"customRules": [
"./rules/throws.js"
"./rules/throws.cjs"
]
}
File renamed without changes.
6 changes: 3 additions & 3 deletions test/customRules/.markdownlint-cli2.jsonc
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion test/customRules/dir/subdir/.markdownlint-cli2.jsonc
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion test/customRules/dir3/.markdownlint-cli2.jsonc
Original file line number Diff line number Diff line change
@@ -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"
]
Expand Down
10 changes: 10 additions & 0 deletions test/customRules/rules/all-rules.cjs
Original file line number Diff line number Diff line change
@@ -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")
];
10 changes: 0 additions & 10 deletions test/customRules/rules/all-rules.js

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions test/import-with-type-json.mjs
Original file line number Diff line number Diff line change
@@ -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"));
26 changes: 12 additions & 14 deletions test/markdownlint-cli2-test-cases.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
// @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 = () => "";
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 = ({
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1161,4 +1159,4 @@ const testCases = ({

};

module.exports = testCases;
export default testCases;
16 changes: 7 additions & 9 deletions test/markdownlint-cli2-test-exec.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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) => {
Expand All @@ -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());
Expand Down
3 changes: 2 additions & 1 deletion test/markdownlint-cli2-test-exports.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
10 changes: 4 additions & 6 deletions test/markdownlint-cli2-test-fs.js
Original file line number Diff line number Diff line change
@@ -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 =
Expand Down
8 changes: 3 additions & 5 deletions test/markdownlint-cli2-test-main.js
Original file line number Diff line number Diff line change
@@ -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("");
Expand Down
9 changes: 4 additions & 5 deletions test/markdownlint-cli2-test.js
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -17,8 +16,8 @@ import FsVirtual from "../webworker/fs-virtual.js";
import firstLine from "./customRules/rules/first-line.cjs";

const schemaIdVersionRe = /^.*v(?<version>\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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"customRules": [
"../../../first-line.js"
"../../../first-line.cjs"
]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"customRules": [
"../../../first-line.js"
"../../../first-line.cjs"
]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"customRules": [
"../../../first-line.js"
"../../../first-line.cjs"
],
"config": {
"no-space-in-code": false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"customRules": [
"../../../first-line.js"
"../../../first-line.cjs"
],
"config": {
"no-space-in-code": false
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"customRules": [
"../first-line.js"
"../first-line.cjs"
]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"customRules": [
"../first-line.js"
"../first-line.cjs"
]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"customRules": [
"../first-line.js"
"../first-line.cjs"
],
"config": {
"no-space-in-code": false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"customRules": [
"../first-line.js"
"../first-line.cjs"
],
"config": {
"no-space-in-code": false
Expand Down

0 comments on commit a41ba34

Please sign in to comment.