@@ -61,6 +61,77 @@ export interface TestResultsData {
6161 Stats : TestStatistics ;
6262}
6363
64+ export function processAndDisplayTestSummary (
65+ runnerTemp : string ,
66+ runId : string ,
67+ actionName : string ,
68+ workspace : string ,
69+ ) {
70+ const testResultsData = getTestResults ( runnerTemp , runId , workspace ) ;
71+ if ( testResultsData ) {
72+ writeSummary ( testResultsData , actionName ) ;
73+ }
74+ }
75+
76+ export function getTestResults (
77+ runnerTemp : string ,
78+ runId : string ,
79+ workspace : string ,
80+ ) : TestResultsData | null {
81+ let testResultsData = null ;
82+ const resultsPath = path . join ( runnerTemp , `matlabTestResults${ runId } .json` ) ;
83+
84+ if ( existsSync ( resultsPath ) ) {
85+ try {
86+ const testArtifact = JSON . parse ( readFileSync ( resultsPath , "utf8" ) ) ;
87+ const testResults : MatlabTestFile [ ] [ ] = [ ] ;
88+ const stats : TestStatistics = {
89+ Total : 0 ,
90+ Passed : 0 ,
91+ Failed : 0 ,
92+ Incomplete : 0 ,
93+ NotRun : 0 ,
94+ Duration : 0 ,
95+ } ;
96+ testResultsData = {
97+ TestResults : testResults ,
98+ Stats : stats ,
99+ } ;
100+
101+ for ( const jsonTestSessionResults of testArtifact ) {
102+ const testSessionResults : MatlabTestFile [ ] = [ ] ;
103+ const map = new Map < string , MatlabTestFile > ( ) ;
104+
105+ const testCases = Array . isArray ( jsonTestSessionResults )
106+ ? jsonTestSessionResults
107+ : [ jsonTestSessionResults ] ;
108+
109+ for ( const jsonTestCase of testCases ) {
110+ processTestCase ( testSessionResults , jsonTestCase , map , stats , workspace ) ;
111+ }
112+
113+ testResults . push ( testSessionResults ) ;
114+ }
115+ } catch ( e ) {
116+ console . error (
117+ "An error occurred while reading the test results summary file ${resultsPath}:" ,
118+ e ,
119+ ) ;
120+ } finally {
121+ try {
122+ unlinkSync ( resultsPath ) ;
123+ } catch ( e ) {
124+ console . error (
125+ `An error occurred while trying to delete the test results summary file ${ resultsPath } :` ,
126+ e ,
127+ ) ;
128+ }
129+ }
130+ }
131+
132+ return testResultsData ;
133+ }
134+
64135export function writeSummary (
65136 testResultsData : TestResultsData ,
66137 actionName : string ,
@@ -196,65 +267,6 @@ export function getStatusEmoji(status: MatlabTestStatus): string {
196267 }
197268}
198269
199- export function getTestResults (
200- runnerTemp : string ,
201- runId : string ,
202- workspace : string ,
203- ) : TestResultsData | null {
204- let testResultsData = null ;
205- const resultsPath = path . join ( runnerTemp , `matlabTestResults${ runId } .json` ) ;
206-
207- if ( existsSync ( resultsPath ) ) {
208- try {
209- const testArtifact = JSON . parse ( readFileSync ( resultsPath , "utf8" ) ) ;
210- const testResults : MatlabTestFile [ ] [ ] = [ ] ;
211- const stats : TestStatistics = {
212- Total : 0 ,
213- Passed : 0 ,
214- Failed : 0 ,
215- Incomplete : 0 ,
216- NotRun : 0 ,
217- Duration : 0 ,
218- } ;
219- testResultsData = {
220- TestResults : testResults ,
221- Stats : stats ,
222- } ;
223-
224- for ( const jsonTestSessionResults of testArtifact ) {
225- const testSessionResults : MatlabTestFile [ ] = [ ] ;
226- const map = new Map < string , MatlabTestFile > ( ) ;
227-
228- const testCases = Array . isArray ( jsonTestSessionResults )
229- ? jsonTestSessionResults
230- : [ jsonTestSessionResults ] ;
231-
232- for ( const jsonTestCase of testCases ) {
233- processTestCase ( testSessionResults , jsonTestCase , map , stats , workspace ) ;
234- }
235-
236- testResults . push ( testSessionResults ) ;
237- }
238- } catch ( e ) {
239- console . error (
240- "An error occurred while reading the test results summary file ${resultsPath}:" ,
241- e ,
242- ) ;
243- } finally {
244- try {
245- unlinkSync ( resultsPath ) ;
246- } catch ( e ) {
247- console . error (
248- `An error occurred while trying to delete the test results summary file ${ resultsPath } :` ,
249- e ,
250- ) ;
251- }
252- }
253- }
254-
255- return testResultsData ;
256- }
257-
258270function processTestCase (
259271 testSessionResults : MatlabTestFile [ ] ,
260272 jsonTestCase : MatlabTestCaseJson ,
@@ -296,24 +308,6 @@ function processTestCase(
296308 updateStats ( testCase , stats ) ;
297309}
298310
299- function incrementDuration ( testFile : MatlabTestFile , testCaseDuration : number ) : void {
300- testFile . Duration = ( testFile . Duration || 0 ) + testCaseDuration ;
301- }
302-
303- function updateFileStatus ( testFile : MatlabTestFile , testCase : MatlabTestCase ) : void {
304- if ( testFile . Status !== MatlabTestStatus . FAILED ) {
305- if ( testCase . Status === MatlabTestStatus . FAILED ) {
306- testFile . Status = MatlabTestStatus . FAILED ;
307- } else if ( testFile . Status !== MatlabTestStatus . INCOMPLETE ) {
308- if ( testCase . Status === MatlabTestStatus . INCOMPLETE ) {
309- testFile . Status = MatlabTestStatus . INCOMPLETE ;
310- } else if ( testCase . Status === MatlabTestStatus . PASSED ) {
311- testFile . Status = MatlabTestStatus . PASSED ;
312- }
313- }
314- }
315- }
316-
317311function determineTestStatus ( testResult : MatlabTestResultJson ) : MatlabTestStatus {
318312 switch ( true ) {
319313 case testResult . Failed :
@@ -333,6 +327,24 @@ function processDiagnostics(diagnostics: MatlabTestDiagnostics | MatlabTestDiagn
333327 return Array . isArray ( diagnostics ) ? diagnostics : [ diagnostics ] ;
334328}
335329
330+ function incrementDuration ( testFile : MatlabTestFile , testCaseDuration : number ) : void {
331+ testFile . Duration = ( testFile . Duration || 0 ) + testCaseDuration ;
332+ }
333+
334+ function updateFileStatus ( testFile : MatlabTestFile , testCase : MatlabTestCase ) : void {
335+ if ( testFile . Status !== MatlabTestStatus . FAILED ) {
336+ if ( testCase . Status === MatlabTestStatus . FAILED ) {
337+ testFile . Status = MatlabTestStatus . FAILED ;
338+ } else if ( testFile . Status !== MatlabTestStatus . INCOMPLETE ) {
339+ if ( testCase . Status === MatlabTestStatus . INCOMPLETE ) {
340+ testFile . Status = MatlabTestStatus . INCOMPLETE ;
341+ } else if ( testCase . Status === MatlabTestStatus . PASSED ) {
342+ testFile . Status = MatlabTestStatus . PASSED ;
343+ }
344+ }
345+ }
346+ }
347+
336348function updateStats ( testCase : MatlabTestCase , stats : TestStatistics ) : void {
337349 stats . Total ++ ;
338350 switch ( testCase . Status ) {
0 commit comments