@astrojs/mdx 0.19.0 → 0.19.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/remark-shiki.js +17 -0
- package/package.json +10 -6
- package/.turbo/turbo-build.log +0 -5
- package/CHANGELOG.md +0 -716
- package/src/index.ts +0 -226
- package/src/plugins.ts +0 -185
- package/src/rehype-collect-headings.ts +0 -11
- package/src/rehype-meta-string.ts +0 -17
- package/src/remark-images-to-component.ts +0 -98
- package/src/remark-prism.ts +0 -18
- package/src/remark-shiki.ts +0 -95
- package/src/utils.ts +0 -108
- package/test/css-head-mdx.test.js +0 -98
- package/test/fixtures/css-head-mdx/node_modules/.bin/astro +0 -17
- package/test/fixtures/css-head-mdx/package.json +0 -10
- package/test/fixtures/css-head-mdx/src/components/BaseHead.astro +0 -11
- package/test/fixtures/css-head-mdx/src/components/BasicBlock.astro +0 -14
- package/test/fixtures/css-head-mdx/src/components/GenericComponent.astro +0 -1
- package/test/fixtures/css-head-mdx/src/components/HelloWorld.astro +0 -11
- package/test/fixtures/css-head-mdx/src/components/MDXWrapper.astro +0 -9
- package/test/fixtures/css-head-mdx/src/components/P.astro +0 -3
- package/test/fixtures/css-head-mdx/src/components/SmallCaps.astro +0 -3
- package/test/fixtures/css-head-mdx/src/components/UsingMdx.astro +0 -8
- package/test/fixtures/css-head-mdx/src/components/WithHoistedScripts.astro +0 -6
- package/test/fixtures/css-head-mdx/src/content/blog/_styles.css +0 -3
- package/test/fixtures/css-head-mdx/src/content/blog/using-mdx.mdx +0 -6
- package/test/fixtures/css-head-mdx/src/content/posts/test.mdx +0 -5
- package/test/fixtures/css-head-mdx/src/content/posts/using-component.mdx +0 -13
- package/test/fixtures/css-head-mdx/src/layouts/ContentLayout.astro +0 -18
- package/test/fixtures/css-head-mdx/src/layouts/DocumentLayout.astro +0 -15
- package/test/fixtures/css-head-mdx/src/layouts/One.astro +0 -15
- package/test/fixtures/css-head-mdx/src/layouts/Three.astro +0 -6
- package/test/fixtures/css-head-mdx/src/layouts/Two.astro +0 -6
- package/test/fixtures/css-head-mdx/src/pages/DirectContentUsage.astro +0 -17
- package/test/fixtures/css-head-mdx/src/pages/componentwithtext.mdx +0 -12
- package/test/fixtures/css-head-mdx/src/pages/indexOne.astro +0 -10
- package/test/fixtures/css-head-mdx/src/pages/indexThree.astro +0 -10
- package/test/fixtures/css-head-mdx/src/pages/indexTwo.astro +0 -10
- package/test/fixtures/css-head-mdx/src/pages/noLayoutWithComponent.mdx +0 -22
- package/test/fixtures/css-head-mdx/src/pages/posts/[post].astro +0 -18
- package/test/fixtures/css-head-mdx/src/pages/remote.astro +0 -17
- package/test/fixtures/css-head-mdx/src/pages/testOne.mdx +0 -15
- package/test/fixtures/css-head-mdx/src/pages/testThree.mdx +0 -15
- package/test/fixtures/css-head-mdx/src/pages/testTwo.mdx +0 -15
- package/test/fixtures/css-head-mdx/src/styles/global.css +0 -3
- package/test/fixtures/css-head-mdx/src/test.mdx +0 -14
- package/test/fixtures/mdx-astro-markdown-remarkRehype/src/pages/index.mdx +0 -5
- package/test/fixtures/mdx-component/src/components/Test.mdx +0 -3
- package/test/fixtures/mdx-component/src/components/WithFragment.mdx +0 -3
- package/test/fixtures/mdx-component/src/pages/glob.astro +0 -20
- package/test/fixtures/mdx-component/src/pages/index.astro +0 -5
- package/test/fixtures/mdx-component/src/pages/w-fragment.astro +0 -5
- package/test/fixtures/mdx-escape/src/components/Em.astro +0 -7
- package/test/fixtures/mdx-escape/src/components/P.astro +0 -1
- package/test/fixtures/mdx-escape/src/components/Title.astro +0 -1
- package/test/fixtures/mdx-escape/src/pages/html-tag.mdx +0 -5
- package/test/fixtures/mdx-escape/src/pages/index.mdx +0 -13
- package/test/fixtures/mdx-frontmatter/src/layouts/Base.astro +0 -38
- package/test/fixtures/mdx-frontmatter/src/pages/glob.json.js +0 -9
- package/test/fixtures/mdx-frontmatter/src/pages/index.mdx +0 -10
- package/test/fixtures/mdx-frontmatter/src/pages/with-headings.mdx +0 -7
- package/test/fixtures/mdx-frontmatter-injection/astro.config.mjs +0 -12
- package/test/fixtures/mdx-frontmatter-injection/node_modules/.bin/astro +0 -17
- package/test/fixtures/mdx-frontmatter-injection/package.json +0 -12
- package/test/fixtures/mdx-frontmatter-injection/src/layouts/Base.astro +0 -17
- package/test/fixtures/mdx-frontmatter-injection/src/markdown-plugins.mjs +0 -27
- package/test/fixtures/mdx-frontmatter-injection/src/pages/glob.json.js +0 -6
- package/test/fixtures/mdx-frontmatter-injection/src/pages/page-1.mdx +0 -8
- package/test/fixtures/mdx-frontmatter-injection/src/pages/page-2.mdx +0 -24
- package/test/fixtures/mdx-get-headings/src/pages/pages.json.js +0 -11
- package/test/fixtures/mdx-get-headings/src/pages/test-with-frontmatter.mdx +0 -45
- package/test/fixtures/mdx-get-headings/src/pages/test-with-jsx-expressions.mdx +0 -8
- package/test/fixtures/mdx-get-headings/src/pages/test.mdx +0 -9
- package/test/fixtures/mdx-get-static-paths/src/content/1.mdx +0 -5
- package/test/fixtures/mdx-get-static-paths/src/pages/[slug].astro +0 -34
- package/test/fixtures/mdx-images/astro.config.ts +0 -8
- package/test/fixtures/mdx-images/node_modules/.bin/astro +0 -17
- package/test/fixtures/mdx-images/package.json +0 -9
- package/test/fixtures/mdx-images/src/assets/houston in space.webp +0 -0
- package/test/fixtures/mdx-images/src/assets/houston.webp +0 -0
- package/test/fixtures/mdx-images/src/pages/index.mdx +0 -11
- package/test/fixtures/mdx-infinite-loop/astro.config.ts +0 -6
- package/test/fixtures/mdx-infinite-loop/node_modules/.bin/astro +0 -17
- package/test/fixtures/mdx-infinite-loop/package.json +0 -10
- package/test/fixtures/mdx-infinite-loop/src/components/Test.js +0 -3
- package/test/fixtures/mdx-infinite-loop/src/pages/doc.mdx +0 -6
- package/test/fixtures/mdx-infinite-loop/src/pages/index.astro +0 -5
- package/test/fixtures/mdx-math/src/pages/mathjax.mdx +0 -5
- package/test/fixtures/mdx-namespace/astro.config.mjs +0 -6
- package/test/fixtures/mdx-namespace/node_modules/.bin/astro +0 -17
- package/test/fixtures/mdx-namespace/package.json +0 -10
- package/test/fixtures/mdx-namespace/src/components/Component.jsx +0 -6
- package/test/fixtures/mdx-namespace/src/pages/object.mdx +0 -3
- package/test/fixtures/mdx-namespace/src/pages/star.mdx +0 -3
- package/test/fixtures/mdx-page/astro.config.ts +0 -5
- package/test/fixtures/mdx-page/node_modules/.bin/astro +0 -17
- package/test/fixtures/mdx-page/package.json +0 -9
- package/test/fixtures/mdx-page/src/pages/index.mdx +0 -3
- package/test/fixtures/mdx-page/src/styles.css +0 -3
- package/test/fixtures/mdx-plugins/src/pages/with-plugins.mdx +0 -25
- package/test/fixtures/mdx-plus-react/astro.config.mjs +0 -6
- package/test/fixtures/mdx-plus-react/node_modules/.bin/astro +0 -17
- package/test/fixtures/mdx-plus-react/package.json +0 -10
- package/test/fixtures/mdx-plus-react/src/components/Component.jsx +0 -5
- package/test/fixtures/mdx-plus-react/src/pages/index.astro +0 -11
- package/test/fixtures/mdx-script-style-raw/src/pages/index.mdx +0 -13
- package/test/fixtures/mdx-slots/src/components/Slotted.astro +0 -4
- package/test/fixtures/mdx-slots/src/components/Test.mdx +0 -15
- package/test/fixtures/mdx-slots/src/pages/glob.astro +0 -11
- package/test/fixtures/mdx-slots/src/pages/index.astro +0 -5
- package/test/fixtures/mdx-syntax-hightlighting/src/pages/index.mdx +0 -9
- package/test/fixtures/mdx-url-export/src/pages/pages.json.js +0 -9
- package/test/fixtures/mdx-url-export/src/pages/test-1.mdx +0 -1
- package/test/fixtures/mdx-url-export/src/pages/test-2.mdx +0 -1
- package/test/fixtures/mdx-url-export/src/pages/with-url-override.mdx +0 -3
- package/test/fixtures/mdx-vite-env-vars/astro.config.mjs +0 -9
- package/test/fixtures/mdx-vite-env-vars/node_modules/.bin/astro +0 -17
- package/test/fixtures/mdx-vite-env-vars/package.json +0 -7
- package/test/fixtures/mdx-vite-env-vars/src/pages/frontmatter.json.js +0 -7
- package/test/fixtures/mdx-vite-env-vars/src/pages/vite-env-vars.mdx +0 -38
- package/test/mdx-astro-markdown-remarkRehype.test.js +0 -85
- package/test/mdx-component.test.js +0 -191
- package/test/mdx-escape.test.js +0 -32
- package/test/mdx-frontmatter-injection.test.js +0 -53
- package/test/mdx-frontmatter.test.js +0 -77
- package/test/mdx-get-headings.test.js +0 -194
- package/test/mdx-get-static-paths.test.js +0 -32
- package/test/mdx-images.test.js +0 -40
- package/test/mdx-infinite-loop.test.js +0 -30
- package/test/mdx-math.test.js +0 -64
- package/test/mdx-namespace.test.js +0 -83
- package/test/mdx-page.test.js +0 -64
- package/test/mdx-plugins.test.js +0 -285
- package/test/mdx-plus-react.test.js +0 -25
- package/test/mdx-script-style-raw.test.js +0 -70
- package/test/mdx-slots.js +0 -124
- package/test/mdx-syntax-highlighting.test.js +0 -145
- package/test/mdx-url-export.test.js +0 -28
- package/test/mdx-vite-env-vars.test.js +0 -54
- package/tsconfig.json +0 -10
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import { rehypeHeadingIds } from '@astrojs/markdown-remark';
|
|
2
|
-
import mdx from '@astrojs/mdx';
|
|
3
|
-
import { visit } from 'unist-util-visit';
|
|
4
|
-
|
|
5
|
-
import { expect } from 'chai';
|
|
6
|
-
import { parseHTML } from 'linkedom';
|
|
7
|
-
import { loadFixture } from '../../../astro/test/test-utils.js';
|
|
8
|
-
|
|
9
|
-
describe('MDX getHeadings', () => {
|
|
10
|
-
let fixture;
|
|
11
|
-
|
|
12
|
-
before(async () => {
|
|
13
|
-
fixture = await loadFixture({
|
|
14
|
-
root: new URL('./fixtures/mdx-get-headings/', import.meta.url),
|
|
15
|
-
integrations: [mdx()],
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
await fixture.build();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('adds anchor IDs to headings', async () => {
|
|
22
|
-
const html = await fixture.readFile('/test/index.html');
|
|
23
|
-
const { document } = parseHTML(html);
|
|
24
|
-
|
|
25
|
-
const h2Ids = document.querySelectorAll('h2').map((el) => el?.id);
|
|
26
|
-
const h3Ids = document.querySelectorAll('h3').map((el) => el?.id);
|
|
27
|
-
expect(document.querySelector('h1').id).to.equal('heading-test');
|
|
28
|
-
expect(h2Ids).to.contain('section-1');
|
|
29
|
-
expect(h2Ids).to.contain('section-2');
|
|
30
|
-
expect(h3Ids).to.contain('subsection-1');
|
|
31
|
-
expect(h3Ids).to.contain('subsection-2');
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('generates correct getHeadings() export', async () => {
|
|
35
|
-
const { headingsByPage } = JSON.parse(await fixture.readFile('/pages.json'));
|
|
36
|
-
// TODO: make this a snapshot test :)
|
|
37
|
-
expect(JSON.stringify(headingsByPage['./test.mdx'])).to.equal(
|
|
38
|
-
JSON.stringify([
|
|
39
|
-
{ depth: 1, slug: 'heading-test', text: 'Heading test' },
|
|
40
|
-
{ depth: 2, slug: 'section-1', text: 'Section 1' },
|
|
41
|
-
{ depth: 3, slug: 'subsection-1', text: 'Subsection 1' },
|
|
42
|
-
{ depth: 3, slug: 'subsection-2', text: 'Subsection 2' },
|
|
43
|
-
{ depth: 2, slug: 'section-2', text: 'Section 2' },
|
|
44
|
-
])
|
|
45
|
-
);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('generates correct getHeadings() export for JSX expressions', async () => {
|
|
49
|
-
const { headingsByPage } = JSON.parse(await fixture.readFile('/pages.json'));
|
|
50
|
-
expect(JSON.stringify(headingsByPage['./test-with-jsx-expressions.mdx'])).to.equal(
|
|
51
|
-
JSON.stringify([
|
|
52
|
-
{
|
|
53
|
-
depth: 1,
|
|
54
|
-
slug: 'heading-test-with-jsx-expressions',
|
|
55
|
-
text: 'Heading test with JSX expressions',
|
|
56
|
-
},
|
|
57
|
-
{ depth: 2, slug: 'h2title', text: 'h2Title' },
|
|
58
|
-
{ depth: 3, slug: 'h3title', text: 'h3Title' },
|
|
59
|
-
])
|
|
60
|
-
);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
describe('MDX heading IDs can be customized by user plugins', () => {
|
|
65
|
-
let fixture;
|
|
66
|
-
|
|
67
|
-
before(async () => {
|
|
68
|
-
fixture = await loadFixture({
|
|
69
|
-
root: new URL('./fixtures/mdx-get-headings/', import.meta.url),
|
|
70
|
-
integrations: [mdx()],
|
|
71
|
-
markdown: {
|
|
72
|
-
rehypePlugins: [
|
|
73
|
-
() => (tree) => {
|
|
74
|
-
let count = 0;
|
|
75
|
-
visit(tree, 'element', (node, index, parent) => {
|
|
76
|
-
if (!/^h\d$/.test(node.tagName)) return;
|
|
77
|
-
if (!node.properties?.id) {
|
|
78
|
-
node.properties = { ...node.properties, id: String(count++) };
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
},
|
|
82
|
-
],
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
await fixture.build();
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('adds user-specified IDs to HTML output', async () => {
|
|
90
|
-
const html = await fixture.readFile('/test/index.html');
|
|
91
|
-
const { document } = parseHTML(html);
|
|
92
|
-
|
|
93
|
-
const h1 = document.querySelector('h1');
|
|
94
|
-
expect(h1?.textContent).to.equal('Heading test');
|
|
95
|
-
expect(h1?.getAttribute('id')).to.equal('0');
|
|
96
|
-
|
|
97
|
-
const headingIDs = document.querySelectorAll('h1,h2,h3').map((el) => el.id);
|
|
98
|
-
expect(JSON.stringify(headingIDs)).to.equal(
|
|
99
|
-
JSON.stringify(Array.from({ length: headingIDs.length }, (_, idx) => String(idx)))
|
|
100
|
-
);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('generates correct getHeadings() export', async () => {
|
|
104
|
-
const { headingsByPage } = JSON.parse(await fixture.readFile('/pages.json'));
|
|
105
|
-
expect(JSON.stringify(headingsByPage['./test.mdx'])).to.equal(
|
|
106
|
-
JSON.stringify([
|
|
107
|
-
{ depth: 1, slug: '0', text: 'Heading test' },
|
|
108
|
-
{ depth: 2, slug: '1', text: 'Section 1' },
|
|
109
|
-
{ depth: 3, slug: '2', text: 'Subsection 1' },
|
|
110
|
-
{ depth: 3, slug: '3', text: 'Subsection 2' },
|
|
111
|
-
{ depth: 2, slug: '4', text: 'Section 2' },
|
|
112
|
-
])
|
|
113
|
-
);
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
describe('MDX heading IDs can be injected before user plugins', () => {
|
|
118
|
-
let fixture;
|
|
119
|
-
|
|
120
|
-
before(async () => {
|
|
121
|
-
fixture = await loadFixture({
|
|
122
|
-
root: new URL('./fixtures/mdx-get-headings/', import.meta.url),
|
|
123
|
-
integrations: [
|
|
124
|
-
mdx({
|
|
125
|
-
rehypePlugins: [
|
|
126
|
-
rehypeHeadingIds,
|
|
127
|
-
() => (tree) => {
|
|
128
|
-
visit(tree, 'element', (node, index, parent) => {
|
|
129
|
-
if (!/^h\d$/.test(node.tagName)) return;
|
|
130
|
-
if (node.properties?.id) {
|
|
131
|
-
node.children.push({ type: 'text', value: ' ' + node.properties.id });
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
},
|
|
135
|
-
],
|
|
136
|
-
}),
|
|
137
|
-
],
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
await fixture.build();
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('adds user-specified IDs to HTML output', async () => {
|
|
144
|
-
const html = await fixture.readFile('/test/index.html');
|
|
145
|
-
const { document } = parseHTML(html);
|
|
146
|
-
|
|
147
|
-
const h1 = document.querySelector('h1');
|
|
148
|
-
expect(h1?.textContent).to.equal('Heading test heading-test');
|
|
149
|
-
expect(h1?.id).to.equal('heading-test');
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
describe('MDX headings with frontmatter', () => {
|
|
154
|
-
let fixture;
|
|
155
|
-
|
|
156
|
-
before(async () => {
|
|
157
|
-
fixture = await loadFixture({
|
|
158
|
-
root: new URL('./fixtures/mdx-get-headings/', import.meta.url),
|
|
159
|
-
integrations: [mdx()],
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
await fixture.build();
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('adds anchor IDs to headings', async () => {
|
|
166
|
-
const html = await fixture.readFile('/test-with-frontmatter/index.html');
|
|
167
|
-
const { document } = parseHTML(html);
|
|
168
|
-
|
|
169
|
-
const h3Ids = document.querySelectorAll('h3').map((el) => el?.id);
|
|
170
|
-
|
|
171
|
-
expect(document.querySelector('h1').id).to.equal('the-frontmatter-title');
|
|
172
|
-
expect(document.querySelector('h2').id).to.equal('frontmattertitle');
|
|
173
|
-
expect(h3Ids).to.contain('keyword-2');
|
|
174
|
-
expect(h3Ids).to.contain('tag-1');
|
|
175
|
-
expect(document.querySelector('h4').id).to.equal('item-2');
|
|
176
|
-
expect(document.querySelector('h5').id).to.equal('nested-item-3');
|
|
177
|
-
expect(document.querySelector('h6').id).to.equal('frontmatterunknown');
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it('generates correct getHeadings() export', async () => {
|
|
181
|
-
const { headingsByPage } = JSON.parse(await fixture.readFile('/pages.json'));
|
|
182
|
-
expect(JSON.stringify(headingsByPage['./test-with-frontmatter.mdx'])).to.equal(
|
|
183
|
-
JSON.stringify([
|
|
184
|
-
{ depth: 1, slug: 'the-frontmatter-title', text: 'The Frontmatter Title' },
|
|
185
|
-
{ depth: 2, slug: 'frontmattertitle', text: 'frontmatter.title' },
|
|
186
|
-
{ depth: 3, slug: 'keyword-2', text: 'Keyword 2' },
|
|
187
|
-
{ depth: 3, slug: 'tag-1', text: 'Tag 1' },
|
|
188
|
-
{ depth: 4, slug: 'item-2', text: 'Item 2' },
|
|
189
|
-
{ depth: 5, slug: 'nested-item-3', text: 'Nested Item 3' },
|
|
190
|
-
{ depth: 6, slug: 'frontmatterunknown', text: 'frontmatter.unknown' },
|
|
191
|
-
])
|
|
192
|
-
);
|
|
193
|
-
});
|
|
194
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import mdx from '@astrojs/mdx';
|
|
2
|
-
|
|
3
|
-
import { expect } from 'chai';
|
|
4
|
-
import { loadFixture } from '../../../astro/test/test-utils.js';
|
|
5
|
-
import * as cheerio from 'cheerio';
|
|
6
|
-
|
|
7
|
-
const FIXTURE_ROOT = new URL('./fixtures/mdx-get-static-paths', import.meta.url);
|
|
8
|
-
|
|
9
|
-
describe('getStaticPaths', () => {
|
|
10
|
-
/** @type {import('astro/test/test-utils').Fixture} */
|
|
11
|
-
let fixture;
|
|
12
|
-
before(async () => {
|
|
13
|
-
fixture = await loadFixture({
|
|
14
|
-
root: FIXTURE_ROOT,
|
|
15
|
-
integrations: [mdx()],
|
|
16
|
-
});
|
|
17
|
-
await fixture.build();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('Provides file and url', async () => {
|
|
21
|
-
const html = await fixture.readFile('/one/index.html');
|
|
22
|
-
|
|
23
|
-
const $ = cheerio.load(html);
|
|
24
|
-
expect($('p').text()).to.equal('First mdx file');
|
|
25
|
-
expect($('#one').text()).to.equal('hello', 'Frontmatter included');
|
|
26
|
-
expect($('#url').text()).to.equal('/src/content/1.mdx', 'url is included');
|
|
27
|
-
expect($('#file').text()).to.contain(
|
|
28
|
-
'fixtures/mdx-get-static-paths/src/content/1.mdx',
|
|
29
|
-
'file is included'
|
|
30
|
-
);
|
|
31
|
-
});
|
|
32
|
-
});
|
package/test/mdx-images.test.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { expect } from 'chai';
|
|
2
|
-
import { parseHTML } from 'linkedom';
|
|
3
|
-
import { loadFixture } from '../../../astro/test/test-utils.js';
|
|
4
|
-
|
|
5
|
-
describe('MDX Page', () => {
|
|
6
|
-
let devServer;
|
|
7
|
-
let fixture;
|
|
8
|
-
|
|
9
|
-
before(async () => {
|
|
10
|
-
fixture = await loadFixture({
|
|
11
|
-
root: new URL('./fixtures/mdx-images/', import.meta.url),
|
|
12
|
-
});
|
|
13
|
-
devServer = await fixture.startDevServer();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
after(async () => {
|
|
17
|
-
await devServer.stop();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
describe('Optimized images in MDX', () => {
|
|
21
|
-
it('works', async () => {
|
|
22
|
-
const res = await fixture.fetch('/');
|
|
23
|
-
expect(res.status).to.equal(200);
|
|
24
|
-
|
|
25
|
-
const html = await res.text();
|
|
26
|
-
const { document } = parseHTML(html);
|
|
27
|
-
|
|
28
|
-
const imgs = document.getElementsByTagName('img');
|
|
29
|
-
expect(imgs.length).to.equal(4);
|
|
30
|
-
// Image using a relative path
|
|
31
|
-
expect(imgs.item(0).src.startsWith('/_image')).to.be.true;
|
|
32
|
-
// Image using an aliased path
|
|
33
|
-
expect(imgs.item(1).src.startsWith('/_image')).to.be.true;
|
|
34
|
-
// Image with title
|
|
35
|
-
expect(imgs.item(2).title).to.equal('Houston title');
|
|
36
|
-
// Image with spaces in the path
|
|
37
|
-
expect(imgs.item(3).src.startsWith('/_image')).to.be.true;
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import mdx from '@astrojs/mdx';
|
|
2
|
-
|
|
3
|
-
import { expect } from 'chai';
|
|
4
|
-
import { loadFixture } from '../../../astro/test/test-utils.js';
|
|
5
|
-
|
|
6
|
-
describe('MDX Infinite Loop', () => {
|
|
7
|
-
let fixture;
|
|
8
|
-
|
|
9
|
-
before(async () => {
|
|
10
|
-
fixture = await loadFixture({
|
|
11
|
-
root: new URL('./fixtures/mdx-infinite-loop/', import.meta.url),
|
|
12
|
-
integrations: [mdx()],
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
describe('build', () => {
|
|
17
|
-
let err;
|
|
18
|
-
before(async () => {
|
|
19
|
-
try {
|
|
20
|
-
await fixture.build();
|
|
21
|
-
} catch (e) {
|
|
22
|
-
err = e;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('does not hang forever if an error is thrown', async () => {
|
|
27
|
-
expect(!!err).to.be.true;
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
});
|
package/test/mdx-math.test.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import mdx from '@astrojs/mdx';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import { parseHTML } from 'linkedom';
|
|
4
|
-
import { loadFixture } from '../../../astro/test/test-utils.js';
|
|
5
|
-
import remarkMath from 'remark-math';
|
|
6
|
-
import rehypeMathjaxSvg from 'rehype-mathjax';
|
|
7
|
-
import rehypeMathjaxChtml from 'rehype-mathjax/chtml.js';
|
|
8
|
-
|
|
9
|
-
const FIXTURE_ROOT = new URL('./fixtures/mdx-math/', import.meta.url);
|
|
10
|
-
|
|
11
|
-
describe('MDX math', () => {
|
|
12
|
-
describe('mathjax', () => {
|
|
13
|
-
it('works with svg', async () => {
|
|
14
|
-
const fixture = await loadFixture({
|
|
15
|
-
root: FIXTURE_ROOT,
|
|
16
|
-
markdown: {
|
|
17
|
-
remarkPlugins: [remarkMath],
|
|
18
|
-
rehypePlugins: [rehypeMathjaxSvg],
|
|
19
|
-
},
|
|
20
|
-
integrations: [mdx()],
|
|
21
|
-
});
|
|
22
|
-
await fixture.build();
|
|
23
|
-
|
|
24
|
-
const html = await fixture.readFile('/mathjax/index.html');
|
|
25
|
-
const { document } = parseHTML(html);
|
|
26
|
-
|
|
27
|
-
const mjxContainer = document.querySelector('mjx-container[jax="SVG"]');
|
|
28
|
-
expect(mjxContainer).to.not.be.null;
|
|
29
|
-
|
|
30
|
-
const mjxStyle = document.querySelector('style').innerHTML;
|
|
31
|
-
expect(mjxStyle).to.include('mjx-container[jax="SVG"]', 'style should not be html-escaped');
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('works with chtml', async () => {
|
|
35
|
-
const fixture = await loadFixture({
|
|
36
|
-
root: FIXTURE_ROOT,
|
|
37
|
-
markdown: {
|
|
38
|
-
remarkPlugins: [remarkMath],
|
|
39
|
-
rehypePlugins: [
|
|
40
|
-
[
|
|
41
|
-
rehypeMathjaxChtml,
|
|
42
|
-
{
|
|
43
|
-
chtml: {
|
|
44
|
-
fontURL: 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/output/chtml/fonts/woff-v2',
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
],
|
|
49
|
-
},
|
|
50
|
-
integrations: [mdx()],
|
|
51
|
-
});
|
|
52
|
-
await fixture.build();
|
|
53
|
-
|
|
54
|
-
const html = await fixture.readFile('/mathjax/index.html');
|
|
55
|
-
const { document } = parseHTML(html);
|
|
56
|
-
|
|
57
|
-
const mjxContainer = document.querySelector('mjx-container[jax="CHTML"]');
|
|
58
|
-
expect(mjxContainer).to.not.be.null;
|
|
59
|
-
|
|
60
|
-
const mjxStyle = document.querySelector('style').innerHTML;
|
|
61
|
-
expect(mjxStyle).to.include('mjx-container[jax="CHTML"]', 'style should not be html-escaped');
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
});
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { expect } from 'chai';
|
|
2
|
-
import { parseHTML } from 'linkedom';
|
|
3
|
-
import { loadFixture } from '../../../astro/test/test-utils.js';
|
|
4
|
-
|
|
5
|
-
describe('MDX Namespace', () => {
|
|
6
|
-
let fixture;
|
|
7
|
-
|
|
8
|
-
before(async () => {
|
|
9
|
-
fixture = await loadFixture({
|
|
10
|
-
root: new URL('./fixtures/mdx-namespace/', import.meta.url),
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
describe('build', () => {
|
|
15
|
-
before(async () => {
|
|
16
|
-
await fixture.build();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('works for object', async () => {
|
|
20
|
-
const html = await fixture.readFile('/object/index.html');
|
|
21
|
-
const { document } = parseHTML(html);
|
|
22
|
-
|
|
23
|
-
const island = document.querySelector('astro-island');
|
|
24
|
-
const component = document.querySelector('#component');
|
|
25
|
-
|
|
26
|
-
expect(island).not.undefined;
|
|
27
|
-
expect(component.textContent).equal('Hello world');
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('works for star', async () => {
|
|
31
|
-
const html = await fixture.readFile('/star/index.html');
|
|
32
|
-
const { document } = parseHTML(html);
|
|
33
|
-
|
|
34
|
-
const island = document.querySelector('astro-island');
|
|
35
|
-
const component = document.querySelector('#component');
|
|
36
|
-
|
|
37
|
-
expect(island).not.undefined;
|
|
38
|
-
expect(component.textContent).equal('Hello world');
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe('dev', () => {
|
|
43
|
-
let devServer;
|
|
44
|
-
|
|
45
|
-
before(async () => {
|
|
46
|
-
devServer = await fixture.startDevServer();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
after(async () => {
|
|
50
|
-
await devServer.stop();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('works for object', async () => {
|
|
54
|
-
const res = await fixture.fetch('/object');
|
|
55
|
-
|
|
56
|
-
expect(res.status).to.equal(200);
|
|
57
|
-
|
|
58
|
-
const html = await res.text();
|
|
59
|
-
const { document } = parseHTML(html);
|
|
60
|
-
|
|
61
|
-
const island = document.querySelector('astro-island');
|
|
62
|
-
const component = document.querySelector('#component');
|
|
63
|
-
|
|
64
|
-
expect(island).not.undefined;
|
|
65
|
-
expect(component.textContent).equal('Hello world');
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('works for star', async () => {
|
|
69
|
-
const res = await fixture.fetch('/star');
|
|
70
|
-
|
|
71
|
-
expect(res.status).to.equal(200);
|
|
72
|
-
|
|
73
|
-
const html = await res.text();
|
|
74
|
-
const { document } = parseHTML(html);
|
|
75
|
-
|
|
76
|
-
const island = document.querySelector('astro-island');
|
|
77
|
-
const component = document.querySelector('#component');
|
|
78
|
-
|
|
79
|
-
expect(island).not.undefined;
|
|
80
|
-
expect(component.textContent).equal('Hello world');
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
});
|
package/test/mdx-page.test.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import mdx from '@astrojs/mdx';
|
|
2
|
-
|
|
3
|
-
import { expect } from 'chai';
|
|
4
|
-
import { parseHTML } from 'linkedom';
|
|
5
|
-
import { loadFixture } from '../../../astro/test/test-utils.js';
|
|
6
|
-
|
|
7
|
-
describe('MDX Page', () => {
|
|
8
|
-
let fixture;
|
|
9
|
-
|
|
10
|
-
before(async () => {
|
|
11
|
-
fixture = await loadFixture({
|
|
12
|
-
root: new URL('./fixtures/mdx-page/', import.meta.url),
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
describe('build', () => {
|
|
17
|
-
before(async () => {
|
|
18
|
-
await fixture.build();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('works', async () => {
|
|
22
|
-
const html = await fixture.readFile('/index.html');
|
|
23
|
-
const { document } = parseHTML(html);
|
|
24
|
-
|
|
25
|
-
const h1 = document.querySelector('h1');
|
|
26
|
-
|
|
27
|
-
expect(h1.textContent).to.equal('Hello page!');
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('injects style imports when layout is not applied', async () => {
|
|
31
|
-
const html = await fixture.readFile('/index.html');
|
|
32
|
-
const { document } = parseHTML(html);
|
|
33
|
-
|
|
34
|
-
const stylesheet = document.querySelector('link[rel="stylesheet"]');
|
|
35
|
-
|
|
36
|
-
expect(stylesheet).to.not.be.null;
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
describe('dev', () => {
|
|
41
|
-
let devServer;
|
|
42
|
-
|
|
43
|
-
before(async () => {
|
|
44
|
-
devServer = await fixture.startDevServer();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
after(async () => {
|
|
48
|
-
await devServer.stop();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('works', async () => {
|
|
52
|
-
const res = await fixture.fetch('/');
|
|
53
|
-
|
|
54
|
-
expect(res.status).to.equal(200);
|
|
55
|
-
|
|
56
|
-
const html = await res.text();
|
|
57
|
-
const { document } = parseHTML(html);
|
|
58
|
-
|
|
59
|
-
const h1 = document.querySelector('h1');
|
|
60
|
-
|
|
61
|
-
expect(h1.textContent).to.equal('Hello page!');
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
});
|