chore: unit tests
This commit is contained in:
parent
65846f4151
commit
39ce218c49
1 changed files with 10 additions and 8 deletions
|
@ -25,13 +25,15 @@ const fixtures = [
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const contentFileExts = ['.md', '.mdx'];
|
||||||
|
|
||||||
describe('Content Collections - getEntryType', () => {
|
describe('Content Collections - getEntryType', () => {
|
||||||
fixtures.forEach(({ title, contentPaths }) => {
|
fixtures.forEach(({ title, contentPaths }) => {
|
||||||
describe(title, () => {
|
describe(title, () => {
|
||||||
it('Returns "content" for Markdown files', () => {
|
it('Returns "content" for Markdown files', () => {
|
||||||
for (const entryPath of ['blog/first-post.md', 'blog/first-post.mdx']) {
|
for (const entryPath of ['blog/first-post.md', 'blog/first-post.mdx']) {
|
||||||
const entry = fileURLToPath(new URL(entryPath, contentPaths.contentDir));
|
const entry = fileURLToPath(new URL(entryPath, contentPaths.contentDir));
|
||||||
const type = getEntryType(entry, contentPaths);
|
const type = getEntryType(entry, contentPaths, contentFileExts);
|
||||||
expect(type).to.equal('content');
|
expect(type).to.equal('content');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -39,44 +41,44 @@ describe('Content Collections - getEntryType', () => {
|
||||||
it('Returns "content" for Markdown files in nested directories', () => {
|
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']) {
|
for (const entryPath of ['blog/2021/01/01/index.md', 'blog/2021/01/01/index.mdx']) {
|
||||||
const entry = fileURLToPath(new URL(entryPath, contentPaths.contentDir));
|
const entry = fileURLToPath(new URL(entryPath, contentPaths.contentDir));
|
||||||
const type = getEntryType(entry, contentPaths);
|
const type = getEntryType(entry, contentPaths, contentFileExts);
|
||||||
expect(type).to.equal('content');
|
expect(type).to.equal('content');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Returns "config" for config files', () => {
|
it('Returns "config" for config files', () => {
|
||||||
const entry = fileURLToPath(contentPaths.config.url);
|
const entry = fileURLToPath(contentPaths.config.url);
|
||||||
const type = getEntryType(entry, contentPaths);
|
const type = getEntryType(entry, contentPaths, contentFileExts);
|
||||||
expect(type).to.equal('config');
|
expect(type).to.equal('config');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Returns "unsupported" for non-Markdown files', () => {
|
it('Returns "unsupported" for non-Markdown files', () => {
|
||||||
const entry = fileURLToPath(new URL('blog/robots.txt', contentPaths.contentDir));
|
const entry = fileURLToPath(new URL('blog/robots.txt', contentPaths.contentDir));
|
||||||
const type = getEntryType(entry, contentPaths);
|
const type = getEntryType(entry, contentPaths, contentFileExts);
|
||||||
expect(type).to.equal('unsupported');
|
expect(type).to.equal('unsupported');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Returns "ignored" for .DS_Store', () => {
|
it('Returns "ignored" for .DS_Store', () => {
|
||||||
const entry = fileURLToPath(new URL('blog/.DS_Store', contentPaths.contentDir));
|
const entry = fileURLToPath(new URL('blog/.DS_Store', contentPaths.contentDir));
|
||||||
const type = getEntryType(entry, contentPaths);
|
const type = getEntryType(entry, contentPaths, contentFileExts);
|
||||||
expect(type).to.equal('ignored');
|
expect(type).to.equal('ignored');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Returns "ignored" for unsupported files using an underscore', () => {
|
it('Returns "ignored" for unsupported files using an underscore', () => {
|
||||||
const entry = fileURLToPath(new URL('blog/_draft-robots.txt', contentPaths.contentDir));
|
const entry = fileURLToPath(new URL('blog/_draft-robots.txt', contentPaths.contentDir));
|
||||||
const type = getEntryType(entry, contentPaths);
|
const type = getEntryType(entry, contentPaths, contentFileExts);
|
||||||
expect(type).to.equal('ignored');
|
expect(type).to.equal('ignored');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Returns "ignored" when using underscore on file name', () => {
|
it('Returns "ignored" when using underscore on file name', () => {
|
||||||
const entry = fileURLToPath(new URL('blog/_first-post.md', contentPaths.contentDir));
|
const entry = fileURLToPath(new URL('blog/_first-post.md', contentPaths.contentDir));
|
||||||
const type = getEntryType(entry, contentPaths);
|
const type = getEntryType(entry, contentPaths, contentFileExts);
|
||||||
expect(type).to.equal('ignored');
|
expect(type).to.equal('ignored');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Returns "ignored" when using underscore on directory name', () => {
|
it('Returns "ignored" when using underscore on directory name', () => {
|
||||||
const entry = fileURLToPath(new URL('blog/_draft/first-post.md', contentPaths.contentDir));
|
const entry = fileURLToPath(new URL('blog/_draft/first-post.md', contentPaths.contentDir));
|
||||||
const type = getEntryType(entry, contentPaths);
|
const type = getEntryType(entry, contentPaths, contentFileExts);
|
||||||
expect(type).to.equal('ignored');
|
expect(type).to.equal('ignored');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue