@@ -12,20 +12,38 @@ describe('Content Intellisense', () => {
1212 /** @type {{collections: {hasSchema: boolean, name: string}[], entries: Record<string, string>} } */
1313 let manifest = undefined ;
1414
15+ /** @type {Record<string, Array<{ id: string; data: any; filePath: string; collection: string }>> } */
16+ let collections ;
17+
1518 before ( async ( ) => {
1619 fixture = await loadFixture ( { root : './fixtures/content-intellisense/' } ) ;
1720 await fixture . build ( ) ;
1821
1922 collectionsDir = await fixture . readdir ( '../.astro/collections' ) ;
2023 manifest = JSON . parse ( await fixture . readFile ( '../.astro/collections/collections.json' ) ) ;
24+ collections = JSON . parse ( await fixture . readFile ( 'index.json' ) ) ;
2125 } ) ;
2226
2327 it ( 'generate JSON schemas for content collections' , async ( ) => {
24- assert . deepEqual ( collectionsDir . includes ( 'blog-cc.schema.json' ) , true ) ;
28+ assert . equal ( collectionsDir . includes ( 'blog-cc.schema.json' ) , true ) ;
2529 } ) ;
2630
2731 it ( 'generate JSON schemas for content layer' , async ( ) => {
28- assert . deepEqual ( collectionsDir . includes ( 'blog-cl.schema.json' ) , true ) ;
32+ assert . equal ( collectionsDir . includes ( 'blog-cl.schema.json' ) , true ) ;
33+ } ) ;
34+
35+ it ( 'generate JSON schemas for file loader' , async ( ) => {
36+ assert . equal ( collectionsDir . includes ( 'data-cl.schema.json' ) , true ) ;
37+ } ) ;
38+
39+ it ( 'generates a record JSON schema for the file loader' , async ( ) => {
40+ const schema = JSON . parse ( await fixture . readFile ( '../.astro/collections/data-cl.schema.json' ) ) ;
41+ assert . equal ( schema . definitions [ 'data-cl' ] . type , 'object' ) ;
42+ assert . equal ( schema . definitions [ 'data-cl' ] . additionalProperties . type , 'object' ) ;
43+ assert . deepEqual ( schema . definitions [ 'data-cl' ] . additionalProperties . properties , {
44+ name : { type : 'string' } ,
45+ color : { type : 'string' } ,
46+ } ) ;
2947 } ) ;
3048
3149 it ( 'manifest exists' , async ( ) => {
@@ -76,4 +94,15 @@ describe('Content Intellisense', () => {
7694 "Expected 3 entries for 'blog-cl' collection to have 'blog-cl' as collection name" ,
7795 ) ;
7896 } ) ;
97+
98+ it ( 'doesn’t generate a `$schema` entry for file loader if `$schema` value is a string' , async ( ) => {
99+ assert . equal ( collections [ 'data-cl-json' ] . map ( ( entry ) => entry . id ) . includes ( '$schema' ) , false ) ;
100+ } ) ;
101+
102+ it ( 'generates a `$schema` entry for file loader if `$schema` value isn’t a string' , async ( ) => {
103+ assert . equal (
104+ collections [ 'data-schema-misuse' ] . map ( ( entry ) => entry . id ) . includes ( '$schema' ) ,
105+ true ,
106+ ) ;
107+ } ) ;
79108} ) ;
0 commit comments