-
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(skip): add skip decorator (#13)
- Loading branch information
1 parent
bff619f
commit db4b064
Showing
7 changed files
with
143 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
// base | ||
export { suite } from './suite.decorator'; | ||
export { test } from './test.decorator'; | ||
// hooks | ||
export { beforeAll } from './beforeAll.decorator'; | ||
export { beforeEach } from './beforeEach.decorator'; | ||
export { afterAll } from './afterAll.decorator'; | ||
export { afterEach } from './afterEach.decorator'; | ||
// annotations | ||
export { skip } from './skip.decorator'; |
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,17 @@ | ||
import {SuiteDecoratedMethod} from "./suite.decorator"; | ||
import {TestDecoratedMethod} from "./test.decorator"; | ||
|
||
/** | ||
* Skip @test or @suite (with optional reason). | ||
*/ | ||
export const skip = (reason?: string) => function(originalMethod: any, context?: any) { | ||
if ((originalMethod as SuiteDecoratedMethod)?.suiteDecorator) { | ||
originalMethod.suiteDecorator.skip = reason || true; | ||
return; | ||
} | ||
|
||
if ((originalMethod as TestDecoratedMethod)?.testDecorator) { | ||
originalMethod.testDecorator.skip = reason || true; | ||
return; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,28 +1,44 @@ | ||
import { suite } from '../lib'; | ||
import {skip, suite, test} from '../lib'; | ||
import playwright, {expect} from '@playwright/test'; | ||
|
||
playwright.describe('@suite decorator', () => { | ||
let withSuiteDecoratorRun = false; | ||
let withoutSuiteDecoratorRun = false; | ||
|
||
@suite() | ||
class WithSuiteDecorator { | ||
constructor() { | ||
withSuiteDecoratorRun = true; | ||
playwright.describe('Class with @suite should be initialized', () => { | ||
const called: string[] = []; | ||
|
||
@suite() | ||
class WithSuiteDecorator { | ||
constructor() { | ||
called.push('constructor'); | ||
} | ||
} | ||
} | ||
|
||
class WithoutSuiteDecorator { | ||
constructor() { | ||
withoutSuiteDecoratorRun = true; | ||
} | ||
} | ||
|
||
playwright('Class with @suite should be initialized', () => { | ||
expect(withSuiteDecoratorRun).toBeTruthy(); | ||
expect(called).toContain('constructor'); | ||
}); | ||
|
||
playwright('Class without @suite should not be initialized', () => { | ||
expect(withoutSuiteDecoratorRun).toBeFalsy(); | ||
const called: string[] = []; | ||
|
||
class WithoutSuiteDecorator { | ||
constructor() { | ||
called.push('constructor'); | ||
} | ||
} | ||
|
||
expect(called).not.toContain('constructor'); | ||
}); | ||
|
||
playwright.describe('Class with @suite & @skip should not run any tests', () => { | ||
const called: string[] = []; | ||
|
||
@skip() | ||
@suite() | ||
class WithSuiteDecorator { | ||
@test() | ||
testMethod() { | ||
called.push('testMethod'); | ||
} | ||
} | ||
|
||
expect(called).not.toContain(['testMethod']); | ||
}); | ||
}) |
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