-
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.
- Loading branch information
1 parent
8d69e29
commit 96359e1
Showing
4 changed files
with
102 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {SuiteDecoratedMethod} from "./suite.decorator"; | ||
import {TestDecoratedMethod} from "./test.decorator"; | ||
|
||
/** | ||
* Adds tags to `@test` or `@suite`. | ||
* You can later run test(s) or suite(s) with specific tag, using `npx playwright test --grep "@nameOfTag"` command. | ||
* For example: to run tests/suites with `x` tag, please run `npx playwright test --grep "@x"` | ||
*/ | ||
export const tag = (tags: string[]) => function(originalMethod: any, context?: any) { | ||
const tagsAsPlaywrightAnnotations = tags.map(tag => `@${tag}`).join(' '); | ||
|
||
if ((originalMethod as SuiteDecoratedMethod)?.suiteDecorator) { | ||
originalMethod.suiteDecorator.name = `${originalMethod.suiteDecorator.name} ${tagsAsPlaywrightAnnotations}`; | ||
return; | ||
} | ||
|
||
if ((originalMethod as TestDecoratedMethod)?.testDecorator) { | ||
originalMethod.testDecorator.name = `${originalMethod.testDecorator.name} ${tagsAsPlaywrightAnnotations}`; | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import playwright, {expect} from "@playwright/test"; | ||
import {mockFn} from "./__mocks__/mockFn"; | ||
import {suite, tag, test} from "../lib"; | ||
|
||
playwright.describe('@tag decorator', () => { | ||
playwright.describe('with @suite', () => { | ||
const titlePath: string[] = []; | ||
|
||
@tag(['x']) | ||
@suite() | ||
class SuiteWithTag { | ||
@test() | ||
async test({}, testInfo) { | ||
titlePath.push(...testInfo.titlePath); | ||
} | ||
} | ||
|
||
playwright('should add @x tag to suite name', () => { | ||
expect(titlePath.join('->')).toContain('SuiteWithTag'); | ||
expect(titlePath.join('->')).toContain('@x'); | ||
}); | ||
}) | ||
|
||
playwright.describe('with @test', () => { | ||
const titlePath: string[] = []; | ||
|
||
@suite() | ||
class TestSuite { | ||
@tag(['x']) | ||
@test() | ||
async testWithTag({}, testInfo) { | ||
titlePath.push(...testInfo.titlePath); | ||
} | ||
} | ||
|
||
playwright('should add @x tag to test name', () => { | ||
expect(titlePath.join('->')).toContain('testWithTag'); | ||
expect(titlePath.join('->')).toContain('@x'); | ||
}); | ||
}); | ||
}); |