Skip to content

Commit

Permalink
chore: add exports util with tests (#1045)
Browse files Browse the repository at this point in the history
[![PR App][icn]][demo] | Fix RM-XYZ
:-------------------:|:----------:

## 🧰 Changes
- Adds a util for parsing out the export names from an MDX string 
- Adds tests for a few different cases

## 🧬 QA & Testing

- [Broken on production][prod].
- [Working in this PR app][demo].


[demo]: https://markdown-pr-PR_NUMBER.herokuapp.com
[prod]: https://SUBDOMAIN.readme.io
[icn]:
https://user-images.githubusercontent.com/886627/160426047-1bee9488-305a-4145-bb2b-09d8b757d38a.svg
  • Loading branch information
davinhazard authored Jan 21, 2025
1 parent bf9ed34 commit e5180a4
Show file tree
Hide file tree
Showing 13 changed files with 1,194 additions and 5 deletions.
19 changes: 19 additions & 0 deletions __tests__/lib/exports/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import singleExportMdx from './input/singleExport.mdx?raw';
import multipleExportsMdx from './input/multipleExports.mdx?raw';
import weirdExportsMdx from './input/weirdExports.mdx?raw';
import { exports } from '../../../lib';

describe('export tags', () => {
it('returns a single export name', () => {

expect(exports(singleExportMdx)).toStrictEqual(['Foo']);
});
it('returns multiple export names', () => {

expect(exports(multipleExportsMdx)).toStrictEqual(['Foo', 'Bar']);
});
it('returns different types of export names', () => {

expect(exports(weirdExportsMdx)).toStrictEqual(['Foo', 'bar', 'doSomethingFunction', 'YELLING']);
});
});
12 changes: 12 additions & 0 deletions __tests__/lib/exports/input/multipleExports.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';

export const Foo = () => {
return <div>Hello World</div>;
}

export const Bar = () => {
return <Foo />;
}

## Hey there
<Foo />
8 changes: 8 additions & 0 deletions __tests__/lib/exports/input/singleExport.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';

export const Foo = () => {
return <div>Hello World</div>;
}

## Hey there
<Foo />
19 changes: 19 additions & 0 deletions __tests__/lib/exports/input/weirdExports.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';

export function Foo() {
return <div>Hello World</div>;
}

export const bar = () => {
return <Foo />;
}

export function doSomethingFunction(input) {
return input.trim();
}

export const
YELLING = () => {}

## Hey there
<Foo />
3 changes: 2 additions & 1 deletion __tests__/lib/hast.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hast, hastFromHtml } from '../../lib';
import { hast } from '../../lib';
import { h } from 'hastscript';

describe('hast transformer', () => {
Expand All @@ -19,6 +19,7 @@ describe('hast transformer', () => {
h('h2', { id: 'its-coming-from-within-the-component' }, "It's coming from within the component!"),
);

// @ts-ignore
expect(hast(md, { components })).toStrictEqualExceptPosition(expected);
});
});
Loading

0 comments on commit e5180a4

Please sign in to comment.