0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00
astro/packages/integrations/mdx/test/mdx-remark-plugins.test.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

63 lines
1.7 KiB
JavaScript
Raw Normal View History

import mdx from '@astrojs/mdx';
import { expect } from 'chai';
import { parseHTML } from 'linkedom';
import { loadFixture } from '../../../astro/test/test-utils.js';
import remarkToc from 'remark-toc';
const FIXTURE_ROOT = new URL('./fixtures/mdx-remark-plugins/', import.meta.url);
describe('MDX remark plugins', () => {
it('supports custom remark plugins - TOC', async () => {
const fixture = await loadFixture({
root: FIXTURE_ROOT,
2022-07-20 13:16:33 -05:00
integrations: [
mdx({
remarkPlugins: [remarkToc],
}),
],
});
await fixture.build();
const html = await fixture.readFile('/with-toc/index.html');
const { document } = parseHTML(html);
const tocLink1 = document.querySelector('ul a[href="#section-1"]');
expect(tocLink1).to.not.be.null;
});
it('applies GitHub-flavored markdown by default', async () => {
const fixture = await loadFixture({
root: FIXTURE_ROOT,
integrations: [mdx()],
});
await fixture.build();
const html = await fixture.readFile('/with-gfm/index.html');
const { document } = parseHTML(html);
const autoGenLink = document.querySelector('a[href="https://example.com"]');
expect(autoGenLink).to.not.be.null;
});
it('preserves default GitHub-flavored markdown with "extends"', async () => {
const fixture = await loadFixture({
root: FIXTURE_ROOT,
2022-07-20 13:16:33 -05:00
integrations: [
mdx({
remarkPlugins: { extends: [remarkToc] },
}),
],
});
await fixture.build();
const html = await fixture.readFile('/with-toc/index.html');
const { document } = parseHTML(html);
const tocLink1 = document.querySelector('ul a[href="#section-1"]');
expect(tocLink1).to.not.be.null;
const autoGenLink = document.querySelector('a[href="https://handle-me-gfm.com"]');
expect(autoGenLink).to.not.be.null;
});
});