Home / File/ content-collections.test.js — astro Source File

content-collections.test.js — astro Source File

Architecture documentation for content-collections.test.js, a javascript file in the astro codebase. 7 imports, 0 dependents.

File javascript CoreAstro RoutingSystem 7 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  c5e7b2c8_0bc0_a6af_9881_0fbe13d48b4d["content-collections.test.js"]
  0a624eac_945e_c9e8_c9de_3feb9de2dd15["test-utils.js"]
  c5e7b2c8_0bc0_a6af_9881_0fbe13d48b4d --> 0a624eac_945e_c9e8_c9de_3feb9de2dd15
  beb21e0a_5a04_1aeb_f065_5ab6c5ffe2ea["fixLineEndings"]
  c5e7b2c8_0bc0_a6af_9881_0fbe13d48b4d --> beb21e0a_5a04_1aeb_f065_5ab6c5ffe2ea
  dd4f09ce_3fd7_8295_f616_8876cda4555c["loadFixture"]
  c5e7b2c8_0bc0_a6af_9881_0fbe13d48b4d --> dd4f09ce_3fd7_8295_f616_8876cda4555c
  6f35189c_9ece_b171_44ed_6095794ea721["../dist/index.js"]
  c5e7b2c8_0bc0_a6af_9881_0fbe13d48b4d --> 6f35189c_9ece_b171_44ed_6095794ea721
  e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"]
  c5e7b2c8_0bc0_a6af_9881_0fbe13d48b4d --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607
  6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"]
  c5e7b2c8_0bc0_a6af_9881_0fbe13d48b4d --> 6b0635f9_51ea_77aa_767b_7857878e98a6
  ca52ff61_c81f_c2ca_81b6_5a678b65fd31["devalue"]
  c5e7b2c8_0bc0_a6af_9881_0fbe13d48b4d --> ca52ff61_c81f_c2ca_81b6_5a678b65fd31
  style c5e7b2c8_0bc0_a6af_9881_0fbe13d48b4d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import { parse as parseDevalue } from 'devalue';
import { fixLineEndings, loadFixture } 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);

const sortById = (a, b) => a.id.localeCompare(b.id);

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());
			assert.deepEqual(formatPost(post), post1Entry);
		});

		it('loads collection', async () => {
			const res = await baseFixture.fetch('/collection.json');
			const posts = parseDevalue(await res.text());
			assert.notEqual(posts, null);

			assert.deepEqual(
				posts.sort(sortById).map((post) => formatPost(post)),
				[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);
			assert.deepEqual(formatPost(post), post1Entry);
		});

		it('loads collection', async () => {
			const res = await baseFixture.readFile('/collection.json');
			const posts = parseDevalue(res);
			assert.notEqual(posts, null);
			assert.deepEqual(
				posts.sort(sortById).map((post) => formatPost(post)),
				[post1Entry, post2Entry, post3Entry],
			);
		});
	});
});

const post1Entry = {
	id: 'post-1',
	collection: 'blog',
	data: {
		schemaWorks: true,
		title: 'Post 1',
	},
	body: '## Post 1\n\nThis is the contents of post 1.',
	deferredRender: true,
	filePath: 'src/content/blog/post-1.mdoc',
	digest: '5d5bd98d949e2b9a',
};

const post2Entry = {
	id: 'post-2',
	collection: 'blog',
	data: {
		schemaWorks: true,
		title: 'Post 2',
	},
	body: '## Post 2\n\nThis is the contents of post 2.',
	deferredRender: true,
	filePath: 'src/content/blog/post-2.mdoc',
	digest: '595af4b93a4af072',
};

const post3Entry = {
	id: 'post-3',
	collection: 'blog',
	data: {
		schemaWorks: true,
		title: 'Post 3',
	},
	body: '## Post 3\n\nThis is the contents of post 3.',
	deferredRender: true,
	filePath: 'src/content/blog/post-3.mdoc',
	digest: 'ef589606e542247e',
};

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does content-collections.test.js do?
content-collections.test.js is a source file in the astro codebase, written in javascript. It belongs to the CoreAstro domain, RoutingSystem subdomain.
What functions are defined in content-collections.test.js?
content-collections.test.js defines 2 function(s): formatPost, sortById.
What does content-collections.test.js depend on?
content-collections.test.js imports 7 module(s): ../dist/index.js, devalue, fixLineEndings, loadFixture, node:test, strict, test-utils.js.
Where is content-collections.test.js in the architecture?
content-collections.test.js is located at packages/integrations/markdoc/test/content-collections.test.js (domain: CoreAstro, subdomain: RoutingSystem, directory: packages/integrations/markdoc/test).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free