Home / File/ frontmatter.test.js — astro Source File

frontmatter.test.js — astro Source File

Architecture documentation for frontmatter.test.js, a javascript file in the astro codebase. 3 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  30e0aa8f_35fd_e068_3b80_e912b7865321["frontmatter.test.js"]
  8350d254_ac08_0a3a_4696_d1a19f979b3a["../dist/index.js"]
  30e0aa8f_35fd_e068_3b80_e912b7865321 --> 8350d254_ac08_0a3a_4696_d1a19f979b3a
  e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"]
  30e0aa8f_35fd_e068_3b80_e912b7865321 --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607
  6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"]
  30e0aa8f_35fd_e068_3b80_e912b7865321 --> 6b0635f9_51ea_77aa_767b_7857878e98a6
  style 30e0aa8f_35fd_e068_3b80_e912b7865321 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { extractFrontmatter, parseFrontmatter } from '../dist/index.js';

const bom = '\uFEFF';

describe('extractFrontmatter', () => {
	it('handles YAML', () => {
		const yaml = `\nfoo: bar\n`;
		assert.equal(extractFrontmatter(`---${yaml}---`), yaml);
		assert.equal(extractFrontmatter(`${bom}---${yaml}---`), yaml);
		assert.equal(extractFrontmatter(`\n---${yaml}---`), yaml);
		assert.equal(extractFrontmatter(`\n  \n---${yaml}---`), yaml);
		assert.equal(extractFrontmatter(`---${yaml}---\ncontent`), yaml);
		assert.equal(extractFrontmatter(`${bom}---${yaml}---\ncontent`), yaml);
		assert.equal(extractFrontmatter(`\n\n---${yaml}---\n\ncontent`), yaml);
		assert.equal(extractFrontmatter(`\n  \n---${yaml}---\n\ncontent`), yaml);
		assert.equal(extractFrontmatter(` ---${yaml}---`), undefined);
		assert.equal(extractFrontmatter(`---${yaml} ---`), undefined);
		assert.equal(extractFrontmatter(`text\n---${yaml}---\n\ncontent`), undefined);
	});

	it('handles TOML', () => {
		const toml = `\nfoo = "bar"\n`;
		assert.equal(extractFrontmatter(`+++${toml}+++`), toml);
		assert.equal(extractFrontmatter(`${bom}+++${toml}+++`), toml);
		assert.equal(extractFrontmatter(`\n+++${toml}+++`), toml);
		assert.equal(extractFrontmatter(`\n  \n+++${toml}+++`), toml);
		assert.equal(extractFrontmatter(`+++${toml}+++\ncontent`), toml);
		assert.equal(extractFrontmatter(`${bom}+++${toml}+++\ncontent`), toml);
		assert.equal(extractFrontmatter(`\n\n+++${toml}+++\n\ncontent`), toml);
		assert.equal(extractFrontmatter(`\n  \n+++${toml}+++\n\ncontent`), toml);
		assert.equal(extractFrontmatter(` +++${toml}+++`), undefined);
		assert.equal(extractFrontmatter(`+++${toml} +++`), undefined);
		assert.equal(extractFrontmatter(`text\n+++${toml}+++\n\ncontent`), undefined);
	});
});

describe('parseFrontmatter', () => {
	it('works for YAML', () => {
		const yaml = `\nfoo: bar\n`;
		assert.deepEqual(parseFrontmatter(`---${yaml}---`), {
			frontmatter: { foo: 'bar' },
			rawFrontmatter: yaml,
			content: '',
		});
		assert.deepEqual(parseFrontmatter(`${bom}---${yaml}---`), {
			frontmatter: { foo: 'bar' },
			rawFrontmatter: yaml,
			content: bom,
		});
		assert.deepEqual(parseFrontmatter(`\n---${yaml}---`), {
			frontmatter: { foo: 'bar' },
			rawFrontmatter: yaml,
			content: '\n',
		});
		assert.deepEqual(parseFrontmatter(`\n  \n---${yaml}---`), {
			frontmatter: { foo: 'bar' },
			rawFrontmatter: yaml,
			content: '\n  \n',
// ... (130 more lines)

Domain

Dependencies

  • ../dist/index.js
  • node:test
  • strict

Frequently Asked Questions

What does frontmatter.test.js do?
frontmatter.test.js is a source file in the astro codebase, written in javascript. It belongs to the CoreAstro domain.
What does frontmatter.test.js depend on?
frontmatter.test.js imports 3 module(s): ../dist/index.js, node:test, strict.
Where is frontmatter.test.js in the architecture?
frontmatter.test.js is located at packages/markdown/remark/test/frontmatter.test.js (domain: CoreAstro, directory: packages/markdown/remark/test).

Analyze Your Own Codebase

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

Try Supermodel Free