test: entry properties can be rendered
This commit is contained in:
parent
61e4425494
commit
1db3825e98
7 changed files with 121 additions and 1 deletions
58
packages/integrations/markdoc/test/entry-prop.test.js
Normal file
58
packages/integrations/markdoc/test/entry-prop.test.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
import { parseHTML } from 'linkedom';
|
||||
import { expect } from 'chai';
|
||||
import { loadFixture } from '../../../astro/test/test-utils.js';
|
||||
import markdoc from '../dist/index.js';
|
||||
|
||||
const root = new URL('./fixtures/entry-prop/', import.meta.url);
|
||||
|
||||
describe('Markdoc - Entry prop', () => {
|
||||
let baseFixture;
|
||||
|
||||
before(async () => {
|
||||
baseFixture = await loadFixture({
|
||||
root,
|
||||
integrations: [markdoc()],
|
||||
});
|
||||
});
|
||||
|
||||
describe('dev', () => {
|
||||
let devServer;
|
||||
|
||||
before(async () => {
|
||||
devServer = await baseFixture.startDevServer();
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await devServer.stop();
|
||||
});
|
||||
|
||||
it('has expected entry properties', async () => {
|
||||
const res = await baseFixture.fetch('/');
|
||||
const html = await res.text();
|
||||
const { document } = parseHTML(html);
|
||||
expect(document.querySelector('h1')?.textContent).to.equal('Processed by schema: Test entry');
|
||||
expect(document.getElementById('id')?.textContent?.trim()).to.equal('id: entry.mdoc');
|
||||
expect(document.getElementById('slug')?.textContent?.trim()).to.equal('slug: entry');
|
||||
expect(document.getElementById('collection')?.textContent?.trim()).to.equal(
|
||||
'collection: blog'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('build', () => {
|
||||
before(async () => {
|
||||
await baseFixture.build();
|
||||
});
|
||||
|
||||
it('has expected entry properties', async () => {
|
||||
const html = await baseFixture.readFile('/index.html');
|
||||
const { document } = parseHTML(html);
|
||||
expect(document.querySelector('h1')?.textContent).to.equal('Processed by schema: Test entry');
|
||||
expect(document.getElementById('id')?.textContent?.trim()).to.equal('id: entry.mdoc');
|
||||
expect(document.getElementById('slug')?.textContent?.trim()).to.equal('slug: entry');
|
||||
expect(document.getElementById('collection')?.textContent?.trim()).to.equal(
|
||||
'collection: blog'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
7
packages/integrations/markdoc/test/fixtures/entry-prop/astro.config.mjs
vendored
Normal file
7
packages/integrations/markdoc/test/fixtures/entry-prop/astro.config.mjs
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
import { defineConfig } from 'astro/config';
|
||||
import markdoc from '@astrojs/markdoc';
|
||||
|
||||
// https://astro.build/config
|
||||
export default defineConfig({
|
||||
integrations: [markdoc()],
|
||||
});
|
9
packages/integrations/markdoc/test/fixtures/entry-prop/package.json
vendored
Normal file
9
packages/integrations/markdoc/test/fixtures/entry-prop/package.json
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"name": "@test/markdoc-entry-prop",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@astrojs/markdoc": "workspace:*",
|
||||
"astro": "workspace:*"
|
||||
}
|
||||
}
|
9
packages/integrations/markdoc/test/fixtures/entry-prop/src/content/blog/entry.mdoc
vendored
Normal file
9
packages/integrations/markdoc/test/fixtures/entry-prop/src/content/blog/entry.mdoc
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
title: Test entry
|
||||
---
|
||||
|
||||
# {% $entry.data.title %}
|
||||
|
||||
- id: {% $entry.id %} {% #id %}
|
||||
- slug: {% $entry.slug %} {% #slug %}
|
||||
- collection: {% $entry.collection %} {% #collection %}
|
9
packages/integrations/markdoc/test/fixtures/entry-prop/src/content/config.ts
vendored
Normal file
9
packages/integrations/markdoc/test/fixtures/entry-prop/src/content/config.ts
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
import { defineCollection, z } from 'astro:content';
|
||||
|
||||
const blog = defineCollection({
|
||||
schema: z.object({
|
||||
title: z.string().transform(v => 'Processed by schema: ' + v),
|
||||
}),
|
||||
});
|
||||
|
||||
export const collections = { blog }
|
19
packages/integrations/markdoc/test/fixtures/entry-prop/src/pages/index.astro
vendored
Normal file
19
packages/integrations/markdoc/test/fixtures/entry-prop/src/pages/index.astro
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
---
|
||||
import { getEntryBySlug } from 'astro:content';
|
||||
|
||||
const entry = await getEntryBySlug('blog', 'entry');
|
||||
const { Content } = await entry.render();
|
||||
---
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<title>Astro</title>
|
||||
</head>
|
||||
<body>
|
||||
<Content />
|
||||
</body>
|
||||
</html>
|
|
@ -3103,6 +3103,14 @@ importers:
|
|||
devDependencies:
|
||||
shiki: 0.11.1
|
||||
|
||||
packages/integrations/markdoc/test/fixtures/entry-prop:
|
||||
specifiers:
|
||||
'@astrojs/markdoc': workspace:*
|
||||
astro: workspace:*
|
||||
dependencies:
|
||||
'@astrojs/markdoc': link:../../..
|
||||
astro: link:../../../../../astro
|
||||
|
||||
packages/integrations/mdx:
|
||||
specifiers:
|
||||
'@astrojs/markdown-remark': ^2.1.0
|
||||
|
@ -14669,6 +14677,7 @@ packages:
|
|||
hasBin: true
|
||||
optionalDependencies:
|
||||
fsevents: 2.3.2
|
||||
dev: true
|
||||
|
||||
/run-parallel/1.2.0:
|
||||
resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==}
|
||||
|
@ -16212,7 +16221,7 @@ packages:
|
|||
esbuild: 0.16.17
|
||||
postcss: 8.4.21
|
||||
resolve: 1.22.1
|
||||
rollup: 3.19.1
|
||||
rollup: 3.14.0
|
||||
optionalDependencies:
|
||||
fsevents: 2.3.2
|
||||
|
||||
|
|
Loading…
Reference in a new issue