Add test to verify exported names are stable, add missing test files after earlier refactor.

This commit is contained in:
David Anson 2025-03-06 20:24:20 -08:00
parent d4a638101a
commit 5cc88a7759
6 changed files with 137 additions and 9 deletions

View file

@ -19,7 +19,7 @@ const exportMappings = new Map([
[ "./style/relaxed", "../style/relaxed.json" ]
]);
test("exportMappings", (t) => {
test("exportMappings table", (t) => {
t.deepEqual(
Object.keys(packageJson.exports),
[ ...exportMappings.keys() ]
@ -31,9 +31,10 @@ const jsonRe = /\.json$/u;
// const importOptionsJson = { "with": { "type": "json" } };
for (const [ exportName, exportPath ] of exportMappings) {
test(exportName, async(t) => {
const exportByName = exportName.replace(/^\./u, packageJson.name);
test(`export mapping for ${exportByName}`, async(t) => {
t.plan(1);
const json = jsonRe.test(exportPath);
const exportByName = exportName.replace(/^\./u, packageJson.name);
const importExportByName = json ?
require(exportByName) :
await import(exportByName);
@ -44,7 +45,22 @@ for (const [ exportName, exportPath ] of exportMappings) {
});
}
test("subpathImports", async(t) => {
test(`exported names`, async(t) => {
t.plan(1);
const exportedNames = {};
for (const [ exportName, exportPath ] of exportMappings) {
const exportByName = exportName.replace(/^\./u, packageJson.name);
const json = jsonRe.test(exportPath);
const importExportByName = json ?
require(exportByName) :
// eslint-disable-next-line no-await-in-loop
await import(exportByName);
exportedNames[exportByName] = Object.keys(importExportByName);
}
t.snapshot(exportedNames);
});
test("subpathImports and conditions", async(t) => {
t.plan(8);
const scenarios = [
{ "conditions": "browser", "throws": true },

View file

@ -17,7 +17,7 @@ const files = await globby(projectFiles);
test("projectFiles", (t) => {
t.plan(2);
t.is(files.length, 60);
t.is(files.length, 61);
const options = {
files,
"config": require("../.markdownlint.json")
@ -40,7 +40,7 @@ test("projectFilesExtendedAscii", (t) => {
"doc/md036.md"
]);
const filteredFiles = files.filter((file) => !ignoreFiles.has(file));
t.is(filteredFiles.length, 56);
t.is(filteredFiles.length, 57);
const options = {
"files": filteredFiles,
"config": require("../.markdownlint.json"),

View file

@ -0,0 +1,113 @@
# Snapshot report for `test/markdownlint-test-exports.mjs`
The actual snapshot is saved in `markdownlint-test-exports.mjs.snap`.
Generated by [AVA](https://avajs.dev).
## exported names
> Snapshot 1
{
markdownlint: [
'applyFix',
'applyFixes',
'getVersion',
'resolveModule',
],
'markdownlint/async': [
'lint',
'readConfig',
],
'markdownlint/helpers': [
'addError',
'addErrorContext',
'addErrorDetailIf',
'allPunctuation',
'allPunctuationNoQuestion',
'clearHtmlCommentText',
'cloneIfArray',
'cloneIfUrl',
'default',
'ellipsify',
'endOfLineGemojiCodeRe',
'endOfLineHtmlEntityRe',
'escapeForRegExp',
'expandTildePath',
'frontMatterHasTitle',
'frontMatterRe',
'getHtmlAttributeRe',
'getPreferredLineEnding',
'getReferenceLinkImageData',
'hasOverlap',
'inlineCommentStartRe',
'isBlankLine',
'isEmptyString',
'isNumber',
'isObject',
'isString',
'isUrl',
'newLineRe',
'nextLinesRe',
],
'markdownlint/promise': [
'extendConfig',
'lint',
'readConfig',
],
'markdownlint/style/all': [
'comment',
'default',
],
'markdownlint/style/cirosantilli': [
'comment',
'default',
'MD003',
'MD004',
'MD007',
'MD030',
'MD033',
'MD035',
],
'markdownlint/style/prettier': [
'comment',
'blanks-around-fences',
'blanks-around-headings',
'blanks-around-lists',
'code-fence-style',
'emphasis-style',
'heading-start-left',
'heading-style',
'hr-style',
'line-length',
'list-indent',
'list-marker-space',
'no-blanks-blockquote',
'no-hard-tabs',
'no-missing-space-atx',
'no-missing-space-closed-atx',
'no-multiple-blanks',
'no-multiple-space-atx',
'no-multiple-space-blockquote',
'no-multiple-space-closed-atx',
'no-trailing-spaces',
'ol-prefix',
'strong-style',
'ul-indent',
],
'markdownlint/style/relaxed': [
'comment',
'default',
'whitespace',
'line_length',
'ul-indent',
'no-inline-html',
'no-bare-urls',
'fenced-code-language',
'first-line-h1',
],
'markdownlint/sync': [
'lint',
'readConfig',
],
}

Binary file not shown.