test: add tests to validate getActionsStatus' behaviour
This commit is contained in:
parent
9bd18b486f
commit
76f9ed9cd9
3 changed files with 70 additions and 3 deletions
10
lib/status-report.test.js
generated
10
lib/status-report.test.js
generated
|
|
@ -109,4 +109,14 @@ function setupEnvironmentAndStub(tmpDir) {
|
||||||
t.is((await (0, status_report_1.createStatusReportBase)(status_report_1.ActionName.Analyze, "failure", new Date("May 19, 2023 05:19:00"), (0, testing_utils_1.createTestConfig)({}), { numAvailableBytes: 100, numTotalBytes: 500 }, (0, logging_1.getRunnerLogger)(false), "failure cause", "exception stack trace"))?.first_party_analysis, true);
|
t.is((await (0, status_report_1.createStatusReportBase)(status_report_1.ActionName.Analyze, "failure", new Date("May 19, 2023 05:19:00"), (0, testing_utils_1.createTestConfig)({}), { numAvailableBytes: 100, numTotalBytes: 500 }, (0, logging_1.getRunnerLogger)(false), "failure cause", "exception stack trace"))?.first_party_analysis, true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
(0, ava_1.default)("getActionStatus handling correctly various types of errors", (t) => {
|
||||||
|
t.is((0, status_report_1.getActionsStatus)(new Error("arbitrary error")), "failure", "We categorise an arbitrary error as a failure");
|
||||||
|
t.is((0, status_report_1.getActionsStatus)(new util_1.ConfigurationError("arbitrary error")), "user-error", "We categorise a ConfigurationError as a user error");
|
||||||
|
t.is((0, status_report_1.getActionsStatus)(new Error("exit code 1"), "multiple things went wrong"), "failure", "getActionsStatus should return failure if passed an arbitrary error and an additional failure cause");
|
||||||
|
t.is((0, status_report_1.getActionsStatus)(new util_1.ConfigurationError("exit code 1"), "multiple things went wrong"), "user-error", "getActionsStatus should return failure if passed a configuration error and an additional failure cause");
|
||||||
|
t.is((0, status_report_1.getActionsStatus)(), "success", "getActionsStatus should return success if no error is passed");
|
||||||
|
t.is((0, status_report_1.getActionsStatus)(new Object()), "failure", "getActionsStatus should return failure if passed an arbitrary object");
|
||||||
|
t.is((0, status_report_1.getActionsStatus)(null, "an error occurred"), "failure", "getActionsStatus should return failure if passed null and an additional failure cause");
|
||||||
|
t.is((0, status_report_1.getActionsStatus)((0, util_1.wrapError)(new util_1.ConfigurationError("arbitrary error"))), "user-error", "We still recognise a wrapped ConfigurationError as a user error");
|
||||||
|
});
|
||||||
//# sourceMappingURL=status-report.test.js.map
|
//# sourceMappingURL=status-report.test.js.map
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -5,13 +5,17 @@ import * as actionsUtil from "./actions-util";
|
||||||
import { EnvVar } from "./environment";
|
import { EnvVar } from "./environment";
|
||||||
import { Language } from "./languages";
|
import { Language } from "./languages";
|
||||||
import { getRunnerLogger } from "./logging";
|
import { getRunnerLogger } from "./logging";
|
||||||
import { ActionName, createStatusReportBase } from "./status-report";
|
import {
|
||||||
|
ActionName,
|
||||||
|
createStatusReportBase,
|
||||||
|
getActionsStatus,
|
||||||
|
} from "./status-report";
|
||||||
import {
|
import {
|
||||||
setupTests,
|
setupTests,
|
||||||
setupActionsVars,
|
setupActionsVars,
|
||||||
createTestConfig,
|
createTestConfig,
|
||||||
} from "./testing-utils";
|
} from "./testing-utils";
|
||||||
import { BuildMode, withTmpDir } from "./util";
|
import { BuildMode, ConfigurationError, withTmpDir, wrapError } from "./util";
|
||||||
|
|
||||||
setupTests(test);
|
setupTests(test);
|
||||||
|
|
||||||
|
|
@ -186,3 +190,56 @@ test("createStatusReportBase_firstParty", async (t) => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("getActionStatus handling correctly various types of errors", (t) => {
|
||||||
|
t.is(
|
||||||
|
getActionsStatus(new Error("arbitrary error")),
|
||||||
|
"failure",
|
||||||
|
"We categorise an arbitrary error as a failure",
|
||||||
|
);
|
||||||
|
|
||||||
|
t.is(
|
||||||
|
getActionsStatus(new ConfigurationError("arbitrary error")),
|
||||||
|
"user-error",
|
||||||
|
"We categorise a ConfigurationError as a user error",
|
||||||
|
);
|
||||||
|
|
||||||
|
t.is(
|
||||||
|
getActionsStatus(new Error("exit code 1"), "multiple things went wrong"),
|
||||||
|
"failure",
|
||||||
|
"getActionsStatus should return failure if passed an arbitrary error and an additional failure cause",
|
||||||
|
);
|
||||||
|
|
||||||
|
t.is(
|
||||||
|
getActionsStatus(
|
||||||
|
new ConfigurationError("exit code 1"),
|
||||||
|
"multiple things went wrong",
|
||||||
|
),
|
||||||
|
"user-error",
|
||||||
|
"getActionsStatus should return failure if passed a configuration error and an additional failure cause",
|
||||||
|
);
|
||||||
|
|
||||||
|
t.is(
|
||||||
|
getActionsStatus(),
|
||||||
|
"success",
|
||||||
|
"getActionsStatus should return success if no error is passed",
|
||||||
|
);
|
||||||
|
|
||||||
|
t.is(
|
||||||
|
getActionsStatus(new Object()),
|
||||||
|
"failure",
|
||||||
|
"getActionsStatus should return failure if passed an arbitrary object",
|
||||||
|
);
|
||||||
|
|
||||||
|
t.is(
|
||||||
|
getActionsStatus(null, "an error occurred"),
|
||||||
|
"failure",
|
||||||
|
"getActionsStatus should return failure if passed null and an additional failure cause",
|
||||||
|
);
|
||||||
|
|
||||||
|
t.is(
|
||||||
|
getActionsStatus(wrapError(new ConfigurationError("arbitrary error"))),
|
||||||
|
"user-error",
|
||||||
|
"We still recognise a wrapped ConfigurationError as a user error",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue