Skip to content

Commit

Permalink
feat: add Sequential Naming with Context
Browse files Browse the repository at this point in the history
  • Loading branch information
m2rads committed Dec 16, 2024
1 parent 810a86a commit f539917
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
6 changes: 4 additions & 2 deletions packages/shortest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ if (!global.__shortest__) {
beforeAllFns: [],
afterAllFns: [],
beforeEachFns: [],
afterEachFns: []
afterEachFns: [],
directTestCounter: 0
}
};

Expand Down Expand Up @@ -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');
Expand Down
1 change: 1 addition & 0 deletions packages/shortest/src/types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export type TestRegistry = {
afterAllFns: TestHookFunction[];
beforeEachFns: TestHookFunction[];
afterEachFns: TestHookFunction[];
directTestCounter: number;
};

export type { Page } from 'playwright';
Expand Down
17 changes: 10 additions & 7 deletions packages/shortest/src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f539917

Please sign in to comment.