diff options
author | 2023-03-27 18:04:37 -0400 | |
---|---|---|
committer | 2023-03-27 18:04:37 -0400 | |
commit | 7c439868a3bc7d466418da9af669966014f3d9fe (patch) | |
tree | af8a8624a96ed9988f475beaed840df28d864646 /packages/integrations/markdoc/test | |
parent | c13d428a7804b5b9809dbea94a1b17c36714a1e1 (diff) | |
download | astro-7c439868a3bc7d466418da9af669966014f3d9fe.tar.gz astro-7c439868a3bc7d466418da9af669966014f3d9fe.tar.zst astro-7c439868a3bc7d466418da9af669966014f3d9fe.zip |
[Markdoc] New config format with runtime variable support! (#6653)
* deps: esbuild
* feat: support direct component imports for render!
* deps: add devalue back
* refactor: remove unused components prop
* refactor: load experimental assets config separately
* fix: upate Content type def to support props
* refactor: replace astro stub with inline data
* feat: pass through viteId to getRenderMod
* fix: add back $entry var with defaults convention
* chore: remove unneeded validateRenderProps
* chore: remove uneeded validateComponents
* fix: remove userMarkdocConfig prop
* chore: add helpful error for legacy config
* deps: kleur
* fix: add back `isCapitalized`
* fix: log instead of throw to avoid scary stacktrace
* chore: delete more old logic (nice)
* chore: delete MORE unused utils
* chore: comment on separate assets config
* chore: remove console.log
* chore: general code cleanup
* test: new render config
* docs: new README
* fix: add expect-error on astro:assets
* feat: add defineMarkdocConfig helper
* docs: update example README
* test: add runtime variable
* chore: lint
* chore: changeset
* chore: add component import deletion
* docs: add notes on Vite fork
* fix: astro check
* chore: add `.mts` to markdoc config formats
Diffstat (limited to 'packages/integrations/markdoc/test')
23 files changed, 274 insertions, 186 deletions
diff --git a/packages/integrations/markdoc/test/content-collections.test.js b/packages/integrations/markdoc/test/content-collections.test.js index 5822c181a..aad389e0c 100644 --- a/packages/integrations/markdoc/test/content-collections.test.js +++ b/packages/integrations/markdoc/test/content-collections.test.js @@ -1,4 +1,3 @@ -import { parseHTML } from 'linkedom'; import { parse as parseDevalue } from 'devalue'; import { expect } from 'chai'; import { loadFixture, fixLineEndings } from '../../../astro/test/test-utils.js'; @@ -37,70 +36,20 @@ describe('Markdoc - Content Collections', () => { it('loads entry', async () => { const res = await baseFixture.fetch('/entry.json'); const post = parseDevalue(await res.text()); - expect(formatPost(post)).to.deep.equal(simplePostEntry); + expect(formatPost(post)).to.deep.equal(post1Entry); }); it('loads collection', async () => { const res = await baseFixture.fetch('/collection.json'); const posts = parseDevalue(await res.text()); expect(posts).to.not.be.null; + expect(posts.sort().map((post) => formatPost(post))).to.deep.equal([ - simplePostEntry, - withComponentsEntry, - withConfigEntry, + post1Entry, + post2Entry, + post3Entry, ]); }); - - it('renders content - simple', async () => { - const res = await baseFixture.fetch('/content-simple'); - const html = await res.text(); - const { document } = parseHTML(html); - const h2 = document.querySelector('h2'); - expect(h2.textContent).to.equal('Simple post'); - const p = document.querySelector('p'); - expect(p.textContent).to.equal('This is a simple Markdoc post.'); - }); - - it('renders content - with config', async () => { - const fixture = await getFixtureWithConfig(); - const server = await fixture.startDevServer(); - - const res = await fixture.fetch('/content-with-config'); - const html = await res.text(); - const { document } = parseHTML(html); - const h2 = document.querySelector('h2'); - expect(h2.textContent).to.equal('Post with config'); - const textContent = html; - - expect(textContent).to.not.include('Hello'); - expect(textContent).to.include('Hola'); - expect(textContent).to.include(`Konnichiwa`); - - await server.stop(); - }); - - it('renders content - with components', async () => { - const fixture = await getFixtureWithComponents(); - const server = await fixture.startDevServer(); - - const res = await fixture.fetch('/content-with-components'); - const html = await res.text(); - const { document } = parseHTML(html); - const h2 = document.querySelector('h2'); - expect(h2.textContent).to.equal('Post with components'); - - // Renders custom shortcode component - const marquee = document.querySelector('marquee'); - expect(marquee).to.not.be.null; - expect(marquee.hasAttribute('data-custom-marquee')).to.equal(true); - - // Renders Astro Code component - const pre = document.querySelector('pre'); - expect(pre).to.not.be.null; - expect(pre.className).to.equal('astro-code'); - - await server.stop(); - }); }); describe('build', () => { @@ -111,7 +60,7 @@ describe('Markdoc - Content Collections', () => { it('loads entry', async () => { const res = await baseFixture.readFile('/entry.json'); const post = parseDevalue(res); - expect(formatPost(post)).to.deep.equal(simplePostEntry); + expect(formatPost(post)).to.deep.equal(post1Entry); }); it('loads collection', async () => { @@ -119,140 +68,43 @@ describe('Markdoc - Content Collections', () => { const posts = parseDevalue(res); expect(posts).to.not.be.null; expect(posts.sort().map((post) => formatPost(post))).to.deep.equal([ - simplePostEntry, - withComponentsEntry, - withConfigEntry, + post1Entry, + post2Entry, + post3Entry, ]); }); - - it('renders content - simple', async () => { - const html = await baseFixture.readFile('/content-simple/index.html'); - const { document } = parseHTML(html); - const h2 = document.querySelector('h2'); - expect(h2.textContent).to.equal('Simple post'); - const p = document.querySelector('p'); - expect(p.textContent).to.equal('This is a simple Markdoc post.'); - }); - - it('renders content - with config', async () => { - const fixture = await getFixtureWithConfig(); - await fixture.build(); - - const html = await fixture.readFile('/content-with-config/index.html'); - const { document } = parseHTML(html); - const h2 = document.querySelector('h2'); - expect(h2.textContent).to.equal('Post with config'); - const textContent = html; - - expect(textContent).to.not.include('Hello'); - expect(textContent).to.include('Hola'); - expect(textContent).to.include(`Konnichiwa`); - }); - - it('renders content - with components', async () => { - const fixture = await getFixtureWithComponents(); - await fixture.build(); - - const html = await fixture.readFile('/content-with-components/index.html'); - const { document } = parseHTML(html); - const h2 = document.querySelector('h2'); - expect(h2.textContent).to.equal('Post with components'); - - // Renders custom shortcode component - const marquee = document.querySelector('marquee'); - expect(marquee).to.not.be.null; - expect(marquee.hasAttribute('data-custom-marquee')).to.equal(true); - - // Renders Astro Code component - const pre = document.querySelector('pre'); - expect(pre).to.not.be.null; - expect(pre.className).to.equal('astro-code'); - }); }); }); -function getFixtureWithConfig() { - return loadFixture({ - root, - integrations: [ - markdoc({ - variables: { - countries: ['ES', 'JP'], - }, - functions: { - includes: { - transform(parameters) { - const [array, value] = Object.values(parameters); - return Array.isArray(array) ? array.includes(value) : false; - }, - }, - }, - }), - ], - }); -} - -function getFixtureWithComponents() { - return loadFixture({ - root, - integrations: [ - markdoc({ - nodes: { - fence: { - render: 'Code', - attributes: { - language: { type: String }, - content: { type: String }, - }, - }, - }, - tags: { - mq: { - render: 'CustomMarquee', - attributes: { - direction: { - type: String, - default: 'left', - matches: ['left', 'right', 'up', 'down'], - errorLevel: 'critical', - }, - }, - }, - }, - }), - ], - }); -} - -const simplePostEntry = { - id: 'simple.mdoc', - slug: 'simple', +const post1Entry = { + id: 'post-1.mdoc', + slug: 'post-1', collection: 'blog', data: { schemaWorks: true, - title: 'Simple post', + title: 'Post 1', }, - body: '\n## Simple post\n\nThis is a simple Markdoc post.\n', + body: '\n## Post 1\n\nThis is the contents of post 1.\n', }; -const withComponentsEntry = { - id: 'with-components.mdoc', - slug: 'with-components', +const post2Entry = { + id: 'post-2.mdoc', + slug: 'post-2', collection: 'blog', data: { schemaWorks: true, - title: 'Post with components', + title: 'Post 2', }, - body: '\n## Post with components\n\nThis uses a custom marquee component with a shortcode:\n\n{% mq direction="right" %}\nI\'m a marquee too!\n{% /mq %}\n\nAnd a code component for code blocks:\n\n```js\nconst isRenderedWithShiki = true;\n```\n', + body: '\n## Post 2\n\nThis is the contents of post 2.\n', }; -const withConfigEntry = { - id: 'with-config.mdoc', - slug: 'with-config', +const post3Entry = { + id: 'post-3.mdoc', + slug: 'post-3', collection: 'blog', data: { schemaWorks: true, - title: 'Post with config', + title: 'Post 3', }, - body: '\n## Post with config\n\n{% if includes($countries, "EN") %} Hello {% /if %}\n{% if includes($countries, "ES") %} Hola {% /if %}\n{% if includes($countries, "JP") %} Konnichiwa {% /if %}\n', + body: '\n## Post 3\n\nThis is the contents of post 3.\n', }; diff --git a/packages/integrations/markdoc/test/fixtures/content-collections/package.json b/packages/integrations/markdoc/test/fixtures/content-collections/package.json index a6403f49b..370b87957 100644 --- a/packages/integrations/markdoc/test/fixtures/content-collections/package.json +++ b/packages/integrations/markdoc/test/fixtures/content-collections/package.json @@ -4,10 +4,6 @@ "private": true, "dependencies": { "@astrojs/markdoc": "workspace:*", - "@markdoc/markdoc": "^0.2.2", "astro": "workspace:*" - }, - "devDependencies": { - "shiki": "^0.11.1" } } diff --git a/packages/integrations/markdoc/test/fixtures/content-collections/src/content/blog/post-1.mdoc b/packages/integrations/markdoc/test/fixtures/content-collections/src/content/blog/post-1.mdoc new file mode 100644 index 000000000..06c900963 --- /dev/null +++ b/packages/integrations/markdoc/test/fixtures/content-collections/src/content/blog/post-1.mdoc @@ -0,0 +1,7 @@ +--- +title: Post 1 +--- + +## Post 1 + +This is the contents of post 1. diff --git a/packages/integrations/markdoc/test/fixtures/content-collections/src/content/blog/post-2.mdoc b/packages/integrations/markdoc/test/fixtures/content-collections/src/content/blog/post-2.mdoc new file mode 100644 index 000000000..cf4dc162f --- /dev/null +++ b/packages/integrations/markdoc/test/fixtures/content-collections/src/content/blog/post-2.mdoc @@ -0,0 +1,7 @@ +--- +title: Post 2 +--- + +## Post 2 + +This is the contents of post 2. diff --git a/packages/integrations/markdoc/test/fixtures/content-collections/src/content/blog/post-3.mdoc b/packages/integrations/markdoc/test/fixtures/content-collections/src/content/blog/post-3.mdoc new file mode 100644 index 000000000..6c601eb65 --- /dev/null +++ b/packages/integrations/markdoc/test/fixtures/content-collections/src/content/blog/post-3.mdoc @@ -0,0 +1,7 @@ +--- +title: Post 3 +--- + +## Post 3 + +This is the contents of post 3. diff --git a/packages/integrations/markdoc/test/fixtures/content-collections/src/pages/entry.json.js b/packages/integrations/markdoc/test/fixtures/content-collections/src/pages/entry.json.js index 842291826..7899a757a 100644 --- a/packages/integrations/markdoc/test/fixtures/content-collections/src/pages/entry.json.js +++ b/packages/integrations/markdoc/test/fixtures/content-collections/src/pages/entry.json.js @@ -3,7 +3,7 @@ import { stringify } from 'devalue'; import { stripRenderFn } from '../../utils.js'; export async function get() { - const post = await getEntryBySlug('blog', 'simple'); + const post = await getEntryBySlug('blog', 'post-1'); return { body: stringify(stripRenderFn(post)), }; diff --git a/packages/integrations/markdoc/test/fixtures/render-simple/astro.config.mjs b/packages/integrations/markdoc/test/fixtures/render-simple/astro.config.mjs new file mode 100644 index 000000000..29d846359 --- /dev/null +++ b/packages/integrations/markdoc/test/fixtures/render-simple/astro.config.mjs @@ -0,0 +1,7 @@ +import { defineConfig } from 'astro/config'; +import markdoc from '@astrojs/markdoc'; + +// https://astro.build/config +export default defineConfig({ + integrations: [markdoc()], +}); diff --git a/packages/integrations/markdoc/test/fixtures/render-simple/package.json b/packages/integrations/markdoc/test/fixtures/render-simple/package.json new file mode 100644 index 000000000..9354cdc58 --- /dev/null +++ b/packages/integrations/markdoc/test/fixtures/render-simple/package.json @@ -0,0 +1,9 @@ +{ + "name": "@test/markdoc-render-simple", + "version": "0.0.0", + "private": true, + "dependencies": { + "@astrojs/markdoc": "workspace:*", + "astro": "workspace:*" + } +} diff --git a/packages/integrations/markdoc/test/fixtures/content-collections/src/content/blog/simple.mdoc b/packages/integrations/markdoc/test/fixtures/render-simple/src/content/blog/simple.mdoc index 557f7b8e5..557f7b8e5 100644 --- a/packages/integrations/markdoc/test/fixtures/content-collections/src/content/blog/simple.mdoc +++ b/packages/integrations/markdoc/test/fixtures/render-simple/src/content/blog/simple.mdoc diff --git a/packages/integrations/markdoc/test/fixtures/content-collections/src/pages/content-simple.astro b/packages/integrations/markdoc/test/fixtures/render-simple/src/pages/index.astro index effbbee1c..940eef154 100644 --- a/packages/integrations/markdoc/test/fixtures/content-collections/src/pages/content-simple.astro +++ b/packages/integrations/markdoc/test/fixtures/render-simple/src/pages/index.astro @@ -1,5 +1,6 @@ --- import { getEntryBySlug } from "astro:content"; + const post = await getEntryBySlug('blog', 'simple'); const { Content } = await post.render(); --- @@ -10,7 +11,7 @@ const { Content } = await post.render(); <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <title>Content - Simple</title> + <title>Content</title> </head> <body> <Content /> diff --git a/packages/integrations/markdoc/test/fixtures/render-with-components/astro.config.mjs b/packages/integrations/markdoc/test/fixtures/render-with-components/astro.config.mjs new file mode 100644 index 000000000..29d846359 --- /dev/null +++ b/packages/integrations/markdoc/test/fixtures/render-with-components/astro.config.mjs @@ -0,0 +1,7 @@ +import { defineConfig } from 'astro/config'; +import markdoc from '@astrojs/markdoc'; + +// https://astro.build/config +export default defineConfig({ + integrations: [markdoc()], +}); diff --git a/packages/integrations/markdoc/test/fixtures/render-with-components/markdoc.config.mjs b/packages/integrations/markdoc/test/fixtures/render-with-components/markdoc.config.mjs new file mode 100644 index 000000000..ada03f5f4 --- /dev/null +++ b/packages/integrations/markdoc/test/fixtures/render-with-components/markdoc.config.mjs @@ -0,0 +1,28 @@ +import Code from './src/components/Code.astro'; +import CustomMarquee from './src/components/CustomMarquee.astro'; +import { defineMarkdocConfig } from '@astrojs/markdoc/config'; + +export default defineMarkdocConfig({ + nodes: { + fence: { + render: Code, + attributes: { + language: { type: String }, + content: { type: String }, + }, + }, + }, + tags: { + mq: { + render: CustomMarquee, + attributes: { + direction: { + type: String, + default: 'left', + matches: ['left', 'right', 'up', 'down'], + errorLevel: 'critical', + }, + }, + }, + }, +}) diff --git a/packages/integrations/markdoc/test/fixtures/render-with-components/package.json b/packages/integrations/markdoc/test/fixtures/render-with-components/package.json new file mode 100644 index 000000000..f14c97f0f --- /dev/null +++ b/packages/integrations/markdoc/test/fixtures/render-with-components/package.json @@ -0,0 +1,12 @@ +{ + "name": "@test/markdoc-render-with-components", + "version": "0.0.0", + "private": true, + "dependencies": { + "@astrojs/markdoc": "workspace:*", + "astro": "workspace:*" + }, + "devDependencies": { + "shiki": "^0.11.1" + } +} diff --git a/packages/integrations/markdoc/test/fixtures/content-collections/src/components/Code.astro b/packages/integrations/markdoc/test/fixtures/render-with-components/src/components/Code.astro index 18bf1399f..18bf1399f 100644 --- a/packages/integrations/markdoc/test/fixtures/content-collections/src/components/Code.astro +++ b/packages/integrations/markdoc/test/fixtures/render-with-components/src/components/Code.astro diff --git a/packages/integrations/markdoc/test/fixtures/content-collections/src/components/CustomMarquee.astro b/packages/integrations/markdoc/test/fixtures/render-with-components/src/components/CustomMarquee.astro index 3108b9973..3108b9973 100644 --- a/packages/integrations/markdoc/test/fixtures/content-collections/src/components/CustomMarquee.astro +++ b/packages/integrations/markdoc/test/fixtures/render-with-components/src/components/CustomMarquee.astro diff --git a/packages/integrations/markdoc/test/fixtures/content-collections/src/content/blog/with-components.mdoc b/packages/integrations/markdoc/test/fixtures/render-with-components/src/content/blog/with-components.mdoc index 2c9bae972..2c9bae972 100644 --- a/packages/integrations/markdoc/test/fixtures/content-collections/src/content/blog/with-components.mdoc +++ b/packages/integrations/markdoc/test/fixtures/render-with-components/src/content/blog/with-components.mdoc diff --git a/packages/integrations/markdoc/test/fixtures/content-collections/src/pages/content-with-components.astro b/packages/integrations/markdoc/test/fixtures/render-with-components/src/pages/index.astro index dfb9b1de5..52239acce 100644 --- a/packages/integrations/markdoc/test/fixtures/content-collections/src/pages/content-with-components.astro +++ b/packages/integrations/markdoc/test/fixtures/render-with-components/src/pages/index.astro @@ -1,7 +1,5 @@ --- import { getEntryBySlug } from "astro:content"; -import Code from '../components/Code.astro'; -import CustomMarquee from '../components/CustomMarquee.astro'; const post = await getEntryBySlug('blog', 'with-components'); const { Content } = await post.render(); @@ -13,11 +11,9 @@ const { Content } = await post.render(); <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <title>Content - with components</title> + <title>Content</title> </head> <body> - <Content - components={{ CustomMarquee, Code }} - /> + <Content /> </body> </html> diff --git a/packages/integrations/markdoc/test/fixtures/render-with-config/astro.config.mjs b/packages/integrations/markdoc/test/fixtures/render-with-config/astro.config.mjs new file mode 100644 index 000000000..29d846359 --- /dev/null +++ b/packages/integrations/markdoc/test/fixtures/render-with-config/astro.config.mjs @@ -0,0 +1,7 @@ +import { defineConfig } from 'astro/config'; +import markdoc from '@astrojs/markdoc'; + +// https://astro.build/config +export default defineConfig({ + integrations: [markdoc()], +}); diff --git a/packages/integrations/markdoc/test/fixtures/render-with-config/markdoc.config.mjs b/packages/integrations/markdoc/test/fixtures/render-with-config/markdoc.config.mjs new file mode 100644 index 000000000..c43ee93a3 --- /dev/null +++ b/packages/integrations/markdoc/test/fixtures/render-with-config/markdoc.config.mjs @@ -0,0 +1,15 @@ +import { defineMarkdocConfig } from '@astrojs/markdoc/config'; + +export default defineMarkdocConfig({ + variables: { + countries: ['ES', 'JP'], + }, + functions: { + includes: { + transform(parameters) { + const [array, value] = Object.values(parameters); + return Array.isArray(array) ? array.includes(value) : false; + }, + }, + }, +}) diff --git a/packages/integrations/markdoc/test/fixtures/render-with-config/package.json b/packages/integrations/markdoc/test/fixtures/render-with-config/package.json new file mode 100644 index 000000000..d4751388c --- /dev/null +++ b/packages/integrations/markdoc/test/fixtures/render-with-config/package.json @@ -0,0 +1,9 @@ +{ + "name": "@test/markdoc-render-with-config", + "version": "0.0.0", + "private": true, + "dependencies": { + "@astrojs/markdoc": "workspace:*", + "astro": "workspace:*" + } +} diff --git a/packages/integrations/markdoc/test/fixtures/content-collections/src/content/blog/with-config.mdoc b/packages/integrations/markdoc/test/fixtures/render-with-config/src/content/blog/with-config.mdoc index 199eadb9c..5376404ea 100644 --- a/packages/integrations/markdoc/test/fixtures/content-collections/src/content/blog/with-config.mdoc +++ b/packages/integrations/markdoc/test/fixtures/render-with-config/src/content/blog/with-config.mdoc @@ -7,3 +7,7 @@ title: Post with config {% if includes($countries, "EN") %} Hello {% /if %} {% if includes($countries, "ES") %} Hola {% /if %} {% if includes($countries, "JP") %} Konnichiwa {% /if %} + +## Runtime variables + +{% $runtimeVariable %} {% #runtime-variable %} diff --git a/packages/integrations/markdoc/test/fixtures/content-collections/src/pages/content-with-config.astro b/packages/integrations/markdoc/test/fixtures/render-with-config/src/pages/index.astro index f37217a62..616d5ec0a 100644 --- a/packages/integrations/markdoc/test/fixtures/content-collections/src/pages/content-with-config.astro +++ b/packages/integrations/markdoc/test/fixtures/render-with-config/src/pages/index.astro @@ -11,9 +11,9 @@ const { Content } = await post.render(); <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <title>Content - with config</title> + <title>Content</title> </head> <body> - <Content /> + <Content runtimeVariable="working!" /> </body> </html> diff --git a/packages/integrations/markdoc/test/render.test.js b/packages/integrations/markdoc/test/render.test.js new file mode 100644 index 000000000..acb17577b --- /dev/null +++ b/packages/integrations/markdoc/test/render.test.js @@ -0,0 +1,124 @@ +import { parseHTML } from 'linkedom'; +import { expect } from 'chai'; +import { loadFixture } from '../../../astro/test/test-utils.js'; + +async function getFixture(name) { + return await loadFixture({ + root: new URL(`./fixtures/${name}/`, import.meta.url), + }); +} + +describe('Markdoc - render', () => { + describe('dev', () => { + it('renders content - simple', async () => { + const fixture = await getFixture('render-simple'); + const server = await fixture.startDevServer(); + + const res = await fixture.fetch('/'); + const html = await res.text(); + const { document } = parseHTML(html); + const h2 = document.querySelector('h2'); + expect(h2.textContent).to.equal('Simple post'); + const p = document.querySelector('p'); + expect(p.textContent).to.equal('This is a simple Markdoc post.'); + + await server.stop(); + }); + + it('renders content - with config', async () => { + const fixture = await getFixture('render-with-config'); + const server = await fixture.startDevServer(); + + const res = await fixture.fetch('/'); + const html = await res.text(); + const { document } = parseHTML(html); + const h2 = document.querySelector('h2'); + expect(h2.textContent).to.equal('Post with config'); + const textContent = html; + + expect(textContent).to.not.include('Hello'); + expect(textContent).to.include('Hola'); + expect(textContent).to.include(`Konnichiwa`); + + const runtimeVariable = document.querySelector('#runtime-variable'); + expect(runtimeVariable?.textContent?.trim()).to.equal('working!'); + + await server.stop(); + }); + + it('renders content - with components', async () => { + const fixture = await getFixture('render-with-components'); + const server = await fixture.startDevServer(); + + const res = await fixture.fetch('/'); + const html = await res.text(); + const { document } = parseHTML(html); + const h2 = document.querySelector('h2'); + expect(h2.textContent).to.equal('Post with components'); + + // Renders custom shortcode component + const marquee = document.querySelector('marquee'); + expect(marquee).to.not.be.null; + expect(marquee.hasAttribute('data-custom-marquee')).to.equal(true); + + // Renders Astro Code component + const pre = document.querySelector('pre'); + expect(pre).to.not.be.null; + expect(pre.className).to.equal('astro-code'); + + await server.stop(); + }); + }); + + describe('build', () => { + it('renders content - simple', async () => { + const fixture = await getFixture('render-simple'); + await fixture.build(); + + const html = await fixture.readFile('/index.html'); + const { document } = parseHTML(html); + const h2 = document.querySelector('h2'); + expect(h2.textContent).to.equal('Simple post'); + const p = document.querySelector('p'); + expect(p.textContent).to.equal('This is a simple Markdoc post.'); + }); + + it('renders content - with config', async () => { + const fixture = await getFixture('render-with-config'); + await fixture.build(); + + const html = await fixture.readFile('/index.html'); + const { document } = parseHTML(html); + const h2 = document.querySelector('h2'); + expect(h2.textContent).to.equal('Post with config'); + const textContent = html; + + expect(textContent).to.not.include('Hello'); + expect(textContent).to.include('Hola'); + expect(textContent).to.include(`Konnichiwa`); + + const runtimeVariable = document.querySelector('#runtime-variable'); + expect(runtimeVariable?.textContent?.trim()).to.equal('working!'); + }); + + it('renders content - with components', async () => { + const fixture = await getFixture('render-with-components'); + await fixture.build(); + + const html = await fixture.readFile('/index.html'); + const { document } = parseHTML(html); + const h2 = document.querySelector('h2'); + expect(h2.textContent).to.equal('Post with components'); + + // Renders custom shortcode component + const marquee = document.querySelector('marquee'); + expect(marquee).to.not.be.null; + expect(marquee.hasAttribute('data-custom-marquee')).to.equal(true); + + // Renders Astro Code component + const pre = document.querySelector('pre'); + expect(pre).to.not.be.null; + expect(pre.className).to.equal('astro-code'); + }); + }); +}); |