@@ -5,13 +5,17 @@ import * as actionsUtil from "./actions-util";
55import { EnvVar } from "./environment" ;
66import { Language } from "./languages" ;
77import { getRunnerLogger } from "./logging" ;
8- import { ActionName , createStatusReportBase } from "./status-report" ;
8+ import {
9+ ActionName ,
10+ createStatusReportBase ,
11+ getActionsStatus ,
12+ } from "./status-report" ;
913import {
1014 setupTests ,
1115 setupActionsVars ,
1216 createTestConfig ,
1317} from "./testing-utils" ;
14- import { BuildMode , withTmpDir } from "./util" ;
18+ import { BuildMode , ConfigurationError , withTmpDir , wrapError } from "./util" ;
1519
1620setupTests ( test ) ;
1721
@@ -186,3 +190,56 @@ test("createStatusReportBase_firstParty", async (t) => {
186190 ) ;
187191 } ) ;
188192} ) ;
193+
194+ test ( "getActionStatus handling correctly various types of errors" , ( t ) => {
195+ t . is (
196+ getActionsStatus ( new Error ( "arbitrary error" ) ) ,
197+ "failure" ,
198+ "We categorise an arbitrary error as a failure" ,
199+ ) ;
200+
201+ t . is (
202+ getActionsStatus ( new ConfigurationError ( "arbitrary error" ) ) ,
203+ "user-error" ,
204+ "We categorise a ConfigurationError as a user error" ,
205+ ) ;
206+
207+ t . is (
208+ getActionsStatus ( new Error ( "exit code 1" ) , "multiple things went wrong" ) ,
209+ "failure" ,
210+ "getActionsStatus should return failure if passed an arbitrary error and an additional failure cause" ,
211+ ) ;
212+
213+ t . is (
214+ getActionsStatus (
215+ new ConfigurationError ( "exit code 1" ) ,
216+ "multiple things went wrong" ,
217+ ) ,
218+ "user-error" ,
219+ "getActionsStatus should return failure if passed a configuration error and an additional failure cause" ,
220+ ) ;
221+
222+ t . is (
223+ getActionsStatus ( ) ,
224+ "success" ,
225+ "getActionsStatus should return success if no error is passed" ,
226+ ) ;
227+
228+ t . is (
229+ getActionsStatus ( new Object ( ) ) ,
230+ "failure" ,
231+ "getActionsStatus should return failure if passed an arbitrary object" ,
232+ ) ;
233+
234+ t . is (
235+ getActionsStatus ( null , "an error occurred" ) ,
236+ "failure" ,
237+ "getActionsStatus should return failure if passed null and an additional failure cause" ,
238+ ) ;
239+
240+ t . is (
241+ getActionsStatus ( wrapError ( new ConfigurationError ( "arbitrary error" ) ) ) ,
242+ "user-error" ,
243+ "We still recognise a wrapped ConfigurationError as a user error" ,
244+ ) ;
245+ } ) ;
0 commit comments