-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added dependency manager for tests
- Loading branch information
Showing
5 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { Reporter, TestCase, TestResult } from '@playwright/test/reporter'; | ||
import { TestDependencyManager } from '@/test-utils/dependency-manager'; | ||
|
||
export default class DependencyReporter implements Reporter { | ||
private manager = TestDependencyManager.getInstance(); | ||
private skippedTests: Map<string, string> = new Map(); | ||
|
||
onTestEnd(test: TestCase, result: TestResult) { | ||
if (result.status === 'skipped') { | ||
this.skippedTests.set( | ||
test.title, | ||
this.manager.getDependencyFailureReason(test.title), | ||
); | ||
} | ||
} | ||
|
||
onEnd() { | ||
console.log('\nDependency Failure Report:'); | ||
this.skippedTests.forEach((reason, test) => { | ||
console.log(`${test}: Skipped due to: ${reason}`); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { test as base } from '@playwright/test'; | ||
import { TestDependencyManager } from '@/test-utils/dependency-manager'; | ||
|
||
type BaseFixtures = { | ||
dependencyManager: TestDependencyManager; | ||
testInfo: { id: string }; | ||
}; | ||
|
||
export const test = base.extend<BaseFixtures>({ | ||
dependencyManager: async ({}, use) => { | ||
const manager = TestDependencyManager.getInstance(); | ||
await use(manager); | ||
}, | ||
|
||
testInfo: [async ({}, use, testInfo) => { | ||
const info = { | ||
id: testInfo.title, | ||
}; | ||
await use(info); | ||
}, { auto: true }], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
export class TestDependencyManager { | ||
private static instance: TestDependencyManager; | ||
private statusMap: Map<string, boolean> = new Map(); | ||
private dependencyGraph: Map<string, string[]> = new Map(); | ||
private errorMessages: Map<string, string> = new Map(); | ||
|
||
private constructor() { | ||
} | ||
|
||
static getInstance(): TestDependencyManager { | ||
if (!TestDependencyManager.instance) { | ||
TestDependencyManager.instance = new TestDependencyManager(); | ||
} | ||
return TestDependencyManager.instance; | ||
} | ||
|
||
registerTest(testId: string, dependencies: string[] = []) { | ||
this.dependencyGraph.set(testId, dependencies); | ||
this.statusMap.set(testId, false); | ||
} | ||
|
||
setTestStatus(testId: string, passed: boolean, errorMessage?: string) { | ||
this.statusMap.set(testId, passed); | ||
if (!passed && errorMessage) { | ||
this.errorMessages.set(testId, errorMessage); | ||
} | ||
} | ||
|
||
canRunTest(testId: string): boolean { | ||
const dependencies = this.dependencyGraph.get(testId) || []; | ||
return dependencies.every(depId => this.statusMap.get(depId)); | ||
} | ||
|
||
getDependencyFailureReason(testId: string): string { | ||
const dependencies = this.dependencyGraph.get(testId) || []; | ||
const failedDeps = dependencies.filter(depId => !this.statusMap.get(depId)); | ||
return failedDeps | ||
.map(depId => `${depId}: ${this.errorMessages.get(depId)}`) | ||
.join(', '); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.