@@ -8,6 +8,7 @@ import { execWasmBinaries } from "./core/execute.js";
88import { generateReport , reportConfig } from "./generator/index.js" ;
99import { TestOption } from "./interface.js" ;
1010import { join } from "node:path" ;
11+ import { CompilationError } from "./utils/ascWrapper.js" ;
1112
1213const { readFileSync, emptydirSync } = pkg ;
1314
@@ -30,10 +31,7 @@ export function validateArgument(includes: unknown, excludes: unknown) {
3031 }
3132}
3233
33- /**
34- * main function of unit-test, will throw Exception in most condition except job carsh
35- */
36- export async function start_unit_test ( options : TestOption ) : Promise < boolean > {
34+ async function startUniTestImpl ( options : TestOption ) : Promise < number > {
3735 const failurePath = join ( options . outputFolder , "failures.json" ) ;
3836 let failedTestCases : string [ ] = [ ] ;
3937 if ( options . onlyFailures ) {
@@ -85,6 +83,18 @@ export async function start_unit_test(options: TestOption): Promise<boolean> {
8583 reportConfig . errorLimit = options . errorLimit || reportConfig . errorLimit ;
8684 generateReport ( options . mode , options . outputFolder , fileCoverageInfo ) ;
8785 }
86+ return executedResult . fail === 0 ? 0 : 1 ;
87+ }
8888
89- return executedResult . fail === 0 ;
89+ export async function start_unit_test ( options : TestOption ) : Promise < number > {
90+ try {
91+ return await startUniTestImpl ( options ) ;
92+ } catch ( error ) {
93+ if ( error instanceof CompilationError ) {
94+ console . log ( error . message ) ;
95+ return 2 ;
96+ }
97+ // unknown exception.
98+ throw error ;
99+ }
90100}
0 commit comments