@@ -120,21 +120,27 @@ test('get data', async () => {
120
120
} )
121
121
122
122
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' )
125
129
await write ( 'blog/first-b.md' , createFront ( 'Second' , '2020-01-04' ) )
126
130
await write ( 'blog/nested/hey1.md' , createFront ( 'Third' , '2020-01-02' ) )
127
131
await write ( 'blog/nested/hey2.md' , createFront ( 'Fourth' , '2020-01-03' ) )
128
132
129
133
const site = await getSite ( )
130
134
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
+ } )
132
138
// expected order is : First, Second, Fourth, Third.
133
139
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' } ,
138
144
] )
139
145
} )
140
146
0 commit comments