import * as assertModule from "assert" ; export type AssertType = typeof assertModule ; import * as harnessModule from "./harness" ; export type HarnessType = typeof harnessModule ; export function errorJSON ( err ) { const result = Object . create ( null ) ; Object . getOwnPropertyNames ( err ) . forEach ( key => result [ key ] = err [ key ] ) ; return result ; } export async function testModulesWorker ( testFunctions , arg ) { let passed = true ; const result = Object . create ( null ) ; await Promise . all ( testFunctions . map ( async ( testFn ) => { passed = await testFn ( arg , result ) && passed ; } ) ) ; return [ passed , result ] ; } export async function testModule ( arg , result , module ) { let passed = true ; await Promise . all ( Object . keys ( module ) . map ( async ( moduleName ) => { passed = await runTests ( arg , moduleName , module [ moduleName ] , result ) && passed ; } ) ) ; return passed ; } async function runTests ( arg , moduleName , module , result ) { let passed = true ; await Promise . all ( Object . keys ( module ) . map ( async ( name ) => { if ( ! name . startsWith ( "test" ) ) { return ; } const fullName = `${ moduleName }.${ name }` ; try { await module [ name ] ( arg ) ; result [ fullName ] = "passed" ; } catch ( err ) { passed = false ; result [ fullName ] = errorJSON ( err ) ; } } ) ) ; return passed ; } export async function assertThrowsAsync ( body ) { try { await body ( ) ; } catch ( err ) { return ; } throw new Error ( "Expected error to be thrown" ) ; }