mirror of
https://github.com/github/codeql-action.git
synced 2026-10-21 02:01:27 +00:00
Add getDisplayActionName tests
This commit is contained in:
11
lib/entry-points.js
generated
11
lib/entry-points.js
generated
@@ -171409,11 +171409,14 @@ function getAddressString(address) {
|
||||
}
|
||||
|
||||
// src/status-report.ts
|
||||
var ACTION_DISPLAY_NAMES = {
|
||||
["finish" /* Analyze */]: "analyze",
|
||||
["init-post" /* InitPost */]: "init post"
|
||||
};
|
||||
function getDisplayActionName(actionName) {
|
||||
if (actionName === "finish" /* Analyze */) {
|
||||
return "analyze";
|
||||
} else if (actionName === "init-post" /* InitPost */) {
|
||||
return "init post";
|
||||
const displayName = ACTION_DISPLAY_NAMES[actionName];
|
||||
if (displayName !== void 0) {
|
||||
return displayName;
|
||||
}
|
||||
return actionName;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,24 @@ import { getErrorMessage } from "./util";
|
||||
|
||||
setupTests(test);
|
||||
|
||||
for (const [key, displayName] of Object.entries(
|
||||
statusReport.ACTION_DISPLAY_NAMES,
|
||||
)) {
|
||||
test(`getDisplayActionName - '${displayName}' instead of '${key}'`, (t) => {
|
||||
t.is(statusReport.getDisplayActionName(key as ActionName), displayName);
|
||||
});
|
||||
}
|
||||
|
||||
test("getDisplayActionName - returns action name", (t) => {
|
||||
for (const actionName of Object.values(ActionName)) {
|
||||
if (statusReport.ACTION_DISPLAY_NAMES[actionName]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
t.is(statusReport.getDisplayActionName(actionName), actionName);
|
||||
}
|
||||
});
|
||||
|
||||
interface RunInActionsTestOpts {
|
||||
runFn?: () => Promise<any>;
|
||||
expectedErrorMessage?: string;
|
||||
|
||||
@@ -61,15 +61,21 @@ export enum ActionName {
|
||||
UploadSarif = "upload-sarif",
|
||||
}
|
||||
|
||||
/** A partial mapping from `ActionName` to names for actions whose display name is not the `ActionName` value. */
|
||||
export const ACTION_DISPLAY_NAMES: Partial<Record<ActionName, string>> = {
|
||||
[ActionName.Analyze]: "analyze",
|
||||
[ActionName.InitPost]: "init post",
|
||||
};
|
||||
|
||||
/**
|
||||
* Maps an `ActionName` to its display name. Usually that is the same, except
|
||||
* for `ActionName.Analyze` where it is `"analyze"` instead of `"finish"`.
|
||||
* Maps an {@link ActionName} to its display name. Usually that is the same, except
|
||||
* for actions which have a different display name in {@link ACTION_DISPLAY_NAMES}.
|
||||
*/
|
||||
export function getDisplayActionName(actionName: ActionName): string {
|
||||
if (actionName === ActionName.Analyze) {
|
||||
return "analyze";
|
||||
} else if (actionName === ActionName.InitPost) {
|
||||
return "init post";
|
||||
const displayName = ACTION_DISPLAY_NAMES[actionName];
|
||||
|
||||
if (displayName !== undefined) {
|
||||
return displayName;
|
||||
}
|
||||
return actionName;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user