-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
161 additions
and
50 deletions.
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
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
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
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
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
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
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
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
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
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
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
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
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
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,35 @@ | ||
import type { | ||
Reporter, FullConfig, Suite, TestCase, TestResult, FullResult, TestStep, Location | ||
} from '@playwright/test/reporter'; | ||
|
||
class SlowStepReporter implements Reporter { | ||
private steps: Array<{ count: number, name: string, location: string | undefined, duration: number }> = []; | ||
|
||
onStepEnd(test: TestCase, result: TestResult, step: TestStep) { | ||
if (step.category === 'test.step') { | ||
const stepToReport = { | ||
count: 1, | ||
name: step.titlePath().join('->'), | ||
location: `${step.location?.file}:${step.location?.line}`, | ||
duration: step.duration | ||
} | ||
const alreadyReported = this.steps.find(s => s.name === stepToReport.name); | ||
|
||
if (alreadyReported) { | ||
alreadyReported.count++ | ||
} else { | ||
this.steps.push(stepToReport); | ||
} | ||
} | ||
} | ||
|
||
onEnd() { | ||
console.warn('TOP-10 slowest steps') | ||
console.table( | ||
// Slowest first | ||
this.steps.sort((a, b) => b.duration - a.duration) | ||
// TOP-10 slowest steps | ||
.slice(0, 10)) | ||
} | ||
} | ||
export default SlowStepReporter; |
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,28 @@ | ||
import { test } from '@playwright/test'; | ||
|
||
/** | ||
* Decorator that wraps a function with a Playwright test step. | ||
* Used for reporting purposes. | ||
* | ||
* @example | ||
``` | ||
import { step } from './step_decorator'; | ||
class MyTestClass { | ||
@step('optional step name') | ||
async myTestFunction() { | ||
// Test code goes here | ||
} | ||
} | ||
``` | ||
*/ | ||
export function step<This, Args extends any[], Return>(message?: string) { | ||
return function actualDecorator(target: (this: This, ...args: Args) => Promise<Return>, context: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Promise<Return>>) { | ||
function replacementMethod(this: any, ...args: Args) { | ||
const name = message ?? `${this.constructor.name}.${context.name as string}`; | ||
|
||
return test.step(name, async () => target.call(this, ...args), { box: true }); | ||
} | ||
|
||
return replacementMethod; | ||
} | ||
} |
Oops, something went wrong.