@astrojs/mdx 0.0.0-imgcache-20220929145446

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.
Files changed (90) hide show
  1. package/.turbo/turbo-build.log +5 -0
  2. package/CHANGELOG.md +209 -0
  3. package/LICENSE +61 -0
  4. package/README.md +527 -0
  5. package/dist/index.d.ts +15 -0
  6. package/dist/index.js +131 -0
  7. package/dist/plugins.d.ts +11 -0
  8. package/dist/plugins.js +214 -0
  9. package/dist/rehype-collect-headings.d.ts +6 -0
  10. package/dist/rehype-collect-headings.js +47 -0
  11. package/dist/remark-prism.d.ts +2 -0
  12. package/dist/remark-prism.js +17 -0
  13. package/dist/remark-shiki.d.ts +3 -0
  14. package/dist/remark-shiki.js +69 -0
  15. package/dist/utils.d.ts +18 -0
  16. package/dist/utils.js +74 -0
  17. package/package.json +71 -0
  18. package/src/index.ts +167 -0
  19. package/src/plugins.ts +273 -0
  20. package/src/rehype-collect-headings.ts +50 -0
  21. package/src/remark-prism.ts +18 -0
  22. package/src/remark-shiki.ts +95 -0
  23. package/src/utils.ts +97 -0
  24. package/test/fixtures/mdx-component/src/components/Test.mdx +3 -0
  25. package/test/fixtures/mdx-component/src/pages/glob.astro +11 -0
  26. package/test/fixtures/mdx-component/src/pages/index.astro +5 -0
  27. package/test/fixtures/mdx-escape/src/components/Em.astro +7 -0
  28. package/test/fixtures/mdx-escape/src/components/P.astro +1 -0
  29. package/test/fixtures/mdx-escape/src/components/Title.astro +1 -0
  30. package/test/fixtures/mdx-escape/src/pages/html-tag.mdx +5 -0
  31. package/test/fixtures/mdx-escape/src/pages/index.mdx +13 -0
  32. package/test/fixtures/mdx-frontmatter/src/layouts/Base.astro +38 -0
  33. package/test/fixtures/mdx-frontmatter/src/pages/glob.json.js +9 -0
  34. package/test/fixtures/mdx-frontmatter/src/pages/index.mdx +10 -0
  35. package/test/fixtures/mdx-frontmatter/src/pages/with-headings.mdx +7 -0
  36. package/test/fixtures/mdx-frontmatter-injection/astro.config.mjs +12 -0
  37. package/test/fixtures/mdx-frontmatter-injection/node_modules/.bin/astro +17 -0
  38. package/test/fixtures/mdx-frontmatter-injection/package.json +12 -0
  39. package/test/fixtures/mdx-frontmatter-injection/src/layouts/Base.astro +17 -0
  40. package/test/fixtures/mdx-frontmatter-injection/src/markdown-plugins.mjs +20 -0
  41. package/test/fixtures/mdx-frontmatter-injection/src/pages/glob.json.js +6 -0
  42. package/test/fixtures/mdx-frontmatter-injection/src/pages/page-1.mdx +7 -0
  43. package/test/fixtures/mdx-frontmatter-injection/src/pages/page-2.mdx +23 -0
  44. package/test/fixtures/mdx-frontmatter-injection/src/pages/with-overrides.mdx +7 -0
  45. package/test/fixtures/mdx-get-headings/src/pages/pages.json.js +11 -0
  46. package/test/fixtures/mdx-get-headings/src/pages/test-with-jsx-expressions.mdx +8 -0
  47. package/test/fixtures/mdx-get-headings/src/pages/test.mdx +9 -0
  48. package/test/fixtures/mdx-get-static-paths/src/content/1.mdx +5 -0
  49. package/test/fixtures/mdx-get-static-paths/src/pages/[slug].astro +34 -0
  50. package/test/fixtures/mdx-namespace/astro.config.mjs +6 -0
  51. package/test/fixtures/mdx-namespace/node_modules/.bin/astro +17 -0
  52. package/test/fixtures/mdx-namespace/package.json +10 -0
  53. package/test/fixtures/mdx-namespace/src/components/Component.jsx +6 -0
  54. package/test/fixtures/mdx-namespace/src/pages/object.mdx +3 -0
  55. package/test/fixtures/mdx-namespace/src/pages/star.mdx +3 -0
  56. package/test/fixtures/mdx-page/astro.config.ts +5 -0
  57. package/test/fixtures/mdx-page/node_modules/.bin/astro +17 -0
  58. package/test/fixtures/mdx-page/package.json +9 -0
  59. package/test/fixtures/mdx-page/src/pages/index.mdx +3 -0
  60. package/test/fixtures/mdx-page/src/styles.css +3 -0
  61. package/test/fixtures/mdx-plugins/src/pages/with-plugins.mdx +19 -0
  62. package/test/fixtures/mdx-plus-react/astro.config.mjs +6 -0
  63. package/test/fixtures/mdx-plus-react/node_modules/.bin/astro +17 -0
  64. package/test/fixtures/mdx-plus-react/package.json +10 -0
  65. package/test/fixtures/mdx-plus-react/src/components/Component.jsx +5 -0
  66. package/test/fixtures/mdx-plus-react/src/pages/index.astro +11 -0
  67. package/test/fixtures/mdx-syntax-hightlighting/src/pages/index.mdx +9 -0
  68. package/test/fixtures/mdx-url-export/src/pages/pages.json.js +9 -0
  69. package/test/fixtures/mdx-url-export/src/pages/test-1.mdx +1 -0
  70. package/test/fixtures/mdx-url-export/src/pages/test-2.mdx +1 -0
  71. package/test/fixtures/mdx-url-export/src/pages/with-url-override.mdx +3 -0
  72. package/test/fixtures/mdx-vite-env-vars/astro.config.mjs +9 -0
  73. package/test/fixtures/mdx-vite-env-vars/node_modules/.bin/astro +17 -0
  74. package/test/fixtures/mdx-vite-env-vars/package.json +7 -0
  75. package/test/fixtures/mdx-vite-env-vars/src/pages/frontmatter.json.js +7 -0
  76. package/test/fixtures/mdx-vite-env-vars/src/pages/vite-env-vars.mdx +38 -0
  77. package/test/mdx-component.test.js +112 -0
  78. package/test/mdx-escape.test.js +32 -0
  79. package/test/mdx-frontmatter-injection.test.js +56 -0
  80. package/test/mdx-frontmatter.test.js +77 -0
  81. package/test/mdx-get-headings.test.js +60 -0
  82. package/test/mdx-get-static-paths.test.js +32 -0
  83. package/test/mdx-namespace.test.js +83 -0
  84. package/test/mdx-page.test.js +64 -0
  85. package/test/mdx-plugins.test.js +211 -0
  86. package/test/mdx-plus-react.test.js +25 -0
  87. package/test/mdx-syntax-highlighting.test.js +91 -0
  88. package/test/mdx-url-export.test.js +28 -0
  89. package/test/mdx-vite-env-vars.test.js +54 -0
  90. package/tsconfig.json +10 -0
@@ -0,0 +1,112 @@
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 Component', () => {
8
+ let fixture;
9
+
10
+ before(async () => {
11
+ fixture = await loadFixture({
12
+ root: new URL('./fixtures/mdx-component/', import.meta.url),
13
+ integrations: [mdx()],
14
+ });
15
+ });
16
+
17
+ describe('build', () => {
18
+ before(async () => {
19
+ await fixture.build();
20
+ });
21
+
22
+ it('supports top-level imports', async () => {
23
+ const html = await fixture.readFile('/index.html');
24
+ const { document } = parseHTML(html);
25
+
26
+ const h1 = document.querySelector('h1');
27
+ const foo = document.querySelector('#foo');
28
+
29
+ expect(h1.textContent).to.equal('Hello component!');
30
+ expect(foo.textContent).to.equal('bar');
31
+ });
32
+
33
+ it('supports glob imports - <Component.default />', async () => {
34
+ const html = await fixture.readFile('/glob/index.html');
35
+ const { document } = parseHTML(html);
36
+
37
+ const h1 = document.querySelector('[data-default-export] h1');
38
+ const foo = document.querySelector('[data-default-export] #foo');
39
+
40
+ expect(h1.textContent).to.equal('Hello component!');
41
+ expect(foo.textContent).to.equal('bar');
42
+ });
43
+
44
+ it('supports glob imports - <Content />', async () => {
45
+ const html = await fixture.readFile('/glob/index.html');
46
+ const { document } = parseHTML(html);
47
+
48
+ const h1 = document.querySelector('[data-content-export] h1');
49
+ const foo = document.querySelector('[data-content-export] #foo');
50
+
51
+ expect(h1.textContent).to.equal('Hello component!');
52
+ expect(foo.textContent).to.equal('bar');
53
+ });
54
+ });
55
+
56
+ describe('dev', () => {
57
+ let devServer;
58
+
59
+ before(async () => {
60
+ devServer = await fixture.startDevServer();
61
+ });
62
+
63
+ after(async () => {
64
+ await devServer.stop();
65
+ });
66
+
67
+ it('supports top-level imports', async () => {
68
+ const res = await fixture.fetch('/');
69
+
70
+ expect(res.status).to.equal(200);
71
+
72
+ const html = await res.text();
73
+ const { document } = parseHTML(html);
74
+
75
+ const h1 = document.querySelector('h1');
76
+ const foo = document.querySelector('#foo');
77
+
78
+ expect(h1.textContent).to.equal('Hello component!');
79
+ expect(foo.textContent).to.equal('bar');
80
+ });
81
+
82
+ it('supports glob imports - <Component.default />', async () => {
83
+ const res = await fixture.fetch('/glob');
84
+
85
+ expect(res.status).to.equal(200);
86
+
87
+ const html = await res.text();
88
+ const { document } = parseHTML(html);
89
+
90
+ const h1 = document.querySelector('[data-default-export] h1');
91
+ const foo = document.querySelector('[data-default-export] #foo');
92
+
93
+ expect(h1.textContent).to.equal('Hello component!');
94
+ expect(foo.textContent).to.equal('bar');
95
+ });
96
+
97
+ it('supports glob imports - <Content />', async () => {
98
+ const res = await fixture.fetch('/glob');
99
+
100
+ expect(res.status).to.equal(200);
101
+
102
+ const html = await res.text();
103
+ const { document } = parseHTML(html);
104
+
105
+ const h1 = document.querySelector('[data-content-export] h1');
106
+ const foo = document.querySelector('[data-content-export] #foo');
107
+
108
+ expect(h1.textContent).to.equal('Hello component!');
109
+ expect(foo.textContent).to.equal('bar');
110
+ });
111
+ });
112
+ });
@@ -0,0 +1,32 @@
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
+ const FIXTURE_ROOT = new URL('./fixtures/mdx-escape/', import.meta.url);
8
+
9
+ describe('MDX frontmatter', () => {
10
+ let fixture;
11
+ before(async () => {
12
+ fixture = await loadFixture({
13
+ root: FIXTURE_ROOT,
14
+ integrations: [mdx()],
15
+ });
16
+ await fixture.build();
17
+ });
18
+
19
+ it('does not have unescaped HTML at top-level', async () => {
20
+ const html = await fixture.readFile('/index.html');
21
+ const { document } = parseHTML(html);
22
+
23
+ expect(document.body.textContent).to.not.include('<em');
24
+ });
25
+
26
+ it('does not have unescaped HTML inside html tags', async () => {
27
+ const html = await fixture.readFile('/html-tag/index.html');
28
+ const { document } = parseHTML(html);
29
+
30
+ expect(document.body.textContent).to.not.include('<em');
31
+ });
32
+ });
@@ -0,0 +1,56 @@
1
+ import { expect } from 'chai';
2
+ import { parseHTML } from 'linkedom';
3
+ import { loadFixture } from '../../../astro/test/test-utils.js';
4
+
5
+ const FIXTURE_ROOT = new URL('./fixtures/mdx-frontmatter-injection/', import.meta.url);
6
+
7
+ describe('MDX frontmatter injection', () => {
8
+ let fixture;
9
+
10
+ before(async () => {
11
+ fixture = await loadFixture({
12
+ root: FIXTURE_ROOT,
13
+ });
14
+ await fixture.build();
15
+ });
16
+
17
+ it('remark supports custom vfile data - get title', async () => {
18
+ const frontmatterByPage = JSON.parse(await fixture.readFile('/glob.json'));
19
+ const titles = frontmatterByPage.map((frontmatter = {}) => frontmatter.title);
20
+ expect(titles).to.contain('Page 1');
21
+ expect(titles).to.contain('Page 2');
22
+ });
23
+
24
+ it('rehype supports custom vfile data - reading time', async () => {
25
+ const frontmatterByPage = JSON.parse(await fixture.readFile('/glob.json'));
26
+ const readingTimes = frontmatterByPage.map(
27
+ (frontmatter = {}) => frontmatter.injectedReadingTime
28
+ );
29
+ expect(readingTimes.length).to.be.greaterThan(0);
30
+ for (let readingTime of readingTimes) {
31
+ expect(readingTime).to.not.be.null;
32
+ expect(readingTime.text).match(/^\d+ min read/);
33
+ }
34
+ });
35
+
36
+ it('overrides injected frontmatter with user frontmatter', async () => {
37
+ const frontmatterByPage = JSON.parse(await fixture.readFile('/glob.json'));
38
+ const readingTimes = frontmatterByPage.map(
39
+ (frontmatter = {}) => frontmatter.injectedReadingTime?.text
40
+ );
41
+ const titles = frontmatterByPage.map((frontmatter = {}) => frontmatter.title);
42
+ expect(titles).to.contain('Overridden title');
43
+ expect(readingTimes).to.contain('1000 min read');
44
+ });
45
+
46
+ it('passes injected frontmatter to layouts', async () => {
47
+ const html1 = await fixture.readFile('/page-1/index.html');
48
+ const html2 = await fixture.readFile('/page-2/index.html');
49
+
50
+ const title1 = parseHTML(html1).document.querySelector('title');
51
+ const title2 = parseHTML(html2).document.querySelector('title');
52
+
53
+ expect(title1.innerHTML).to.equal('Page 1');
54
+ expect(title2.innerHTML).to.equal('Page 2');
55
+ });
56
+ });
@@ -0,0 +1,77 @@
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
+ const FIXTURE_ROOT = new URL('./fixtures/mdx-frontmatter/', import.meta.url);
8
+
9
+ describe('MDX frontmatter', () => {
10
+ let fixture;
11
+ before(async () => {
12
+ fixture = await loadFixture({
13
+ root: FIXTURE_ROOT,
14
+ integrations: [mdx()],
15
+ });
16
+ await fixture.build();
17
+ });
18
+ it('builds when "frontmatter.property" is in JSX expression', async () => {
19
+ expect(true).to.equal(true);
20
+ });
21
+
22
+ it('extracts frontmatter to "frontmatter" export', async () => {
23
+ const { titles } = JSON.parse(await fixture.readFile('/glob.json'));
24
+ expect(titles).to.include('Using YAML frontmatter');
25
+ });
26
+
27
+ it('renders layout from "layout" frontmatter property', async () => {
28
+ const html = await fixture.readFile('/index.html');
29
+ const { document } = parseHTML(html);
30
+
31
+ const layoutParagraph = document.querySelector('[data-layout-rendered]');
32
+
33
+ expect(layoutParagraph).to.not.be.null;
34
+ });
35
+
36
+ it('passes frontmatter to layout via "content" and "frontmatter" props', async () => {
37
+ const html = await fixture.readFile('/index.html');
38
+ const { document } = parseHTML(html);
39
+
40
+ const contentTitle = document.querySelector('[data-content-title]');
41
+ const frontmatterTitle = document.querySelector('[data-frontmatter-title]');
42
+
43
+ expect(contentTitle.textContent).to.equal('Using YAML frontmatter');
44
+ expect(frontmatterTitle.textContent).to.equal('Using YAML frontmatter');
45
+ });
46
+
47
+ it('passes headings to layout via "headings" prop', async () => {
48
+ const html = await fixture.readFile('/with-headings/index.html');
49
+ const { document } = parseHTML(html);
50
+
51
+ const headingSlugs = [...document.querySelectorAll('[data-headings] > li')].map(
52
+ (el) => el.textContent
53
+ );
54
+
55
+ expect(headingSlugs.length).to.be.greaterThan(0);
56
+ expect(headingSlugs).to.contain('section-1');
57
+ expect(headingSlugs).to.contain('section-2');
58
+ });
59
+
60
+ it('passes "file" and "url" to layout', async () => {
61
+ const html = await fixture.readFile('/with-headings/index.html');
62
+ const { document } = parseHTML(html);
63
+
64
+ const frontmatterFile = document.querySelector('[data-frontmatter-file]')?.textContent;
65
+ const frontmatterUrl = document.querySelector('[data-frontmatter-url]')?.textContent;
66
+ const file = document.querySelector('[data-file]')?.textContent;
67
+ const url = document.querySelector('[data-url]')?.textContent;
68
+
69
+ expect(frontmatterFile?.endsWith('with-headings.mdx')).to.equal(
70
+ true,
71
+ '"file" prop does not end with correct path or is undefined'
72
+ );
73
+ expect(frontmatterUrl).to.equal('/with-headings');
74
+ expect(file).to.equal(frontmatterFile);
75
+ expect(url).to.equal(frontmatterUrl);
76
+ });
77
+ });
@@ -0,0 +1,60 @@
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 getHeadings', () => {
8
+ let fixture;
9
+
10
+ before(async () => {
11
+ fixture = await loadFixture({
12
+ root: new URL('./fixtures/mdx-get-headings/', import.meta.url),
13
+ integrations: [mdx()],
14
+ });
15
+
16
+ await fixture.build();
17
+ });
18
+
19
+ it('adds anchor IDs to headings', async () => {
20
+ const html = await fixture.readFile('/test/index.html');
21
+ const { document } = parseHTML(html);
22
+
23
+ const h2Ids = document.querySelectorAll('h2').map((el) => el?.id);
24
+ const h3Ids = document.querySelectorAll('h3').map((el) => el?.id);
25
+ expect(document.querySelector('h1').id).to.equal('heading-test');
26
+ expect(h2Ids).to.contain('section-1');
27
+ expect(h2Ids).to.contain('section-2');
28
+ expect(h3Ids).to.contain('subsection-1');
29
+ expect(h3Ids).to.contain('subsection-2');
30
+ });
31
+
32
+ it('generates correct getHeadings() export', async () => {
33
+ const { headingsByPage } = JSON.parse(await fixture.readFile('/pages.json'));
34
+ // TODO: make this a snapshot test :)
35
+ expect(JSON.stringify(headingsByPage['./test.mdx'])).to.equal(
36
+ JSON.stringify([
37
+ { depth: 1, slug: 'heading-test', text: 'Heading test' },
38
+ { depth: 2, slug: 'section-1', text: 'Section 1' },
39
+ { depth: 3, slug: 'subsection-1', text: 'Subsection 1' },
40
+ { depth: 3, slug: 'subsection-2', text: 'Subsection 2' },
41
+ { depth: 2, slug: 'section-2', text: 'Section 2' },
42
+ ])
43
+ );
44
+ });
45
+
46
+ it('generates correct getHeadings() export for JSX expressions', async () => {
47
+ const { headingsByPage } = JSON.parse(await fixture.readFile('/pages.json'));
48
+ expect(JSON.stringify(headingsByPage['./test-with-jsx-expressions.mdx'])).to.equal(
49
+ JSON.stringify([
50
+ {
51
+ depth: 1,
52
+ slug: 'heading-test-with-jsx-expressions',
53
+ text: 'Heading test with JSX expressions',
54
+ },
55
+ { depth: 2, slug: 'h2title', text: 'h2Title' },
56
+ { depth: 3, slug: 'h3title', text: 'h3Title' },
57
+ ])
58
+ );
59
+ });
60
+ });
@@ -0,0 +1,32 @@
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
+ });
@@ -0,0 +1,83 @@
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
+ });
@@ -0,0 +1,64 @@
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
+ });