Skip to content

Commit 76f9ed9

Browse files
committed
test: add tests to validate getActionsStatus' behaviour
1 parent 9bd18b4 commit 76f9ed9

File tree

3 files changed

+70
-3
lines changed

3 files changed

+70
-3
lines changed

lib/status-report.test.js

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/status-report.test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/status-report.test.ts

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ import * as actionsUtil from "./actions-util";
55
import { EnvVar } from "./environment";
66
import { Language } from "./languages";
77
import { getRunnerLogger } from "./logging";
8-
import { ActionName, createStatusReportBase } from "./status-report";
8+
import {
9+
ActionName,
10+
createStatusReportBase,
11+
getActionsStatus,
12+
} from "./status-report";
913
import {
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

1620
setupTests(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

Comments
 (0)