Skip to content

Commit 15d42d2

Browse files
committed
feat(#1349729): add tags to the test as role function and add makefile e2e tag filter
1 parent c1adac1 commit 15d42d2

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,10 @@ phpunit: ## Run php unit tests, pass the parameter "p=" to launch tests on a spe
144144
jest: ## Run jest unit tests
145145
@$(DOCKER_COMP) exec pwa yarn test
146146

147-
e2e: ## Run e2e tests or pass the parameter "f=" to filters tests, example: make e2e f=login
147+
e2e: ## Run e2e tests or pass the parameter "f=" to filters tests and "t=" to run only certain tags, example: make e2e f=login t=standard
148148
@$(eval f ?=)
149-
@$(DOCKER_COMP) exec e2e yarn test $(f)
149+
@$(eval t ?=)
150+
@$(DOCKER_COMP) exec e2e yarn test $(f) $(if $(t),--grep $(t))
150151

151152
jest_update: ## Run jest unit tests
152153
@$(DOCKER_COMP) exec pwa yarn test:update

front/e2e/src/helper/auth.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Page, expect, test} from '@playwright/test'
1+
import { Page, expect, test, TestDetails } from '@playwright/test'
22
import {TestId, generateTestId} from "./testIds";
33

44
const testIds = {
@@ -31,13 +31,22 @@ export enum UserRole {
3131
CONTRIBUTOR = 'contributor',
3232
}
3333

34+
type TestDetailsWithRequiredTag = TestDetails & Required<Pick<TestDetails, 'tag'>>
35+
3436
export function runTestsAsRoles(
3537
roles: UserRole[],
38+
details: TestDetailsWithRequiredTag,
3639
callback: (page: Page, role?: UserRole) => Promise<void>
3740
): void {
41+
// Adds the @multirole to the existing tag, these tests can be slower than the others
42+
// So it might be useful to have an easy way to include/exclude them from a run
43+
const detailsWithMultiroleTag: TestDetailsWithRequiredTag = {
44+
...details,
45+
tag: [...new Set([...details.tag, '@multiroles'])]
46+
}
3847
for (const role of roles) {
3948
// Instantiate an isolated test context for each role
40-
test(`Test as ${role} role`, async ({ page }) => {
49+
test(`Test as ${role} role`, detailsWithMultiroleTag, async ({ page }) => {
4150
await login(page, role)
4251
// Run callback with a page authenticated with the specified role
4352
await callback(page, role)

front/e2e/src/tests/pages/admin/settings/scope.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ test.beforeEach(async ({ context }) => {
185185
});
186186

187187
test.describe('Parameters Page', () => {
188-
runTestsAsRoles([UserRole.ADMIN, UserRole.CONTRIBUTOR], async (page: Page) => {
188+
runTestsAsRoles([UserRole.ADMIN, UserRole.CONTRIBUTOR], { tag: ['@premium', '@standard'] }, async (page: Page) => {
189189
await testParametersPage(page)
190190
})
191191
})

0 commit comments

Comments
 (0)