Last active
June 19, 2023 22:12
-
-
Save graffhyrum/db93289417bd33d739f2f68ac597658c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| //annotation_list.ts | |
| export const ANNOTATIONKEY = ['fixme', 'skip', 'fail', 'slow'] as const; | |
| export type AnnotationKey = (typeof ANNOTATIONKEY)[number]; | |
| type Defect = { | |
| jira: string; | |
| ids: string[]; | |
| }; | |
| type AnnotationList = Record<AnnotationKey, Defect[]>; | |
| /** | |
| * This is a static list of the tests that are known to have issues. | |
| * Strictly speaking, entries should follow the format provided of | |
| * jira and CaseID, but functionally you can put any unique substring | |
| * into a test title and pass it in the ids array. | |
| * | |
| * This file is consumed by the fixture.ts file, which uses an | |
| * auto-applied fixture to dynamically annotate the tests. | |
| * | |
| * @example | |
| * const TESTLIST = { | |
| * fail: [ | |
| * { | |
| * jira: 'https://acme.atlassian.net/browse/DEV-1112', | |
| * ids: ['C0002', 'C0001', 'C0000'], | |
| * } | |
| * ], | |
| * skip: [ | |
| * { | |
| * jira: 'https://acme.atlassian.net/browse/DEV-1111', | |
| * ids: ["C00003"], | |
| * }, | |
| * ], | |
| */ | |
| export const TESTLIST: AnnotationList = { | |
| fail: [ | |
| { | |
| jira: 'https://acme.atlassian.net/browse/DEV-1112', | |
| ids: ['C0001', 'C0000'], | |
| } | |
| ], | |
| skip: [ | |
| { | |
| jira: 'https://acme.atlassian.net/browse/DEV-1111', | |
| ids: ["C0003"], | |
| }, | |
| ], | |
| slow: [], | |
| fixme: [] | |
| } |
This file contains hidden or 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
| // unrelated typescript Entries helper | |
| export type Entries<T> = { | |
| [K in keyof T]-?: [K, T[K]]; | |
| }[keyof T][]; | |
| export const getEntries = <T extends object>(obj: T): Entries<T> => { | |
| return Object.entries(obj) as Entries<T>; | |
| }; |
This file contains hidden or 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
| // fixtures.ts | |
| import {test as base} from '@playwright/test'; | |
| import getEntries from 'better_entries'; | |
| export const test = base.extend<{ annotator: void}>({ | |
| annotator: [ | |
| // eslint-disable-next-line no-empty-pattern | |
| async ({}, use, testInfo) => { | |
| annotateTest(); | |
| await use(); | |
| /** | |
| * Annotate a test with the appropriate annotation based on the ID in the | |
| * test title. | |
| */ | |
| function annotateTest() { | |
| for (const [annotation, defects] of getEntries(TESTLIST)) { | |
| if (defects.some(defect => defect.ids.some(id => testInfo.title.includes(id)))) { | |
| switch (annotation) { | |
| case "fixme": | |
| test.fixme(); | |
| break; | |
| case "skip": | |
| test.skip(); | |
| break; | |
| case "fail": | |
| test.fail(); | |
| break; | |
| case "slow": | |
| test.slow(); | |
| break; | |
| } | |
| } | |
| } | |
| } | |
| }, { auto: true } | |
| ] | |
| } | |
| ) | |
This file contains hidden or 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
| // my_tests.spec.ts | |
| import test from './fixtures'; | |
| test('C0000 - This test will fail', async ({}) => { | |
| // test code | |
| }); | |
| test('C0001 - This test will also fail', async ({}) => { | |
| // test code | |
| }); | |
| test('C0002 - This test will pass', async ({}) => { | |
| // test code | |
| }); | |
| test('C0003 - This test will skip', async ({}) => { | |
| // test code | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment