11#!/usr/bin/env -S deno run --allow-read --allow-run
22import * as path from "@std/path" ;
3-
4- const decoder = new TextDecoder ( ) ;
3+ import { decode , encode } from "@commontools/utils/encoding" ;
54
65export const ALL_DISABLED = [
76 "background-charm-service" , // no tests yet
87 "vendor-astral" , // no tests yet
98] ;
109
11- export async function testPackage ( packagePath : string ) : Promise < boolean > {
12- const result = await new Deno . Command ( Deno . execPath ( ) , {
13- args : [ "task" , "test" ] ,
14- cwd : packagePath ,
15- stdout : "piped" ,
16- } ) . output ( ) ;
17-
18- const stdout = decoder . decode ( result . stdout ) ;
19- if ( stdout ) {
20- console . log ( stdout ) ;
21- }
22- const stderr = decoder . decode ( result . stderr ) ;
23- if ( stderr ) {
24- console . error ( stderr ) ;
10+ export async function testPackage (
11+ packagePath : string ,
12+ ) : Promise < { packagePath : string ; result : Deno . CommandOutput } > {
13+ try {
14+ return {
15+ packagePath,
16+ result : await new Deno . Command ( Deno . execPath ( ) , {
17+ args : [ "task" , "test" ] ,
18+ cwd : packagePath ,
19+ stdout : "piped" ,
20+ } ) . output ( ) ,
21+ } ;
22+ } catch ( e ) {
23+ return {
24+ packagePath,
25+ result : {
26+ success : false ,
27+ stdout : new Uint8Array ( ) ,
28+ stderr : encode ( `${ e } ` ) ,
29+ code : 1 ,
30+ signal : null ,
31+ } ,
32+ } ;
2533 }
26- return result . success ;
2734}
2835
2936export async function runTests ( disabledPackages : string [ ] ) : Promise < boolean > {
3037 const workspaceCwd = Deno . cwd ( ) ;
3138 const manifest = JSON . parse ( await Deno . readTextFile ( "./deno.json" ) ) ;
3239 const members : string [ ] = manifest . workspace ;
3340
34- const failedPackages : string [ ] = [ ] ;
35-
41+ const tests = [ ] ;
3642 for ( const memberPath of members ) {
3743 // Convert "./packages/memory" to "memory"
3844 const packageName = memberPath . substring ( 2 ) . split ( "/" ) [ 1 ] ;
@@ -42,18 +48,21 @@ export async function runTests(disabledPackages: string[]): Promise<boolean> {
4248 }
4349 console . log ( `Testing ${ packageName } ...` ) ;
4450 const packagePath = path . join ( workspaceCwd , "packages" , packageName ) ;
45- if ( ! await testPackage ( packagePath ) ) {
46- failedPackages . push ( packageName ) ;
47- }
51+ tests . push ( testPackage ( packagePath ) ) ;
4852 }
4953
54+ const results = await Promise . all ( tests ) ;
55+ const failedPackages = results . filter ( ( result ) => ! result . result . success ) ;
56+
5057 if ( failedPackages . length === 0 ) {
5158 console . log ( "All tests passing!" ) ;
5259 } else {
5360 console . error ( "One or more tests failed." ) ;
5461 console . error ( "Failed packages:" ) ;
55- for ( const pkg of failedPackages ) {
56- console . error ( `- ${ pkg } ` ) ;
62+ for ( const result of failedPackages ) {
63+ console . error ( `- ${ result . packagePath } ` ) ;
64+ console . log ( decode ( result . result . stdout ) ) ;
65+ console . error ( decode ( result . result . stderr ) ) ;
5766 }
5867 Deno . exit ( 1 ) ;
5968 }
0 commit comments