Skip to content

Commit dcde113

Browse files
[REACH-2529] fail unit test if frontmatter is formatted incorrectly (#2111)
* [REACH-2529] fail unit test if frontmatter is formatted incorrectly * reorder tests
1 parent e4da791 commit dcde113

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

content.test.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,22 @@ describe.each(glob.sync('content/**/*.md'))('%s', (file) => {
8787
Tags?: string[];
8888
};
8989

90-
const { attributes }: FrontMatterResult<FrontMatterAttributes> = frontmatter(
91-
fs.readFileSync(file, 'utf8')
92-
);
90+
const fileContent = fs.readFileSync(file, 'utf8');
91+
92+
if (!frontmatter.test(fileContent)) {
93+
throw new Error(
94+
`error: ${file} does not contain properly formatted frontmatter.`
95+
);
96+
}
97+
98+
if (!fileContent.startsWith('---')) {
99+
throw new Error(
100+
`error: ${file} does not contain properly formatted frontmatter. Check for leading invisible characters.`
101+
);
102+
}
103+
104+
const { attributes }: FrontMatterResult<FrontMatterAttributes> =
105+
frontmatter(fileContent);
93106

94107
it('has only valid metadata keys', () => {
95108
const validKeys: Record<string, string> = {

0 commit comments

Comments
 (0)