Skip to content

Commit 083ef7c

Browse files
authored
Merge pull request #199 from goblinfactory-forks/chore/test-content-collection
Update `content-collection` test and comments to include testing pubDate
2 parents 16b348a + 1be8d2e commit 083ef7c

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

packages/nuekit/test/nuekit.test.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,27 @@ test('get data', async () => {
120120
})
121121

122122
test('content collection', async () => {
123-
// Default sorting is on pubDate returning most recent first.
124-
await write('blog/first-a.md', createFront('First'))
123+
// This test proves
124+
// ----------------
125+
// 1. Default sorting is on pubDate returning most recent first.
126+
// 2. Collection returns parent folders, then child folders.
127+
// 3. Posts with null dates, e.g. First, come before posts with dates.
128+
await write('blog/first-a.md', '# First')
125129
await write('blog/first-b.md', createFront('Second', '2020-01-04'))
126130
await write('blog/nested/hey1.md', createFront('Third', '2020-01-02'))
127131
await write('blog/nested/hey2.md', createFront('Fourth', '2020-01-03'))
128132

129133
const site = await getSite()
130134
const coll = await site.getContentCollection('blog')
131-
const actual = coll.map(c => { return { url: c.url, title: c.title, dir: c.dir, slug: c.slug }; });
135+
const actual = coll.map(c => {
136+
return { pubDate: c.pubDate, url: c.url, title: c.title, dir: c.dir, slug: c.slug }
137+
})
132138
// expected order is : First, Second, Fourth, Third.
133139
expect(actual).toEqual([
134-
{ url: '/blog/first-a.html', title: 'First', dir: 'blog', slug: 'first-a.html' },
135-
{ url: '/blog/first-b.html', title: 'Second', dir: 'blog', slug: 'first-b.html' },
136-
{ url: '/blog/nested/hey2.html', title: 'Fourth', dir: join('blog', 'nested'), slug: 'hey2.html' },
137-
{ url: '/blog/nested/hey1.html', title: 'Third', dir: join('blog', 'nested'), slug: 'hey1.html' },
140+
{ pubDate: undefined, url: '/blog/first-a.html', title: 'First', dir: 'blog', slug: 'first-a.html' },
141+
{ pubDate: new Date('2020-01-04T00:00:00.000Z'), url: '/blog/first-b.html', title: 'Second', dir: 'blog', slug: 'first-b.html' },
142+
{ pubDate: new Date('2020-01-03T00:00:00.000Z'), url: '/blog/nested/hey2.html', title: 'Fourth', dir: 'blog/nested', slug: 'hey2.html' },
143+
{ pubDate: new Date('2020-01-02T00:00:00.000Z'), url: '/blog/nested/hey1.html', title: 'Third', dir: 'blog/nested', slug: 'hey1.html' },
138144
])
139145
})
140146

0 commit comments

Comments
 (0)