bitttttten / jest-transformer-mdx

A jest transformer for MDX with frontMatter support
12 stars 6 forks source link

Add support for frontMatterName option #9

Closed ccesare closed 4 years ago

ccesare commented 4 years ago

As mentioned in #8, this PR adds support for a frontMatterName option that specifies the name of the parsed frontmatter object.

bitttttten commented 4 years ago

Nice! So there is a regression with this change if you don't provide any options, but it's an easy fix which I just patched :) It's no biggie, but if you don't provide any options, config inside of createTransformer gets set to undefined. The regex matches, but there are no options, so config.transform[i][2] is equal to undefined, then undefined will be passed to parseFrontMatter and it'll fail on the destructing of options to get the frontMatterName.

function parseFrontMatter(src, options = {}) {
   ..
}

I also updated the docs and added a test for this use case, although I can't seem to update this PR so I'll open a new one.

I released it under "2.2.0-beta" too :) See https://github.com/bitttttten/jest-transformer-mdx/pull/10 for more.

ccesare commented 4 years ago

Oh, duh! Thanks for catching that.

I'll check out the new release to make sure it works on my end and then close this PR. Thanks for integrating this feature do quickly.

bitttttten commented 4 years ago

Nice, let me know how you get on! The tests pass so 👍

I like how this solution can also expand to solving other use cases too, nice implementation!