Home / File/ mdx-get-headings.test.js — astro Source File

mdx-get-headings.test.js — astro Source File

Architecture documentation for mdx-get-headings.test.js, a javascript file in the astro codebase. 8 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  e31b6e6d_9459_29c6_59c9_1f596c436286["mdx-get-headings.test.js"]
  0a624eac_945e_c9e8_c9de_3feb9de2dd15["test-utils.js"]
  e31b6e6d_9459_29c6_59c9_1f596c436286 --> 0a624eac_945e_c9e8_c9de_3feb9de2dd15
  dd4f09ce_3fd7_8295_f616_8876cda4555c["loadFixture"]
  e31b6e6d_9459_29c6_59c9_1f596c436286 --> dd4f09ce_3fd7_8295_f616_8876cda4555c
  e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"]
  e31b6e6d_9459_29c6_59c9_1f596c436286 --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607
  6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"]
  e31b6e6d_9459_29c6_59c9_1f596c436286 --> 6b0635f9_51ea_77aa_767b_7857878e98a6
  82f345a2_2234_43f1_c3c4_eea191acdca8["markdown-remark"]
  e31b6e6d_9459_29c6_59c9_1f596c436286 --> 82f345a2_2234_43f1_c3c4_eea191acdca8
  b05fd4c1_a3ee_3301_adcd_43b49bae78f1["mdx"]
  e31b6e6d_9459_29c6_59c9_1f596c436286 --> b05fd4c1_a3ee_3301_adcd_43b49bae78f1
  cb315bcc_59d8_fa19_79aa_5da7cd3730c5["linkedom"]
  e31b6e6d_9459_29c6_59c9_1f596c436286 --> cb315bcc_59d8_fa19_79aa_5da7cd3730c5
  d7b51bf7_4a46_1479_0cea_09e174fc7c48["unist-util-visit"]
  e31b6e6d_9459_29c6_59c9_1f596c436286 --> d7b51bf7_4a46_1479_0cea_09e174fc7c48
  style e31b6e6d_9459_29c6_59c9_1f596c436286 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import * as assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import { rehypeHeadingIds } from '@astrojs/markdown-remark';
import mdx from '@astrojs/mdx';
import { parseHTML } from 'linkedom';
import { visit } from 'unist-util-visit';
import { loadFixture } from '../../../astro/test/test-utils.js';

describe('MDX getHeadings', () => {
	let fixture;

	before(async () => {
		fixture = await loadFixture({
			root: new URL('./fixtures/mdx-get-headings/', import.meta.url),
			integrations: [mdx()],
		});

		await fixture.build();
	});

	it('adds anchor IDs to headings', async () => {
		const html = await fixture.readFile('/test/index.html');
		const { document } = parseHTML(html);

		const h2Ids = document.querySelectorAll('h2').map((el) => el?.id);
		const h3Ids = document.querySelectorAll('h3').map((el) => el?.id);
		assert.equal(document.querySelector('h1').id, 'heading-test');
		assert.equal(h2Ids.includes('section-1'), true);
		assert.equal(h2Ids.includes('section-2'), true);
		assert.equal(h3Ids.includes('subsection-1'), true);
		assert.equal(h3Ids.includes('subsection-2'), true);
	});

	it('generates correct getHeadings() export', async () => {
		const { headingsByPage } = JSON.parse(await fixture.readFile('/pages.json'));
		// TODO: make this a snapshot test :)
		assert.equal(
			JSON.stringify(headingsByPage['./test.mdx']),
			JSON.stringify([
				{ depth: 1, slug: 'heading-test', text: 'Heading test' },
				{ depth: 2, slug: 'section-1', text: 'Section 1' },
				{ depth: 3, slug: 'subsection-1', text: 'Subsection 1' },
				{ depth: 3, slug: 'subsection-2', text: 'Subsection 2' },
				{ depth: 2, slug: 'section-2', text: 'Section 2' },
				{ depth: 2, slug: 'picture-', text: '<Picture />' },
				{ depth: 3, slug: '-sacrebleu--', text: '« Sacrebleu ! »' },
			]),
		);
	});

	it('generates correct getHeadings() export for JSX expressions', async () => {
		const { headingsByPage } = JSON.parse(await fixture.readFile('/pages.json'));
		assert.equal(
			JSON.stringify(headingsByPage['./test-with-jsx-expressions.mdx']),
			JSON.stringify([
				{
					depth: 1,
					slug: 'heading-test-with-jsx-expressions',
					text: 'Heading test with JSX expressions',
				},
// ... (144 more lines)

Domain

Dependencies

Frequently Asked Questions

What does mdx-get-headings.test.js do?
mdx-get-headings.test.js is a source file in the astro codebase, written in javascript. It belongs to the CoreAstro domain.
What does mdx-get-headings.test.js depend on?
mdx-get-headings.test.js imports 8 module(s): linkedom, loadFixture, markdown-remark, mdx, node:test, strict, test-utils.js, unist-util-visit.
Where is mdx-get-headings.test.js in the architecture?
mdx-get-headings.test.js is located at packages/integrations/mdx/test/mdx-get-headings.test.js (domain: CoreAstro, directory: packages/integrations/mdx/test).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free