Skip to content

Commit

Permalink
refactor(test): use a fixture rather than afterEach for coverage (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
divdavem authored Nov 27, 2023
1 parent ff83ff7 commit 570275b
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 50 deletions.
2 changes: 1 addition & 1 deletion e2e/accordion/accordion.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
3 changes: 1 addition & 2 deletions e2e/alert/alert.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion e2e/demo.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
32 changes: 16 additions & 16 deletions e2e/fixture.ts
Original file line number Diff line number Diff line change
@@ -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<FixtureOptions>({
framework: [undefined, {option: true}],
});
test.afterEach(afterEach);
return test;
}
export const test = base.extend<FixtureOptions>({
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},
],
});
3 changes: 1 addition & 2 deletions e2e/focustrack/focustrack.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {expect, getTest} from '../fixture';
import {expect, test} from '../fixture';
import {FocusTrackPO} from '../demo-po/focustrack.po';

type PromiseValue<T> = T extends Promise<infer U> ? U : never;
type State = PromiseValue<ReturnType<FocusTrackPO['getState']>>;

const test = getTest();
test.describe(`Select tests`, () => {
test.beforeEach(async ({page}) => {
await page.goto('#/focustrack/focustrack');
Expand Down
3 changes: 1 addition & 2 deletions e2e/modal/modal.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
3 changes: 1 addition & 2 deletions e2e/navmanager/navmanager.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -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}) => {
Expand Down
3 changes: 1 addition & 2 deletions e2e/pagination/pagination.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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: []};
Expand Down
4 changes: 1 addition & 3 deletions e2e/progressbar/progressbar.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
3 changes: 1 addition & 2 deletions e2e/rating/rating.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -12,7 +12,6 @@ function createArray<T>(length: number, value: T) {
return array;
}

const test = getTest();
test.describe.parallel(`Rating tests`, () => {
test(`Basic features`, async ({page}) => {
const ratingDemoPO = new RatingDemoPO(page);
Expand Down
13 changes: 2 additions & 11 deletions e2e/samplesMarkup.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions e2e/select/select.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -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> = T extends Promise<infer U> ? U : never;
type State = PromiseValue<ReturnType<SelectPO['state']>>;

const test = getTest();
test.describe.parallel(`Select tests`, () => {
test.beforeEach(async ({page}) => {
await page.goto('#/select/select?filterText=initial value');
Expand Down
3 changes: 1 addition & 2 deletions e2e/slider/slider.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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}) => {
Expand Down
3 changes: 1 addition & 2 deletions e2e/transition/transition.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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');
Expand Down

0 comments on commit 570275b

Please sign in to comment.