summaryrefslogtreecommitdiff
path: root/packages/integrations/mdx/test/mdx-rehype-plugins.test.js
diff options
context:
space:
mode:
authorGravatar Ben Holmes <hey@bholmes.dev> 2022-08-30 13:38:35 -0400
committerGravatar GitHub <noreply@github.com> 2022-08-30 13:38:35 -0400
commit8f8dff4d339a3a12ee155d81a97132032ef3b622 (patch)
tree0581df292a1003288b0dbd7a3f9246f25b5a3cce /packages/integrations/mdx/test/mdx-rehype-plugins.test.js
parente905784bf12ef45093078404d3d07f01e32638ca (diff)
downloadastro-8f8dff4d339a3a12ee155d81a97132032ef3b622.tar.gz
astro-8f8dff4d339a3a12ee155d81a97132032ef3b622.tar.zst
astro-8f8dff4d339a3a12ee155d81a97132032ef3b622.zip
[MDX] Extend Markdown plugin config, with customization options (#4504)
* test: new combined remark / rehype suite * fix: use with-plugins fixture * chore: remove old mdx plugin tests * docs: add JS docs * docs: update README with thorough example * chore: changeset * fix: add "extends" error message * fix: ignore string-based plugins in md * feat: add warning log for string plugins * docs: highlight `extendPlugins` Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * nit: highlight "extendPlugins" * fix: md plugins type check * chore: "defaults" -> "astroDefaults" * nit: info log when inheriting markdown plugins * refactor: one big log on new behavior * dan: dan nit Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
Diffstat (limited to 'packages/integrations/mdx/test/mdx-rehype-plugins.test.js')
-rw-r--r--packages/integrations/mdx/test/mdx-rehype-plugins.test.js70
1 files changed, 0 insertions, 70 deletions
diff --git a/packages/integrations/mdx/test/mdx-rehype-plugins.test.js b/packages/integrations/mdx/test/mdx-rehype-plugins.test.js
deleted file mode 100644
index 17430c750..000000000
--- a/packages/integrations/mdx/test/mdx-rehype-plugins.test.js
+++ /dev/null
@@ -1,70 +0,0 @@
-import mdx from '@astrojs/mdx';
-
-import getReadingTime from 'reading-time';
-import { toString } from 'mdast-util-to-string';
-import { expect } from 'chai';
-import { parseHTML } from 'linkedom';
-import { jsToTreeNode } from '../dist/utils.js';
-
-import { loadFixture } from '../../../astro/test/test-utils.js';
-
-function rehypeReadingTime() {
- return function (tree, { data }) {
- const readingTime = getReadingTime(toString(tree));
- tree.children.unshift(
- jsToTreeNode(`export const readingTime = ${JSON.stringify(readingTime)}`)
- );
- };
-}
-
-const FIXTURE_ROOT = new URL('./fixtures/mdx-rehype-plugins/', import.meta.url);
-
-describe('MDX rehype plugins', () => {
- describe('without "extends"', () => {
- let fixture;
- before(async () => {
- fixture = await loadFixture({
- root: FIXTURE_ROOT,
- integrations: [
- mdx({
- rehypePlugins: [rehypeReadingTime],
- }),
- ],
- });
- await fixture.build();
- });
-
- it('supports custom rehype plugins - reading time', async () => {
- const { readingTime } = JSON.parse(await fixture.readFile('/reading-time.json'));
-
- expect(readingTime).to.not.be.null;
- expect(readingTime.text).to.match(/^\d+ min read/);
- });
- });
-
- describe('with "extends"', () => {
- let fixture;
- before(async () => {
- fixture = await loadFixture({
- root: FIXTURE_ROOT,
- integrations: [
- mdx({
- rehypePlugins: { extends: [rehypeReadingTime] },
- }),
- ],
- });
- await fixture.build();
- });
-
- it('preserves default getHeadings', async () => {
- const html = await fixture.readFile('/space-ipsum/index.html');
- const { document } = parseHTML(html);
-
- const headings = [...document.querySelectorAll('h1, h2')];
- expect(headings.length).to.be.greaterThan(0);
- for (const heading of headings) {
- expect(heading.id).to.not.be.empty;
- }
- });
- });
-});