2022-07-21 01:34:21 +00:00
|
|
|
import mdx from '@astrojs/mdx';
|
|
|
|
|
|
|
|
import { expect } from 'chai';
|
2022-07-29 15:22:57 +00:00
|
|
|
import { parseHTML } from 'linkedom';
|
2022-07-21 01:34:21 +00:00
|
|
|
import { loadFixture } from '../../../astro/test/test-utils.js';
|
|
|
|
|
|
|
|
const FIXTURE_ROOT = new URL('./fixtures/mdx-frontmatter/', import.meta.url);
|
|
|
|
|
|
|
|
describe('MDX frontmatter', () => {
|
2022-08-03 21:54:55 +00:00
|
|
|
let fixture;
|
|
|
|
before(async () => {
|
|
|
|
fixture = await loadFixture({
|
2022-07-21 01:34:21 +00:00
|
|
|
root: FIXTURE_ROOT,
|
|
|
|
integrations: [mdx()],
|
|
|
|
});
|
|
|
|
await fixture.build();
|
2022-08-03 21:56:30 +00:00
|
|
|
});
|
2022-08-03 21:54:55 +00:00
|
|
|
it('builds when "frontmatter.property" is in JSX expression', async () => {
|
2022-07-21 01:34:21 +00:00
|
|
|
expect(true).to.equal(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('extracts frontmatter to "frontmatter" export', async () => {
|
|
|
|
const { titles } = JSON.parse(await fixture.readFile('/glob.json'));
|
|
|
|
expect(titles).to.include('Using YAML frontmatter');
|
|
|
|
});
|
|
|
|
|
2022-07-29 15:22:57 +00:00
|
|
|
it('renders layout from "layout" frontmatter property', async () => {
|
|
|
|
const html = await fixture.readFile('/index.html');
|
|
|
|
const { document } = parseHTML(html);
|
|
|
|
|
|
|
|
const layoutParagraph = document.querySelector('[data-layout-rendered]');
|
|
|
|
|
|
|
|
expect(layoutParagraph).to.not.be.null;
|
|
|
|
});
|
|
|
|
|
2022-08-03 21:54:55 +00:00
|
|
|
it('passes frontmatter to layout via "content" and "frontmatter" props', async () => {
|
2022-07-29 15:22:57 +00:00
|
|
|
const html = await fixture.readFile('/index.html');
|
|
|
|
const { document } = parseHTML(html);
|
|
|
|
|
2022-08-03 21:54:55 +00:00
|
|
|
const contentTitle = document.querySelector('[data-content-title]');
|
|
|
|
const frontmatterTitle = document.querySelector('[data-frontmatter-title]');
|
|
|
|
|
|
|
|
expect(contentTitle.textContent).to.equal('Using YAML frontmatter');
|
|
|
|
expect(frontmatterTitle.textContent).to.equal('Using YAML frontmatter');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('passes headings to layout via "headings" prop', async () => {
|
|
|
|
const html = await fixture.readFile('/with-headings/index.html');
|
|
|
|
const { document } = parseHTML(html);
|
|
|
|
|
2022-08-03 21:56:30 +00:00
|
|
|
const headingSlugs = [...document.querySelectorAll('[data-headings] > li')].map(
|
|
|
|
(el) => el.textContent
|
|
|
|
);
|
2022-07-29 15:22:57 +00:00
|
|
|
|
2022-08-03 21:54:55 +00:00
|
|
|
expect(headingSlugs.length).to.be.greaterThan(0);
|
|
|
|
expect(headingSlugs).to.contain('section-1');
|
|
|
|
expect(headingSlugs).to.contain('section-2');
|
2022-07-29 15:22:57 +00:00
|
|
|
});
|
2022-07-21 01:34:21 +00:00
|
|
|
});
|