@@ -42,43 +42,54 @@ async function main(
4242 const entryPoints = findEntryPointsWithinNpmPackage ( npmPackageDir , packageJson ) ;
4343 const outdatedGoldens : string [ ] = [ ] ;
4444
45- let allTestsSucceeding = true ;
45+ const tasks : Promise < boolean > [ ] = [ ] ;
4646
4747 for ( const { subpath, typesEntryPointPath} of entryPoints ) {
48- // API extractor generates API reports as markdown files. For each types
49- // entry-point we maintain a separate golden file. These golden files are
50- // based on the name of the defining NodeJS exports subpath in the NPM package,
51- // See: https://api-extractor.com/pages/overview/demo_api_report/.
52- const goldenName = path . join ( subpath , 'index.api.md' ) ;
53- const goldenFilePath = path . join ( goldenDir , goldenName ) ;
54- const moduleName = normalizePathToPosix ( path . join ( packageJson . name , subpath ) ) ;
55-
56- const actual = await testApiGolden (
57- typesEntryPointPath ,
58- stripExportPattern ,
59- typeNames ,
60- packageJsonPath ,
61- moduleName ,
62- ) ;
48+ tasks . push (
49+ ( async ( ) => {
50+ // API extractor generates API reports as markdown files. For each types
51+ // entry-point we maintain a separate golden file. These golden files are
52+ // based on the name of the defining NodeJS exports subpath in the NPM package,
53+ // See: https://api-extractor.com/pages/overview/demo_api_report/.
54+ const goldenName = path . join ( subpath , 'index.api.md' ) ;
55+ const goldenFilePath = path . join ( goldenDir , goldenName ) ;
56+ const moduleName = normalizePathToPosix ( path . join ( packageJson . name , subpath ) ) ;
57+
58+ const actual = await testApiGolden (
59+ typesEntryPointPath ,
60+ stripExportPattern ,
61+ typeNames ,
62+ packageJsonPath ,
63+ moduleName ,
64+ ) ;
65+
66+ if ( actual === null ) {
67+ console . error (
68+ `Could not generate API golden for subpath: "${ subpath } ". See errors above.` ,
69+ ) ;
70+ process . exit ( 1 ) ;
71+ }
6372
64- if ( actual === null ) {
65- console . error ( `Could not generate API golden for subpath: "${ subpath } ". See errors above.` ) ;
66- process . exit ( 1 ) ;
67- }
68-
69- if ( approveGolden ) {
70- fs . mkdirSync ( path . dirname ( goldenFilePath ) , { recursive : true } ) ;
71- fs . writeFileSync ( goldenFilePath , actual , 'utf8' ) ;
72- } else {
73- const expected = fs . readFileSync ( goldenFilePath , 'utf8' ) ;
74- if ( actual !== expected ) {
75- // Keep track of outdated goldens for error message.
76- outdatedGoldens . push ( goldenName ) ;
77- allTestsSucceeding = false ;
78- }
79- }
73+ if ( approveGolden ) {
74+ await fs . promises . mkdir ( path . dirname ( goldenFilePath ) , { recursive : true } ) ;
75+ await fs . promises . writeFile ( goldenFilePath , actual , 'utf8' ) ;
76+ } else {
77+ const expected = await fs . promises . readFile ( goldenFilePath , 'utf8' ) ;
78+ if ( actual !== expected ) {
79+ // Keep track of outdated goldens for error message.
80+ outdatedGoldens . push ( goldenName ) ;
81+ return false ;
82+ }
83+ }
84+
85+ return true ;
86+ } ) ( ) ,
87+ ) ;
8088 }
8189
90+ const results = await Promise . all ( tasks ) ;
91+ const allTestsSucceeding = results . every ( ( r ) => r === true ) ;
92+
8293 if ( outdatedGoldens . length ) {
8394 console . error ( chalk . red ( `The following goldens are outdated:` ) ) ;
8495 outdatedGoldens . forEach ( ( name ) => console . info ( `- ${ name } ` ) ) ;
0 commit comments