@@ -23,6 +23,7 @@ import { TimeoutManager, TimeoutManagerError, kMaxDeadline } from './timeoutMana
2323import { addSuffixToFilePath , filteredStackTrace , getContainedPath , normalizeAndSaveAttachment , sanitizeFilePathBeforeExtension , trimLongString , windowsFilesystemFriendlyLength } from '../util' ;
2424import { TestTracing } from './testTracing' ;
2525import { testInfoError } from './util' ;
26+ import { wrapFunctionWithLocation } from '../transform/transform' ;
2627
2728import type { RunnableDescription } from './timeoutManager' ;
2829import type { FullProject , TestInfo , TestStatus , TestStepInfo , TestAnnotation } from '../../types/test' ;
@@ -80,6 +81,12 @@ export class TestInfoImpl implements TestInfo {
8081 _hasUnhandledError = false ;
8182 _allowSkips = false ;
8283
84+ // ------------ Main methods ------------
85+ skip : ( arg ?: any , description ?: string ) => void ;
86+ fixme : ( arg ?: any , description ?: string ) => void ;
87+ fail : ( arg ?: any , description ?: string ) => void ;
88+ slow : ( arg ?: any , description ?: string ) => void ;
89+
8390 // ------------ TestInfo fields ------------
8491 readonly testId : string ;
8592 readonly repeatEachIndex : number ;
@@ -205,9 +212,14 @@ export class TestInfoImpl implements TestInfo {
205212 } ;
206213
207214 this . _tracing = new TestTracing ( this , workerParams . artifactsDir ) ;
215+
216+ this . skip = wrapFunctionWithLocation ( ( location , ...args ) => this . _modifier ( 'skip' , location , args ) ) ;
217+ this . fixme = wrapFunctionWithLocation ( ( location , ...args ) => this . _modifier ( 'fixme' , location , args ) ) ;
218+ this . fail = wrapFunctionWithLocation ( ( location , ...args ) => this . _modifier ( 'fail' , location , args ) ) ;
219+ this . slow = wrapFunctionWithLocation ( ( location , ...args ) => this . _modifier ( 'slow' , location , args ) ) ;
208220 }
209221
210- private _modifier ( type : 'skip' | 'fail' | 'fixme' | 'slow' , modifierArgs : [ arg ?: any , description ?: string ] ) {
222+ _modifier ( type : 'skip' | 'fail' | 'fixme' | 'slow' , location : Location , modifierArgs : [ arg ?: any , description ?: string ] ) {
211223 if ( typeof modifierArgs [ 1 ] === 'function' ) {
212224 throw new Error ( [
213225 'It looks like you are calling test.skip() inside the test and pass a callback.' ,
@@ -222,7 +234,7 @@ export class TestInfoImpl implements TestInfo {
222234 return ;
223235
224236 const description = modifierArgs [ 1 ] ;
225- this . annotations . push ( { type, description } ) ;
237+ this . annotations . push ( { type, description, location } ) ;
226238 if ( type === 'slow' ) {
227239 this . _timeoutManager . slow ( ) ;
228240 } else if ( type === 'skip' || type === 'fixme' ) {
@@ -567,22 +579,6 @@ export class TestInfoImpl implements TestInfo {
567579 return this . _resolveSnapshotPaths ( kind , name . length <= 1 ? name [ 0 ] : name , 'dontUpdateSnapshotIndex' ) . absoluteSnapshotPath ;
568580 }
569581
570- skip ( ...args : [ arg ?: any , description ?: string ] ) {
571- this . _modifier ( 'skip' , args ) ;
572- }
573-
574- fixme ( ...args : [ arg ?: any , description ?: string ] ) {
575- this . _modifier ( 'fixme' , args ) ;
576- }
577-
578- fail ( ...args : [ arg ?: any , description ?: string ] ) {
579- this . _modifier ( 'fail' , args ) ;
580- }
581-
582- slow ( ...args : [ arg ?: any , description ?: string ] ) {
583- this . _modifier ( 'slow' , args ) ;
584- }
585-
586582 setTimeout ( timeout : number ) {
587583 this . _timeoutManager . setTimeout ( timeout ) ;
588584 }
@@ -594,14 +590,25 @@ export class TestStepInfoImpl implements TestStepInfo {
594590 private _testInfo : TestInfoImpl ;
595591 private _stepId : string ;
596592
593+ skip : ( arg ?: any , description ?: string ) => void ;
594+
597595 constructor ( testInfo : TestInfoImpl , stepId : string ) {
598596 this . _testInfo = testInfo ;
599597 this . _stepId = stepId ;
598+ this . skip = wrapFunctionWithLocation ( ( location : Location , ...args : unknown [ ] ) => {
599+ // skip();
600+ // skip(condition: boolean, description: string);
601+ if ( args . length > 0 && ! args [ 0 ] )
602+ return ;
603+ const description = args [ 1 ] as ( string | undefined ) ;
604+ this . annotations . push ( { type : 'skip' , description, location } ) ;
605+ throw new StepSkipError ( description ) ;
606+ } ) ;
600607 }
601608
602- async _runStepBody < T > ( skip : boolean , body : ( step : TestStepInfo ) => T | Promise < T > ) {
609+ async _runStepBody < T > ( skip : boolean , body : ( step : TestStepInfo ) => T | Promise < T > , location ?: Location ) {
603610 if ( skip ) {
604- this . annotations . push ( { type : 'skip' } ) ;
611+ this . annotations . push ( { type : 'skip' , location } ) ;
605612 return undefined as T ;
606613 }
607614 try {
@@ -620,16 +627,6 @@ export class TestStepInfoImpl implements TestStepInfo {
620627 async attach ( name : string , options ?: { body ?: string | Buffer ; contentType ?: string ; path ?: string ; } ) : Promise < void > {
621628 this . _attachToStep ( await normalizeAndSaveAttachment ( this . _testInfo . outputPath ( ) , name , options ) ) ;
622629 }
623-
624- skip ( ...args : unknown [ ] ) {
625- // skip();
626- // skip(condition: boolean, description: string);
627- if ( args . length > 0 && ! args [ 0 ] )
628- return ;
629- const description = args [ 1 ] as ( string | undefined ) ;
630- this . annotations . push ( { type : 'skip' , description } ) ;
631- throw new StepSkipError ( description ) ;
632- }
633630}
634631
635632export class TestSkipError extends Error {
0 commit comments