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/content-collections.test.js | |
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/content-collections.test.js')
-rw-r--r-- | packages/integrations/markdoc/test/content-collections.test.js | 196 |
1 files changed, 24 insertions, 172 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', }; |