mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2024-11-22 00:11:02 -05:00
Moved FailMode
to its own file
This commit is contained in:
parent
5a2e5f176c
commit
9ca1e9f0d9
2 changed files with 77 additions and 0 deletions
48
src/utils/fail-mode.ts
Normal file
48
src/utils/fail-mode.ts
Normal file
|
@ -0,0 +1,48 @@
|
|||
import { Enum, EnumOptions } from "@/utils/enum";
|
||||
|
||||
/**
|
||||
* Represents different failure modes for handling errors.
|
||||
*
|
||||
* @partial
|
||||
*/
|
||||
enum FailModeValues {
|
||||
/**
|
||||
* Fail mode, halts the operation on encountering an error.
|
||||
*/
|
||||
FAIL,
|
||||
|
||||
/**
|
||||
* Warn mode, logs a warning and continues operation on encountering an error.
|
||||
*/
|
||||
WARN,
|
||||
|
||||
/**
|
||||
* Skip mode, skips the current operation and continues with the next one on encountering an error.
|
||||
*/
|
||||
SKIP,
|
||||
}
|
||||
|
||||
/**
|
||||
* Options for configuring the behavior of the `FailMode` enum.
|
||||
*
|
||||
* @partial
|
||||
*/
|
||||
const FailModeOptions: EnumOptions = {
|
||||
/**
|
||||
* The case should be ignored while parsing the fail mode.
|
||||
*/
|
||||
ignoreCase: true,
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents different failure modes for handling errors.
|
||||
*/
|
||||
export const FailMode = Enum.create(
|
||||
FailModeValues,
|
||||
FailModeOptions,
|
||||
);
|
||||
|
||||
/**
|
||||
* Represents different failure modes for handling errors.
|
||||
*/
|
||||
export type FailMode = Enum<typeof FailModeValues>;
|
29
tests/unit/utils/fail-mode.spec.ts
Normal file
29
tests/unit/utils/fail-mode.spec.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
import { FailMode } from "@/utils/fail-mode";
|
||||
|
||||
describe("FailMode", () => {
|
||||
describe("parse", () => {
|
||||
test("parses all its own formatted values", () => {
|
||||
for (const value of FailMode.values()) {
|
||||
expect(FailMode.parse(FailMode.format(value))).toBe(value);
|
||||
}
|
||||
});
|
||||
|
||||
test("parses all friendly names of its own values", () => {
|
||||
for (const value of FailMode.values()) {
|
||||
expect(FailMode.parse(FailMode.friendlyNameOf(value))).toBe(value);
|
||||
}
|
||||
});
|
||||
|
||||
test("parses all its own formatted values in lowercase", () => {
|
||||
for (const value of FailMode.values()) {
|
||||
expect(FailMode.parse(FailMode.format(value).toLowerCase())).toBe(value);
|
||||
}
|
||||
});
|
||||
|
||||
test("parses all its own formatted values in UPPERCASE", () => {
|
||||
for (const value of FailMode.values()) {
|
||||
expect(FailMode.parse(FailMode.format(value).toUpperCase())).toBe(value);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue