summaryrefslogtreecommitdiff
path: root/packages/integrations/mdx/test
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations/mdx/test')
-rw-r--r--packages/integrations/mdx/test/mdx-plugins.test.js134
-rw-r--r--packages/integrations/mdx/test/mdx-syntax-highlighting.test.js26
2 files changed, 76 insertions, 84 deletions
diff --git a/packages/integrations/mdx/test/mdx-plugins.test.js b/packages/integrations/mdx/test/mdx-plugins.test.js
index a077fde45..f74ded3ea 100644
--- a/packages/integrations/mdx/test/mdx-plugins.test.js
+++ b/packages/integrations/mdx/test/mdx-plugins.test.js
@@ -80,91 +80,57 @@ describe('MDX plugins', () => {
expect(selectTocLink(document)).to.be.null;
});
- it('respects "extendDefaultPlugins" when extending markdown', async () => {
- const fixture = await buildFixture({
- markdown: {
- remarkPlugins: [remarkExamplePlugin],
- rehypePlugins: [rehypeExamplePlugin],
- extendDefaultPlugins: true,
- },
- integrations: [mdx()],
- });
-
- const html = await fixture.readFile(FILE);
- const { document } = parseHTML(html);
-
- expect(selectRemarkExample(document)).to.not.be.null;
- expect(selectRehypeExample(document)).to.not.be.null;
- expect(selectGfmLink(document)).to.not.be.null;
- });
-
- it('extends markdown config with extendPlugins: "markdown"', async () => {
- const fixture = await buildFixture({
- markdown: {
- remarkPlugins: [remarkExamplePlugin],
- rehypePlugins: [rehypeExamplePlugin],
- },
- integrations: [
- mdx({
- extendPlugins: 'markdown',
- remarkPlugins: [remarkToc],
- }),
- ],
- });
-
- const html = await fixture.readFile(FILE);
- const { document } = parseHTML(html);
-
- expect(selectRemarkExample(document)).to.not.be.null;
- expect(selectRehypeExample(document)).to.not.be.null;
- expect(selectTocLink(document)).to.not.be.null;
- });
-
- it('extends default plugins with extendPlugins: "astroDefaults"', async () => {
- const fixture = await buildFixture({
- markdown: {
- // should NOT be applied to MDX
- remarkPlugins: [remarkToc],
- },
- integrations: [
- mdx({
- remarkPlugins: [remarkExamplePlugin],
- rehypePlugins: [rehypeExamplePlugin],
- extendPlugins: 'astroDefaults',
- }),
- ],
- });
-
- const html = await fixture.readFile(FILE);
- const { document } = parseHTML(html);
-
- expect(selectGfmLink(document)).to.not.be.null;
- // remark and rehype plugins still respected
- expect(selectRemarkExample(document)).to.not.be.null;
- expect(selectRehypeExample(document)).to.not.be.null;
- // Does NOT inherit TOC from markdown config
- expect(selectTocLink(document)).to.be.null;
- });
-
- it('does not extend default plugins with extendPlugins: false', async () => {
- const fixture = await buildFixture({
- markdown: {
- remarkPlugins: [remarkExamplePlugin],
- },
- integrations: [
- mdx({
- remarkPlugins: [],
- extendPlugins: false,
- }),
- ],
+ for (const extendMarkdownConfig of [true, false]) {
+ describe(`extendMarkdownConfig = ${extendMarkdownConfig}`, () => {
+ let fixture;
+ before(async () => {
+ fixture = await buildFixture({
+ markdown: {
+ remarkPlugins: [remarkToc],
+ gfm: false,
+ },
+ integrations: [
+ mdx({
+ extendMarkdownConfig,
+ remarkPlugins: [remarkExamplePlugin],
+ rehypePlugins: [rehypeExamplePlugin],
+ }),
+ ],
+ });
+ });
+
+ it('Handles MDX plugins', async () => {
+ const html = await fixture.readFile(FILE);
+ const { document } = parseHTML(html);
+
+ expect(selectRemarkExample(document, 'MDX remark plugins not applied.')).to.not.be.null;
+ expect(selectRehypeExample(document, 'MDX rehype plugins not applied.')).to.not.be.null;
+ });
+
+ it('Handles Markdown plugins', async () => {
+ const html = await fixture.readFile(FILE);
+ const { document } = parseHTML(html);
+
+ expect(
+ selectTocLink(
+ document,
+ '`remarkToc` plugin applied unexpectedly. Should override Markdown config.'
+ )
+ ).to.be.null;
+ });
+
+ it('Handles gfm', async () => {
+ const html = await fixture.readFile(FILE);
+ const { document } = parseHTML(html);
+
+ if (extendMarkdownConfig === true) {
+ expect(selectGfmLink(document), 'Does not respect `markdown.gfm` option.').to.be.null;
+ } else {
+ expect(selectGfmLink(document), 'Respects `markdown.gfm` unexpectedly.').to.not.be.null;
+ }
+ });
});
-
- const html = await fixture.readFile(FILE);
- const { document } = parseHTML(html);
-
- expect(selectGfmLink(document)).to.be.null;
- expect(selectRemarkExample(document)).to.be.null;
- });
+ }
it('supports custom recma plugins', async () => {
const fixture = await buildFixture({
diff --git a/packages/integrations/mdx/test/mdx-syntax-highlighting.test.js b/packages/integrations/mdx/test/mdx-syntax-highlighting.test.js
index 32c6bcd04..d420faabc 100644
--- a/packages/integrations/mdx/test/mdx-syntax-highlighting.test.js
+++ b/packages/integrations/mdx/test/mdx-syntax-highlighting.test.js
@@ -67,6 +67,32 @@ describe('MDX syntax highlighting', () => {
const prismCodeBlock = document.querySelector('pre.language-astro');
expect(prismCodeBlock).to.not.be.null;
});
+
+ for (const extendMarkdownConfig of [true, false]) {
+ it(`respects syntaxHighlight when extendMarkdownConfig = ${extendMarkdownConfig}`, async () => {
+ const fixture = await loadFixture({
+ root: FIXTURE_ROOT,
+ markdown: {
+ syntaxHighlight: 'shiki',
+ },
+ integrations: [
+ mdx({
+ extendMarkdownConfig,
+ syntaxHighlight: 'prism',
+ }),
+ ],
+ });
+ await fixture.build();
+
+ const html = await fixture.readFile('/index.html');
+ const { document } = parseHTML(html);
+
+ const shikiCodeBlock = document.querySelector('pre.astro-code');
+ expect(shikiCodeBlock, 'Markdown config syntaxHighlight used unexpectedly').to.be.null;
+ const prismCodeBlock = document.querySelector('pre.language-astro');
+ expect(prismCodeBlock).to.not.be.null;
+ });
+ }
});
it('supports custom highlighter - shiki-twoslash', async () => {