From f53991780247909d8d94a52bc51df98bfb111e23 Mon Sep 17 00:00:00 2001 From: Mohammad Rad Date: Mon, 16 Dec 2024 00:09:14 -0800 Subject: [PATCH] feat: add Sequential Naming with Context --- packages/shortest/src/index.ts | 6 ++++-- packages/shortest/src/types/test.ts | 1 + packages/shortest/src/utils/logger.ts | 17 ++++++++++------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/shortest/src/index.ts b/packages/shortest/src/index.ts index 6c8d5f4d..f68e1a44 100644 --- a/packages/shortest/src/index.ts +++ b/packages/shortest/src/index.ts @@ -30,7 +30,8 @@ if (!global.__shortest__) { beforeAllFns: [], afterAllFns: [], beforeEachFns: [], - afterEachFns: [] + afterEachFns: [], + directTestCounter: 0 } }; @@ -117,12 +118,13 @@ function createTestChain( // Handle direct execution if (typeof nameOrFn === 'function') { + registry.directTestCounter++; const test: TestFunction = { + name: `Direct Test #${registry.directTestCounter}`, directExecution: true, fn: nameOrFn }; registry.currentFileTests.push(test); - // Return empty chain for type compatibility return { expect: () => { throw new Error('expect() cannot be called on direct execution test'); diff --git a/packages/shortest/src/types/test.ts b/packages/shortest/src/types/test.ts index 0f273bb2..b3a39e99 100644 --- a/packages/shortest/src/types/test.ts +++ b/packages/shortest/src/types/test.ts @@ -84,6 +84,7 @@ export type TestRegistry = { afterAllFns: TestHookFunction[]; beforeEachFns: TestHookFunction[]; afterEachFns: TestHookFunction[]; + directTestCounter: number; }; export type { Page } from 'playwright'; diff --git a/packages/shortest/src/utils/logger.ts b/packages/shortest/src/utils/logger.ts index ecc3bb88..999a08b9 100644 --- a/packages/shortest/src/utils/logger.ts +++ b/packages/shortest/src/utils/logger.ts @@ -19,15 +19,18 @@ export class Logger { console.log(pc.blue(`\nšŸ“„ ${pc.bold(this.currentFile)}`)); } - reportTest(name: string, status: TestStatus = 'passed', error?: Error) { - const icon = this.getStatusIcon(status); - console.log(` ${icon} ${name}`); + reportTest(name: string | undefined, status: 'passed' | 'failed', error?: Error) { + const testName = name || 'Unnamed Test'; + const symbol = status === 'passed' ? 'āœ“' : 'āœ—'; + const color = status === 'passed' ? pc.green : pc.red; + + console.log(` ${color(symbol)} ${testName}`); - if (status === 'failed' && error?.message) { - console.log(pc.red(` Reason: ${error.message}`)); + if (error) { + console.log(pc.red(` ${error.message}`)); } - - this.testResults.push({ name, status, error }); + + this.testResults.push({ name: testName, status, error }); } private getStatusIcon(status: TestStatus): string {