mirror of
https://github.com/withastro/astro.git
synced 2024-12-23 21:53:55 -05:00
d4cd7a59fd
* feat: "file" and "url" top-level layout props * test: markdown file and url * test: mdx file and url * feat: update MarkdownInstance + JSDoc improvements * chore: changeset
77 lines
2.7 KiB
JavaScript
77 lines
2.7 KiB
JavaScript
import mdx from '@astrojs/mdx';
|
|
|
|
import { expect } from 'chai';
|
|
import { parseHTML } from 'linkedom';
|
|
import { loadFixture } from '../../../astro/test/test-utils.js';
|
|
|
|
const FIXTURE_ROOT = new URL('./fixtures/mdx-frontmatter/', import.meta.url);
|
|
|
|
describe('MDX frontmatter', () => {
|
|
let fixture;
|
|
before(async () => {
|
|
fixture = await loadFixture({
|
|
root: FIXTURE_ROOT,
|
|
integrations: [mdx()],
|
|
});
|
|
await fixture.build();
|
|
});
|
|
it('builds when "frontmatter.property" is in JSX expression', async () => {
|
|
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');
|
|
});
|
|
|
|
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;
|
|
});
|
|
|
|
it('passes frontmatter to layout via "content" and "frontmatter" props', async () => {
|
|
const html = await fixture.readFile('/index.html');
|
|
const { document } = parseHTML(html);
|
|
|
|
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);
|
|
|
|
const headingSlugs = [...document.querySelectorAll('[data-headings] > li')].map(
|
|
(el) => el.textContent
|
|
);
|
|
|
|
expect(headingSlugs.length).to.be.greaterThan(0);
|
|
expect(headingSlugs).to.contain('section-1');
|
|
expect(headingSlugs).to.contain('section-2');
|
|
});
|
|
|
|
it('passes "file" and "url" to layout', async () => {
|
|
const html = await fixture.readFile('/with-headings/index.html');
|
|
const { document } = parseHTML(html);
|
|
|
|
const frontmatterFile = document.querySelector('[data-frontmatter-file]')?.textContent;
|
|
const frontmatterUrl = document.querySelector('[data-frontmatter-url]')?.textContent;
|
|
const file = document.querySelector('[data-file]')?.textContent;
|
|
const url = document.querySelector('[data-url]')?.textContent;
|
|
|
|
expect(frontmatterFile?.endsWith('with-headings.mdx')).to.equal(
|
|
true,
|
|
'"file" prop does not end with correct path or is undefined'
|
|
);
|
|
expect(frontmatterUrl).to.equal('/with-headings');
|
|
expect(file).to.equal(frontmatterFile);
|
|
expect(url).to.equal(frontmatterUrl);
|
|
});
|
|
});
|