Skip to content

chore: mdxish cleanup#1353

Open
maximilianfalco wants to merge 14 commits intonextfrom
falco/mdxish-cleanup
Open

chore: mdxish cleanup#1353
maximilianfalco wants to merge 14 commits intonextfrom
falco/mdxish-cleanup

Conversation

@maximilianfalco
Copy link
Contributor

@maximilianfalco maximilianfalco commented Feb 23, 2026

PR App Fix RM-XYZ

🧰 Changes

DRY-ing and cleaning up tests files for mdxish

Note

This is a step 1 of a bigger attempt at cleaning up everything in the test suites.

New test file structure

__tests__/
├── helpers.ts                                      ← +findElementByTagName, findElementsByTagName,
│                                                      stubModule, makeComponents
├── lib/
│   ├── gemoji.test.ts                              ← moved here (not mdxish)
│   └── mdxish/
│       ├── components.test.ts
│       ├── legacy-variables.test.ts
│       ├── magic-blocks.test.ts
│       ├── mdx-expressions.test.ts
│       ├── mdxish-ast-processor.test.ts            ← renamed from camelCase
│       ├── mdxish-jsx-to-mdast.test.ts
│       ├── mdxish-mdast-to-md.test.ts              ← renamed from camelCase
│       ├── mdxish-snake-case.test.ts
│       ├── mdxish-tags.test.ts                     ← moved in + renamed from camelCase
│       ├── mdxish.test.ts
│       ├── tailwind.test.ts
│       ├── variables-code.test.ts
│       ├── perf/
│       │   └── magic-block-table-perf.test.ts
│       └── utils/
│           └── protect-code-blocks.test.ts
├── transformers/
│   ├── callouts.test.ts
│   ├── code-tabs.test.ts
│   ├── embeds.test.ts
│   ├── images.test.ts
│   ├── readme-components.test.ts
│   ├── readme-to-mdx.test.ts
│   ├── variables.test.tsx
│   └── mdxish/                                     ← new subdir
│       ├── evaluate-expressions.test.ts
│       ├── mdxish-component-blocks.test.ts
│       ├── mdxish-heading-slugs.test.ts
│       ├── normalize-malformed-md-syntax.test.ts
│       ├── normalize-table-separator.test.ts
│       ├── preprocess-jsx-expressions.test.ts
│       ├── preprocess-redos-attack.test.ts
│       └── terminate-html-flow-blocks.test.ts
└── processor/plugin/
    └── mdxish-components.test.ts

🧬 QA & Testing

Copy link
Contributor

@Jadenzzz Jadenzzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! looks much more organized

Comment on lines +10 to +41
/** Recursively searches a hast tree and returns the first element matching the given tag name. */
export function findElementByTagName(node: Root | RootContent, tagName: string): Element | null {
if ('type' in node && node.type === 'element' && 'tagName' in node && node.tagName === tagName) {
return node;
}

if ('children' in node && Array.isArray(node.children)) {
return node.children.reduce<Element | null>((found, child) => {
if (found) return found;
return findElementByTagName(child, tagName);
}, null);
}

return null;
}

/** Recursively searches a hast tree and returns all elements matching the given tag name. */
export function findElementsByTagName(node: Root | RootContent, tagName: string): Element[] {
const results: Element[] = [];

if ('type' in node && node.type === 'element' && 'tagName' in node && node.tagName === tagName) {
results.push(node);
}

if ('children' in node && Array.isArray(node.children)) {
node.children.forEach(child => {
results.push(...findElementsByTagName(child, tagName));
});
}

return results;
}
Copy link
Contributor

@kevinports kevinports Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ty for moving these into shared helpers, cleans up so much repetetive code!

default: () => null,
Toc: null,
toc: [],
} as unknown as RMDXModule;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor detail but is it possible to avoid casting with an assertion here?

Suggested change
} as unknown as RMDXModule;
} satisfies RMDXModule;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay yea this makes sense but requires us to change this

default: () => null as unknown as React.JSX.Element,

basically adding the as unknown as above it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appreciate normalizing the casing here. But are the mdxish- prefixes now necessary for files inside the mdxish/ directory? So files now follow a <feature>.test.ts pattern but some have the prefix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it should be fine as is since they are already in an mdxish subdir, do you reckon we need the prefix?

@eaglethrost eaglethrost self-requested a review March 2, 2026 03:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants