diff options
author | 2022-07-20 21:34:21 -0400 | |
---|---|---|
committer | 2022-07-20 21:34:21 -0400 | |
commit | b2b367c969493aaf21c974064beb241d05228066 (patch) | |
tree | 0f1f445ad5d3b98d32af438af405961ff6fe7fd2 /packages/integrations/mdx/test/mdx-frontmatter.js | |
parent | 40a45e3ef6284c024d442cf7cb8e36d8354a35d1 (diff) | |
download | astro-b2b367c969493aaf21c974064beb241d05228066.tar.gz astro-b2b367c969493aaf21c974064beb241d05228066.tar.zst astro-b2b367c969493aaf21c974064beb241d05228066.zip |
[MDX] Support YAML frontmatter (#3995)
* chore: remove old comment
* deps: add remark-frontmatter
* deps: add remark-mdx-frontmatter
* fix: handle null or undefined frontmatter key
* feat: configure frontmatter plugins with defaults
* test: frontmatter and custom frontmatter name
* docs: add frontmatterOptions config
* docs: add "variables" and "frontmatter" docs
* chore: excessible -> accessible
* chore: changeset
* chore: remove bad mdx comment
Diffstat (limited to '')
-rw-r--r-- | packages/integrations/mdx/test/mdx-frontmatter.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/packages/integrations/mdx/test/mdx-frontmatter.js b/packages/integrations/mdx/test/mdx-frontmatter.js new file mode 100644 index 000000000..1d8ec36f6 --- /dev/null +++ b/packages/integrations/mdx/test/mdx-frontmatter.js @@ -0,0 +1,43 @@ +import mdx from '@astrojs/mdx'; + +import { expect } from 'chai'; +import { loadFixture } from '../../../astro/test/test-utils.js'; + +const FIXTURE_ROOT = new URL('./fixtures/mdx-frontmatter/', import.meta.url); + +describe('MDX frontmatter', () => { + it('builds when "frontmatter.property" is in JSX expression', async () => { + const fixture = await loadFixture({ + root: FIXTURE_ROOT, + integrations: [mdx()], + }); + await fixture.build(); + expect(true).to.equal(true); + }); + + it('extracts frontmatter to "frontmatter" export', async () => { + const fixture = await loadFixture({ + root: FIXTURE_ROOT, + integrations: [mdx()], + }); + await fixture.build(); + + const { titles } = JSON.parse(await fixture.readFile('/glob.json')); + expect(titles).to.include('Using YAML frontmatter'); + }); + + it('extracts frontmatter to "customFrontmatter" export when configured', async () => { + const fixture = await loadFixture({ + root: new URL('./fixtures/mdx-custom-frontmatter-name/', import.meta.url), + integrations: [mdx({ + frontmatterOptions: { + name: 'customFrontmatter', + }, + })], + }); + await fixture.build(); + + const { titles } = JSON.parse(await fixture.readFile('/glob.json')); + expect(titles).to.include('Using YAML frontmatter'); + }); +}); |