chore: unit tests

This commit is contained in:
bholmesdev 2023-02-07 14:00:27 -05:00
parent 4a275ab4d0
commit d8baec8bd1

View file

@ -2,6 +2,8 @@ import { getEntryType } from '../../../dist/content/utils.js';
import { expect } from 'chai';
import { fileURLToPath } from 'node:url';
const contentFileExts = ['.md', '.mdx'];
describe('Content Collections - getEntryType', () => {
const contentDir = new URL('src/content/', import.meta.url);
const contentPaths = {
@ -14,7 +16,7 @@ describe('Content Collections - getEntryType', () => {
it('Returns "content" for Markdown files', () => {
for (const entryPath of ['blog/first-post.md', 'blog/first-post.mdx']) {
const entry = fileURLToPath(new URL(entryPath, contentDir));
const type = getEntryType(entry, contentPaths);
const type = getEntryType(entry, contentPaths, contentFileExts);
expect(type).to.equal('content');
}
});
@ -22,44 +24,44 @@ describe('Content Collections - getEntryType', () => {
it('Returns "content" for Markdown files in nested directories', () => {
for (const entryPath of ['blog/2021/01/01/index.md', 'blog/2021/01/01/index.mdx']) {
const entry = fileURLToPath(new URL(entryPath, contentDir));
const type = getEntryType(entry, contentPaths);
const type = getEntryType(entry, contentPaths, contentFileExts);
expect(type).to.equal('content');
}
});
it('Returns "config" for config files', () => {
const entry = fileURLToPath(contentPaths.config.url);
const type = getEntryType(entry, contentPaths);
const type = getEntryType(entry, contentPaths, contentFileExts);
expect(type).to.equal('config');
});
it('Returns "unsupported" for non-Markdown files', () => {
const entry = fileURLToPath(new URL('blog/robots.txt', contentDir));
const type = getEntryType(entry, contentPaths);
const type = getEntryType(entry, contentPaths, contentFileExts);
expect(type).to.equal('unsupported');
});
it('Returns "ignored" for .DS_Store', () => {
const entry = fileURLToPath(new URL('blog/.DS_Store', contentDir));
const type = getEntryType(entry, contentPaths);
const type = getEntryType(entry, contentPaths, contentFileExts);
expect(type).to.equal('ignored');
});
it('Returns "ignored" for unsupported files using an underscore', () => {
const entry = fileURLToPath(new URL('blog/_draft-robots.txt', contentDir));
const type = getEntryType(entry, contentPaths);
const type = getEntryType(entry, contentPaths, contentFileExts);
expect(type).to.equal('ignored');
});
it('Returns "ignored" when using underscore on file name', () => {
const entry = fileURLToPath(new URL('blog/_first-post.md', contentDir));
const type = getEntryType(entry, contentPaths);
const type = getEntryType(entry, contentPaths, contentFileExts);
expect(type).to.equal('ignored');
});
it('Returns "ignored" when using underscore on directory name', () => {
const entry = fileURLToPath(new URL('blog/_draft/first-post.md', contentDir));
const type = getEntryType(entry, contentPaths);
const type = getEntryType(entry, contentPaths, contentFileExts);
expect(type).to.equal('ignored');
});
});