@@ -34,7 +34,10 @@ const name = "World";
3434
3535 const root = ret . root as AstroRoot ;
3636 expect ( root . type ) . toBe ( "AstroRoot" ) ;
37- expect ( root . frontmatter ) . toBeNull ( ) ;
37+ // When no frontmatter exists, a synthetic empty frontmatter is created
38+ // for semantic analysis to have a Program root node
39+ expect ( root . frontmatter ) . not . toBeNull ( ) ;
40+ expect ( root . frontmatter ?. program . body . length ) . toBe ( 0 ) ;
3841 expect ( root . body . length ) . toBeGreaterThan ( 0 ) ;
3942 } ) ;
4043
@@ -71,10 +74,16 @@ const name = "World";
7174 const root = ret . root as AstroRoot ;
7275 expect ( root . type ) . toBe ( "AstroRoot" ) ;
7376
74- // Find the AstroScript in the body
75- const astroScript = root . body . find ( ( child : any ) => child . type === "AstroScript" ) as
76- | AstroScript
77- | undefined ;
77+ // Find the script JSXElement in the body
78+ const scriptElement = root . body . find (
79+ ( child : any ) => child . type === "JSXElement" && child . openingElement ?. name ?. name === "script" ,
80+ ) as any ;
81+ expect ( scriptElement ) . toBeDefined ( ) ;
82+
83+ // The AstroScript is inside the script element's children
84+ const astroScript = scriptElement ?. children ?. find (
85+ ( child : any ) => child . type === "AstroScript" ,
86+ ) as AstroScript | undefined ;
7887 expect ( astroScript ) . toBeDefined ( ) ;
7988 expect ( astroScript ?. type ) . toBe ( "AstroScript" ) ;
8089 expect ( astroScript ?. program ) . toBeDefined ( ) ;
0 commit comments