Skip to content

Commit

Permalink
chore: unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bholmesdev committed Feb 16, 2023
1 parent 545246d commit cb70602
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -14,52 +16,52 @@ 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');
}
});

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');
});
});

0 comments on commit cb70602

Please sign in to comment.