11/** 
22 * Test the consistency of elements extracts with IDL extracts. 
3-  *   
3+  * 
44 * The tests run against the curated and package views of the data. An extract 
55 * that passes a test in the curated view may fail the same test in the package 
66 * view because of some missing IDL definition in that view. 
77 */ 
88
9- import  {  describe ,  it ,   before  }  from  'node:test' ; 
9+ import  {  describe ,  it  }  from  'node:test' ; 
1010import  {  strict  as  assert  }  from  'node:assert' ; 
1111import  path  from  'node:path' ; 
1212import  {  fileURLToPath  }  from  'node:url' ; 
@@ -26,37 +26,36 @@ const views = [
2626] ; 
2727
2828views . forEach ( ( {  name,  folder } )  =>  { 
29-   describe ( `The ${ name }   view of elements extracts` ,  ( )  =>  { 
30-     before ( async  ( )  =>  { 
31-       // Create a set of well-known interfaces 
32-       const  allIdl  =  await  idl . parseAll ( {  folder : path . join ( folder ,  'idl' )  } ) ; 
33-       const  interfaces  =  new  Set ( ) ; 
34-       for  ( const  [ shortname ,  ast ]  of  Object . entries ( allIdl ) )  { 
35-         for  ( const  dfn  of  ast )  { 
36-           if  ( dfn . name )  { 
37-             interfaces . add ( dfn . name ) ; 
38-           } 
29+   describe ( `The ${ name }   view of elements extracts` ,  async  ( )  =>  { 
30+     let  allIdl ; 
31+     try  { 
32+       allIdl  =  await  idl . parseAll ( {  folder : path . join ( folder ,  'idl' )  } ) ; 
33+     }  catch  ( err )  { 
34+       it ( 'contains valid JSON data' ,  ( )  =>  { throw  err ; } ) ; 
35+     } 
36+     const  interfaces  =  new  Set ( ) ; 
37+     for  ( const  [ shortname ,  ast ]  of  Object . entries ( allIdl ) )  { 
38+       for  ( const  dfn  of  ast )  { 
39+         if  ( dfn . name )  { 
40+           interfaces . add ( dfn . name ) ; 
3941        } 
4042      } 
43+     } 
4144
42-       const  allElements  =  await  elements . listAll ( {  folder : path . join ( folder ,  'elements' )  } ) ; 
43-       for  ( const  [ shortname ,  data ]  of  Object . entries ( allElements ) )  { 
44-         describe ( `The elements extract for ${ shortname }   in the ${ name }   view` ,  ( )  =>  { 
45-           for  ( const  el  of  data . elements )  { 
46-             if  ( ! el . interface )  { 
47-               continue ; 
48-             } 
49-             it ( `links to a well-known interface for "${ el . name }  "` ,  ( )  =>  { 
50-               assert ( interfaces . has ( el . interface ) ,  `Unknown interface "${ el . interface }  "` ) ; 
51-             } ) ; 
45+     const  allElements  =  await  elements . listAll ( {  folder : path . join ( folder ,  'elements' )  } ) ; 
46+     for  ( const  [ shortname ,  data ]  of  Object . entries ( allElements ) )  { 
47+       describe ( `The elements extract for ${ shortname }   in the ${ name }   view` ,  ( )  =>  { 
48+         for  ( const  el  of  data . elements )  { 
49+           if  ( ! el . interface )  { 
50+             continue ; 
5251          } 
53-         } ) ; 
54-       } 
55-     } ) ; 
56- 
57-     // Dummy test needed for "before" to run and register late tests 
58-     // (test will fail if before function throws, e.g. because data is invalid) 
59-     it ( 'contains valid JSON data' ,  ( )  =>  { } ) ; 
52+           it ( `links to a well-known interface for "${ el . name }  "` ,  ( )  =>  { 
53+             assert ( interfaces . has ( el . interface ) ,  `Unknown interface "${ el . interface }  "` ) ; 
54+           } ) ; 
55+         } 
56+       } ) ; 
57+     } 
6058  } ) ; 
59+ 
6160} ) ; 
6261
0 commit comments