Skip to content

Commit

Permalink
feat: add error methods
Browse files Browse the repository at this point in the history
  • Loading branch information
syzzana committed Nov 24, 2023
1 parent 8d241c9 commit 35d7ca4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 28 deletions.
47 changes: 22 additions & 25 deletions action-template/action-colors.ts → color-text/ansi-colors.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
const ColorReset = "\x1b[0m";

export type ColorOptions = {
isDimmed?: boolean;
backgroundColor?: BackgroundColor;
foregroundColor?: ForegroundColor;
isBold?: boolean;
isUnderlined?: boolean;
isBlinking?: boolean;
withTextEffectBg?: TextEffect
withTextEffectFg?: TextEffect
};
enum TextEffect {
export enum TextEffect {
Bright = "\x1b[1m",
Dim = "\x1b[2m",
Underscore = "\x1b[4m",
Expand All @@ -17,7 +15,7 @@ enum TextEffect {
Hidden = "\x1b[8m"
}

enum ForegroundColor {
export enum ForegroundColor {
Black = "\x1b[30m",
Red = "\x1b[31m",
Green = "\x1b[32m",
Expand All @@ -27,34 +25,33 @@ enum ForegroundColor {
Cyan = "\x1b[36m",
White = "\x1b[37m"
}

enum BackgroundColor { //TODO implement background colors
Black = "",
Red = "",
Green = "",
Yellow = "",
Blue = "",
Magenta = "",
Cyan = "",
White = ""
export enum BackgroundColor { //TODO implement background colors
Black = "\x1b[40m",
Red = "\x1b[41m",
Green = "\x1b[42m",
Yellow = "\x1b[43m",
Blue = "\x1b[44m",
Magenta = "\x1b[45m",
Cyan = "\x1b[46m",
White = "\x1b[47m"
}

export const color = (text: string, options?: ColorOptions) => {
let bgStyle = "";
let fgStyle = "";
let myStyledText = "";
if (options?.foregroundColor) {
myStyledText += options.foregroundColor;
fgStyle += options.foregroundColor;
}
if (options?.backgroundColor) {
myStyledText += options.backgroundColor;
}
if (options?.isBold) {
myStyledText += TextEffect.Bright;
bgStyle += options.backgroundColor;
}
if (options?.isDimmed) {
myStyledText += TextEffect.Dim;
if (options?.withTextEffectFg) {
fgStyle += options.withTextEffectFg;
}
if (options?.isUnderlined) {
myStyledText += TextEffect.Underscore;
if (options?.withTextEffectBg) {
bgStyle += options.withTextEffectBg;
}
myStyledText = `${fgStyle}${bgStyle}`;
return `${myStyledText}${text}${ColorReset}`;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"author": "Syzana Bicaj",
"license": "MIT",
"dependencies": {
"playwright": "^1.39.0",
"playwright": "^1.40.0",
"@playwright/test": "^1.39.0",
"@types/node": "^20.6.1",
"@typescript-eslint/eslint-plugin": "^6.9.1",
Expand Down
18 changes: 18 additions & 0 deletions src/indent-list-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,24 @@ class IndentListReporter implements Reporter {
}
}

onError(error: TestError) {
log(color.bgBlack("ERROR:").red);
log(color.red(error.message));
}

async onExit(): Promise<void> {
await Promise.resolve();
process.exit(0);
}

onStdErr(chunk: Buffer | string, test:void|TestCase, result: void|TestResult) {
log(chunk.toString());
}

onStdOut(chunk: Buffer | string, test:void|TestCase, result: void|TestResult) {
log(chunk.toString());
}

onEnd(result: FullResult) {
const myTests = filterDuplicateSpecNames(this.allTests);
logTestResults(myTests);
Expand Down
4 changes: 2 additions & 2 deletions tests/placeholder/thirdlevel/subtest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ test.describe.serial("SUB API", async () => {
});
});

const status = 200;
const testM3e = "test me";
test.describe("SUB SUB API 22", async () => {
test("sub 22 authentication", async () => {
const status = 200;
expect(status).toBe(200);
});

test("sub 23 unauthorized", async () => {
const status = 200;
expect(status).toBe(200);
});
});

0 comments on commit 35d7ca4

Please sign in to comment.