0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00
astro/packages/integrations/markdoc/test/content-collections.test.js
Ben Holmes 7c439868a3
[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
2023-03-27 18:04:37 -04:00

110 lines
2.4 KiB
JavaScript

import { parse as parseDevalue } from 'devalue';
import { expect } from 'chai';
import { loadFixture, fixLineEndings } from '../../../astro/test/test-utils.js';
import markdoc from '../dist/index.js';
function formatPost(post) {
return {
...post,
body: fixLineEndings(post.body),
};
}
const root = new URL('./fixtures/content-collections/', import.meta.url);
describe('Markdoc - Content Collections', () => {
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('loads entry', async () => {
const res = await baseFixture.fetch('/entry.json');
const post = parseDevalue(await res.text());
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([
post1Entry,
post2Entry,
post3Entry,
]);
});
});
describe('build', () => {
before(async () => {
await baseFixture.build();
});
it('loads entry', async () => {
const res = await baseFixture.readFile('/entry.json');
const post = parseDevalue(res);
expect(formatPost(post)).to.deep.equal(post1Entry);
});
it('loads collection', async () => {
const res = await baseFixture.readFile('/collection.json');
const posts = parseDevalue(res);
expect(posts).to.not.be.null;
expect(posts.sort().map((post) => formatPost(post))).to.deep.equal([
post1Entry,
post2Entry,
post3Entry,
]);
});
});
});
const post1Entry = {
id: 'post-1.mdoc',
slug: 'post-1',
collection: 'blog',
data: {
schemaWorks: true,
title: 'Post 1',
},
body: '\n## Post 1\n\nThis is the contents of post 1.\n',
};
const post2Entry = {
id: 'post-2.mdoc',
slug: 'post-2',
collection: 'blog',
data: {
schemaWorks: true,
title: 'Post 2',
},
body: '\n## Post 2\n\nThis is the contents of post 2.\n',
};
const post3Entry = {
id: 'post-3.mdoc',
slug: 'post-3',
collection: 'blog',
data: {
schemaWorks: true,
title: 'Post 3',
},
body: '\n## Post 3\n\nThis is the contents of post 3.\n',
};