From 35d7ca456e11fd5616303ce18c1848394aa57f6b Mon Sep 17 00:00:00 2001 From: syzzana Date: Fri, 24 Nov 2023 22:55:37 +0100 Subject: [PATCH] feat: add error methods --- .../ansi-colors.ts | 47 +++++++++---------- package.json | 2 +- src/indent-list-reporter.ts | 18 +++++++ tests/placeholder/thirdlevel/subtest.spec.ts | 4 +- 4 files changed, 43 insertions(+), 28 deletions(-) rename action-template/action-colors.ts => color-text/ansi-colors.ts (50%) diff --git a/action-template/action-colors.ts b/color-text/ansi-colors.ts similarity index 50% rename from action-template/action-colors.ts rename to color-text/ansi-colors.ts index f59f2c6..7106d9c 100644 --- a/action-template/action-colors.ts +++ b/color-text/ansi-colors.ts @@ -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", @@ -17,7 +15,7 @@ enum TextEffect { Hidden = "\x1b[8m" } -enum ForegroundColor { +export enum ForegroundColor { Black = "\x1b[30m", Red = "\x1b[31m", Green = "\x1b[32m", @@ -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}`; } \ No newline at end of file diff --git a/package.json b/package.json index a02c96d..f811d85 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/indent-list-reporter.ts b/src/indent-list-reporter.ts index 5f595f5..86036b6 100644 --- a/src/indent-list-reporter.ts +++ b/src/indent-list-reporter.ts @@ -85,6 +85,24 @@ class IndentListReporter implements Reporter { } } + onError(error: TestError) { + log(color.bgBlack("ERROR:").red); + log(color.red(error.message)); + } + + async onExit(): Promise { + 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); diff --git a/tests/placeholder/thirdlevel/subtest.spec.ts b/tests/placeholder/thirdlevel/subtest.spec.ts index b76c66c..92ac480 100644 --- a/tests/placeholder/thirdlevel/subtest.spec.ts +++ b/tests/placeholder/thirdlevel/subtest.spec.ts @@ -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); }); });