mirror of
https://github.com/withastro/astro.git
synced 2024-12-23 21:53:55 -05:00
81dce94f2a
* chore: strictNullChecks for zod * feat: expose `rssSchema` helper * refactor: align types with schema types * feat: break glob handler to globToRssItems util * refactor: RSS options validation to Zod * refactor: avoid intermediate type * fix: allow numbers and dates in pubDate * test: update glob and error tests * feat: add rss to with-content starter * fix: move globToRssItems back to internal behavior * chore: JSON.stringify * Revert "fix: move globToRssItems back to internal behavior" This reverts commit 85305075e6444907455541b24bccbccd5016951a. * test: missing url * docs: `import.meta.env.SITE` -> `context.site` * docs: update README to content collections example * fix: url -> link * docs: add `rssSchema` to README * chore: consistent formatting * docs: add `pagesGlobToRssItems()` reference * chore: globToRssItems -> pagesGlobToRssItems * chore: changeset * fix: bad docs line highlighting * fix: add collections export to example * nit: remove "our" * fix: are -> all * fix: more README edits * deps: kleur * chore: add back import.meta.glob handling as deprecated * docs: bump down to `minor`, update headline to be less content collections-y * typo: suggest adding * chore: support URL object on `site` * docs: add await to pagesGlob ex * docs: tighten `rssSchema` explainer * docs: tighten pagesGlobToRssItems section * docs: add content to README * docs: replace examples with docs link * docs: re-we Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
85 lines
2.1 KiB
JavaScript
85 lines
2.1 KiB
JavaScript
import chai from 'chai';
|
|
import chaiPromises from 'chai-as-promised';
|
|
import { phpFeedItem, web1FeedItem } from './test-utils.js';
|
|
import { pagesGlobToRssItems } from '../dist/index.js';
|
|
|
|
chai.use(chaiPromises);
|
|
|
|
describe('pagesGlobToRssItems', () => {
|
|
it('should generate on valid result', async () => {
|
|
const globResult = {
|
|
'./posts/php.md': () =>
|
|
new Promise((resolve) =>
|
|
resolve({
|
|
url: phpFeedItem.link,
|
|
frontmatter: {
|
|
title: phpFeedItem.title,
|
|
pubDate: phpFeedItem.pubDate,
|
|
description: phpFeedItem.description,
|
|
},
|
|
})
|
|
),
|
|
'./posts/nested/web1.md': () =>
|
|
new Promise((resolve) =>
|
|
resolve({
|
|
url: web1FeedItem.link,
|
|
frontmatter: {
|
|
title: web1FeedItem.title,
|
|
pubDate: web1FeedItem.pubDate,
|
|
description: web1FeedItem.description,
|
|
},
|
|
})
|
|
),
|
|
};
|
|
|
|
const items = await pagesGlobToRssItems(globResult);
|
|
|
|
chai.expect(items.sort((a, b) => a.pubDate - b.pubDate)).to.deep.equal([
|
|
{
|
|
title: phpFeedItem.title,
|
|
link: phpFeedItem.link,
|
|
pubDate: new Date(phpFeedItem.pubDate),
|
|
description: phpFeedItem.description,
|
|
},
|
|
{
|
|
title: web1FeedItem.title,
|
|
link: web1FeedItem.link,
|
|
pubDate: new Date(web1FeedItem.pubDate),
|
|
description: web1FeedItem.description,
|
|
},
|
|
]);
|
|
});
|
|
|
|
it('should fail on missing "url"', () => {
|
|
const globResult = {
|
|
'./posts/php.md': () =>
|
|
new Promise((resolve) =>
|
|
resolve({
|
|
url: undefined,
|
|
frontmatter: {
|
|
pubDate: phpFeedItem.pubDate,
|
|
description: phpFeedItem.description,
|
|
},
|
|
})
|
|
),
|
|
};
|
|
return chai.expect(pagesGlobToRssItems(globResult)).to.be.rejected;
|
|
});
|
|
|
|
it('should fail on missing "title" key', () => {
|
|
const globResult = {
|
|
'./posts/php.md': () =>
|
|
new Promise((resolve) =>
|
|
resolve({
|
|
url: phpFeedItem.link,
|
|
frontmatter: {
|
|
title: undefined,
|
|
pubDate: phpFeedItem.pubDate,
|
|
description: phpFeedItem.description,
|
|
},
|
|
})
|
|
),
|
|
};
|
|
return chai.expect(pagesGlobToRssItems(globResult)).to.be.rejected;
|
|
});
|
|
});
|