diff options
Diffstat (limited to 'packages/integrations/mdx/test')
5 files changed, 131 insertions, 0 deletions
diff --git a/packages/integrations/mdx/test/fixtures/mdx-component/src/components/Test.mdx b/packages/integrations/mdx/test/fixtures/mdx-component/src/components/Test.mdx new file mode 100644 index 000000000..1c6b33184 --- /dev/null +++ b/packages/integrations/mdx/test/fixtures/mdx-component/src/components/Test.mdx @@ -0,0 +1,3 @@ +# Hello component! + +<div id="foo">bar</div> diff --git a/packages/integrations/mdx/test/fixtures/mdx-component/src/pages/index.astro b/packages/integrations/mdx/test/fixtures/mdx-component/src/pages/index.astro new file mode 100644 index 000000000..ed5ae98a3 --- /dev/null +++ b/packages/integrations/mdx/test/fixtures/mdx-component/src/pages/index.astro @@ -0,0 +1,5 @@ +--- +import Test from '../components/Test.mdx'; +--- + +<Test /> diff --git a/packages/integrations/mdx/test/fixtures/mdx-page/src/pages/index.mdx b/packages/integrations/mdx/test/fixtures/mdx-page/src/pages/index.mdx new file mode 100644 index 000000000..195881e02 --- /dev/null +++ b/packages/integrations/mdx/test/fixtures/mdx-page/src/pages/index.mdx @@ -0,0 +1 @@ +# Hello page! diff --git a/packages/integrations/mdx/test/mdx-component.test.js b/packages/integrations/mdx/test/mdx-component.test.js new file mode 100644 index 000000000..462e86e7b --- /dev/null +++ b/packages/integrations/mdx/test/mdx-component.test.js @@ -0,0 +1,63 @@ +import mdx from '@astrojs/mdx'; + +import { expect } from 'chai'; +import { parseHTML } from 'linkedom' +import { loadFixture } from '../../../astro/test/test-utils.js'; + +describe('MDX Component', () => { + let fixture; + + before(async () => { + fixture = await loadFixture({ + root: new URL('./fixtures/mdx-component/', import.meta.url), + integrations: [ + mdx() + ] + }); + }); + + describe('build', () => { + before(async () => { + await fixture.build(); + }); + + + it('works', async () => { + const html = await fixture.readFile('/index.html'); + const { document } = parseHTML(html); + + const h1 = document.querySelector('h1'); + const foo = document.querySelector('#foo'); + + expect(h1.textContent).to.equal('Hello component!'); + expect(foo.textContent).to.equal('bar'); + }); + }) + + describe('dev', () => { + let devServer; + + before(async () => { + devServer = await fixture.startDevServer(); + }); + + after(async () => { + await devServer.stop(); + }); + + it('works', async () => { + const res = await fixture.fetch('/'); + + expect(res.status).to.equal(200); + + const html = await res.text(); + const { document } = parseHTML(html); + + const h1 = document.querySelector('h1'); + const foo = document.querySelector('#foo'); + + expect(h1.textContent).to.equal('Hello component!'); + expect(foo.textContent).to.equal('bar'); + }); + }) +}) diff --git a/packages/integrations/mdx/test/mdx-page.test.js b/packages/integrations/mdx/test/mdx-page.test.js new file mode 100644 index 000000000..6e4ae79af --- /dev/null +++ b/packages/integrations/mdx/test/mdx-page.test.js @@ -0,0 +1,59 @@ +import mdx from '@astrojs/mdx'; + +import { expect } from 'chai'; +import { parseHTML } from 'linkedom' +import { loadFixture } from '../../../astro/test/test-utils.js'; + +describe('MDX Page', () => { + let fixture; + + before(async () => { + fixture = await loadFixture({ + root: new URL('./fixtures/mdx-page/', import.meta.url), + integrations: [ + mdx() + ] + }); + }); + + describe('build', () => { + before(async () => { + await fixture.build(); + }); + + + it('works', async () => { + const html = await fixture.readFile('/index.html'); + const { document } = parseHTML(html); + + const h1 = document.querySelector('h1'); + + expect(h1.textContent).to.equal('Hello page!'); + }); + }) + + describe('dev', () => { + let devServer; + + before(async () => { + devServer = await fixture.startDevServer(); + }); + + after(async () => { + await devServer.stop(); + }); + + it('works', async () => { + const res = await fixture.fetch('/'); + + expect(res.status).to.equal(200); + + const html = await res.text(); + const { document } = parseHTML(html); + + const h1 = document.querySelector('h1'); + + expect(h1.textContent).to.equal('Hello page!'); + }); + }) +}) |