diff --git a/e2e/accordion/accordion.e2e-spec.ts b/e2e/accordion/accordion.e2e-spec.ts index a82be9c4ea..4090b6af8f 100644 --- a/e2e/accordion/accordion.e2e-spec.ts +++ b/e2e/accordion/accordion.e2e-spec.ts @@ -1,4 +1,4 @@ -import {expect, test} from '@playwright/test'; +import {expect, test} from '../fixture'; import {AccordionPO} from '@agnos-ui/page-objects'; import {AccordionTogglePanels} from '../demo-po/accordion.po'; diff --git a/e2e/alert/alert.e2e-spec.ts b/e2e/alert/alert.e2e-spec.ts index afc9fbb098..420ea1e117 100644 --- a/e2e/alert/alert.e2e-spec.ts +++ b/e2e/alert/alert.e2e-spec.ts @@ -1,8 +1,7 @@ import {AlertPO} from '@agnos-ui/page-objects'; -import {expect, getTest} from '../fixture'; +import {expect, test} from '../fixture'; import {AlertDemoPO} from '../demo-po/alert.po'; -const test = getTest(); test.describe(`Alert tests`, () => { test(`Config alert`, async ({page}) => { const alertDemoPO = new AlertDemoPO(page); diff --git a/e2e/demo.spec.ts b/e2e/demo.spec.ts index 890bbd97da..7997713f28 100644 --- a/e2e/demo.spec.ts +++ b/e2e/demo.spec.ts @@ -1,5 +1,5 @@ import type {Page} from '@playwright/test'; -import {test, expect} from '@playwright/test'; +import {test, expect} from './fixture'; import AxeBuilder from '@axe-core/playwright'; import type {AxeResults} from 'axe-core'; import {globSync} from 'glob'; diff --git a/e2e/fixture.ts b/e2e/fixture.ts index 35560227f6..6eae8645bf 100644 --- a/e2e/fixture.ts +++ b/e2e/fixture.ts @@ -1,25 +1,25 @@ import reportCoverage from '@agnos-ui/code-coverage/reportCoverage'; -import type {Page, TestInfo} from '@playwright/test'; import {test as base} from '@playwright/test'; -async function afterEach({page}: {page: Page}, testInfo: TestInfo) { - const coverage: string = await page.evaluate(() => { - return JSON.stringify((window as any).__coverage__); - }); - if (coverage && testInfo.project.name.endsWith(':chromium')) { - reportCoverage(__dirname, coverage); - } -} export {expect} from '@playwright/test'; export type FixtureOptions = { framework?: string; + coverage: void; }; -export function getTest() { - const test = base.extend({ - framework: [undefined, {option: true}], - }); - test.afterEach(afterEach); - return test; -} +export const test = base.extend({ + framework: [undefined, {option: true}], + coverage: [ + async ({page, browserName}, use) => { + await use(); + const coverage: string = await page.evaluate(() => { + return JSON.stringify((window as any).__coverage__); + }); + if (coverage && browserName === 'chromium') { + reportCoverage(__dirname, coverage); + } + }, + {auto: true}, + ], +}); diff --git a/e2e/focustrack/focustrack.e2e-spec.ts b/e2e/focustrack/focustrack.e2e-spec.ts index f774d99776..4b20ef988b 100644 --- a/e2e/focustrack/focustrack.e2e-spec.ts +++ b/e2e/focustrack/focustrack.e2e-spec.ts @@ -1,10 +1,9 @@ -import {expect, getTest} from '../fixture'; +import {expect, test} from '../fixture'; import {FocusTrackPO} from '../demo-po/focustrack.po'; type PromiseValue = T extends Promise ? U : never; type State = PromiseValue>; -const test = getTest(); test.describe(`Select tests`, () => { test.beforeEach(async ({page}) => { await page.goto('#/focustrack/focustrack'); diff --git a/e2e/modal/modal.e2e-spec.ts b/e2e/modal/modal.e2e-spec.ts index ab817222c3..b74856b0d7 100644 --- a/e2e/modal/modal.e2e-spec.ts +++ b/e2e/modal/modal.e2e-spec.ts @@ -1,8 +1,7 @@ -import {expect, getTest} from '../fixture'; +import {expect, test} from '../fixture'; import {ModalDefaultDemoModalPO, ModalDemoPO, ModalStackDemoModalPO} from '../demo-po/modal.po'; import {ModalPO} from '@agnos-ui/page-objects'; -const test = getTest(); test.describe.parallel(`Modal tests`, () => { test(`Default modal`, async ({page}) => { const modalDemoPO = new ModalDemoPO(page); diff --git a/e2e/navmanager/navmanager.e2e-spec.ts b/e2e/navmanager/navmanager.e2e-spec.ts index f49fbcd195..9c1d9a3b11 100644 --- a/e2e/navmanager/navmanager.e2e-spec.ts +++ b/e2e/navmanager/navmanager.e2e-spec.ts @@ -1,8 +1,7 @@ import type {Page} from '@playwright/test'; import {NavManagerLinePO, NavManagerPO} from '../demo-po/navmanager.po'; -import {expect, getTest} from '../fixture'; +import {expect, test} from '../fixture'; -const test = getTest(); for (const sample of ['navmanager', 'navmanagerwithselector']) { test.describe(sample, () => { test.beforeEach(async ({page}) => { diff --git a/e2e/pagination/pagination.e2e-spec.ts b/e2e/pagination/pagination.e2e-spec.ts index 1d8612d7c1..91e30c31aa 100644 --- a/e2e/pagination/pagination.e2e-spec.ts +++ b/e2e/pagination/pagination.e2e-spec.ts @@ -1,4 +1,4 @@ -import {expect, getTest} from '../fixture'; +import {expect, test} from '../fixture'; import {PaginationPO} from '@agnos-ui/page-objects'; import {PaginationDemoPO} from '../demo-po/pagination.po'; interface returnState { @@ -11,7 +11,6 @@ interface returnState { isLastDisabled?: boolean; } -const test = getTest(); async function paginationState(paginationPO: PaginationPO) { return paginationPO.locatorRoot.evaluate((rootNode: HTMLElement) => { const returnState: returnState = {rootClasses: [], disabled: null, pages: []}; diff --git a/e2e/progressbar/progressbar.e2e-spec.ts b/e2e/progressbar/progressbar.e2e-spec.ts index 2bab35cdf5..0e0418307f 100644 --- a/e2e/progressbar/progressbar.e2e-spec.ts +++ b/e2e/progressbar/progressbar.e2e-spec.ts @@ -1,9 +1,7 @@ import {ProgressbarPO} from '@agnos-ui/page-objects'; -import {expect, getTest} from '../fixture'; +import {expect, test} from '../fixture'; import {ProgressbarDemoPO} from 'e2e/demo-po/progressbar.po'; -const test = getTest(); - test.describe(`Progressbar tests`, () => { test(`Default progressbar`, async ({page}) => { const progressbarDemoPO = new ProgressbarDemoPO(page); diff --git a/e2e/rating/rating.e2e-spec.ts b/e2e/rating/rating.e2e-spec.ts index 4340092851..127f58c881 100644 --- a/e2e/rating/rating.e2e-spec.ts +++ b/e2e/rating/rating.e2e-spec.ts @@ -1,4 +1,4 @@ -import {expect, getTest} from '../fixture'; +import {expect, test} from '../fixture'; import {RatingPO} from '@agnos-ui/page-objects'; import {RatingDemoPO} from '../demo-po/rating.po'; @@ -12,7 +12,6 @@ function createArray(length: number, value: T) { return array; } -const test = getTest(); test.describe.parallel(`Rating tests`, () => { test(`Basic features`, async ({page}) => { const ratingDemoPO = new RatingDemoPO(page); diff --git a/e2e/samplesMarkup.e2e-spec.ts b/e2e/samplesMarkup.e2e-spec.ts index b67890bddc..1109df1c13 100644 --- a/e2e/samplesMarkup.e2e-spec.ts +++ b/e2e/samplesMarkup.e2e-spec.ts @@ -1,5 +1,5 @@ import type {Page} from '@playwright/test'; -import {expect, test} from '@playwright/test'; +import {expect, test} from './fixture'; import {globSync} from 'glob'; import path from 'path'; import {openDemoModal} from './demo-po/modal.po'; @@ -24,16 +24,7 @@ test.describe.parallel(`Samples markup consistency check`, () => { }; for (const route of allRoutes) { - test(`${route} should have a consistent markup`, async ({page}, testInfo) => { - test.skip(route === 'pagination/pagination', 'FIXME: sample to be made consistent'); - // skipping accordion playground for angular until we handle playground config better for components like accordion - if (route === 'accordion/playground' && testInfo.project.name.startsWith('angular:')) { - test.skip(); - } - // skipping consistency checks for react and svelte for slider - // if (route.startsWith('slider') && (testInfo.project.name.startsWith('react:') || testInfo.project.name.startsWith('svelte:'))) { - // test.skip(); - // } + test(`${route} should have a consistent markup`, async ({page}) => { await page.goto(`#/${route}${routesExtraHash[route] ?? ''}`); await expect.poll(async () => (await page.locator('#root').innerHTML()).trim().length).toBeGreaterThan(0); await routesExtraAction[route]?.(page); diff --git a/e2e/select/select.e2e-spec.ts b/e2e/select/select.e2e-spec.ts index a2eff9d51e..7cb3b255fe 100644 --- a/e2e/select/select.e2e-spec.ts +++ b/e2e/select/select.e2e-spec.ts @@ -1,11 +1,10 @@ -import {expect, getTest} from '../fixture'; +import {expect, test} from '../fixture'; import {SelectPO} from '@agnos-ui/page-objects'; import {SelectDemoPO} from '../demo-po/select.po'; type PromiseValue = T extends Promise ? U : never; type State = PromiseValue>; -const test = getTest(); test.describe.parallel(`Select tests`, () => { test.beforeEach(async ({page}) => { await page.goto('#/select/select?filterText=initial value'); diff --git a/e2e/slider/slider.e2e-spec.ts b/e2e/slider/slider.e2e-spec.ts index 721491781c..f7c798f8af 100644 --- a/e2e/slider/slider.e2e-spec.ts +++ b/e2e/slider/slider.e2e-spec.ts @@ -1,6 +1,6 @@ import {SliderPO} from '@agnos-ui/page-objects'; import {SliderDemoPO} from '../demo-po/slider.po'; -import {getTest, expect} from '../fixture'; +import {test, expect} from '../fixture'; const defaultExpectedState: {[key: string]: string | null} = { value: '60', @@ -59,7 +59,6 @@ const defaultExpectedHandleStateVertical: {[key: string]: string | null}[] = [ }, ]; -const test = getTest(); test.describe(`Slider tests`, () => { test.describe(`Basic slider`, () => { test(`should snap the handle to correct tick on the slider click event`, async ({page}) => { diff --git a/e2e/transition/transition.e2e-spec.ts b/e2e/transition/transition.e2e-spec.ts index a6f5ce6906..80d862de1f 100644 --- a/e2e/transition/transition.e2e-spec.ts +++ b/e2e/transition/transition.e2e-spec.ts @@ -1,4 +1,4 @@ -import {expect, getTest} from '../fixture'; +import {expect, test} from '../fixture'; import type {State} from '../demo-po/transition.po'; import {TransitionPO} from '../demo-po/transition.po'; @@ -20,7 +20,6 @@ const disableAnimationSetting = async (po: TransitionPO, expectedState: State) = await expect.poll(() => po.getState()).toEqual(expectedState); }; -const test = getTest(); test.describe.parallel('Transition tests', () => { test.beforeEach(async ({page}) => { await page.goto('#/transition/transition');