Skip to content

Commit

Permalink
better unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Jan 18, 2024
1 parent bfea370 commit 604febd
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 18 deletions.

This file was deleted.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -220,20 +220,109 @@ export const c = 1;
`;
exports[`toc remark plugin works with imported markdown 1`] = `
"import Partial, {toc as __toc0} from './_partial.md';
"import Partial, {toc as __toc0} from './_partial1.md';
import SomeComponent from './SomeComponent';
# Index
Some text
import Partial2, {toc as __toc1} from './_partial2.md';
## Index section 1
Foo
<Partial />
Some text
<SomeComponent />
## Index section 2
<Partial2 />
## Unused partials
Unused partials (that are only imported but not rendered) shouldn't alter the TOC
import UnusedPartialImport, {toc as __toc2} from './_partial3.md';
## NonExisting Partials
Partials that do not exist should alter the TOC
It's not the responsibility of the Remark plugin to check for their existance
import DoesNotExist, {toc as __toc3} from './_doesNotExist.md';
export const toc = [{
"value": "Thanos",
"id": "thanos",
"value": "Index section 1",
"id": "index-section-1",
"level": 2
}, ...__toc0];
}, ...__toc0, {
"value": "Index section 2",
"id": "index-section-2",
"level": 2
}, ...__toc1, {
"value": "Unused partials",
"id": "unused-partials",
"level": 2
}, {
"value": "NonExisting Partials",
"id": "nonexisting-partials",
"level": 2
}, ...__toc3, {
"value": "Duplicate partials",
"id": "duplicate-partials",
"level": 2
}, ...__toc0, ...__toc0];
## Thanos
<DoesNotExist />
Foo
## Duplicate partials
It's fine if we use partials at the end
<Partial />
And we can use the partial multiple times!
<Partial />
"
`;
exports[`toc remark plugin works with partials importing other partials 1`] = `
"## Partial 2
Partial 2
### Partial 2 Sub Heading
Content
import Partial2Nested, {toc as __toc0} from './partial2-nested.md';
export const toc = [{
"value": "Partial 2",
"id": "partial-2",
"level": 2
}, {
"value": "Partial 2 Sub Heading",
"id": "partial-2-sub-heading",
"level": 3
}, ...__toc0];
<Partial2Nested />
"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ const processFixture = async (name: string) => {
const {default: gfm} = await import('remark-gfm');
const {default: mdx} = await import('remark-mdx');

const filePath = path.join(__dirname, '__fixtures__', `${name}.md`);
const filePath = path.join(
__dirname,
'__fixtures__',
name.endsWith('.mdx') ? name : `${name}.md`,
);

const file = await vfile.read(filePath);
const result = await remark()
.use(headings)
Expand Down Expand Up @@ -90,7 +95,12 @@ describe('toc remark plugin', () => {
});

it('works with imported markdown', async () => {
const result = await processFixture('imported-markdown');
const result = await processFixture('partials/index.mdx');
expect(result).toMatchSnapshot();
});

it('works with partials importing other partials', async () => {
const result = await processFixture('partials/_partial2.mdx');
expect(result).toMatchSnapshot();
});
});

0 comments on commit 604febd

Please sign in to comment.