UNPKG

e2ed

Version:

E2E testing framework over Playwright

82 lines (81 loc) 2.65 kB
import type { PlaywrightTestArgs } from '@playwright/test'; import type { TestRunStatus } from '../constants/internal'; import type { E2edError } from '../utils/error'; import type { Brand } from './brand'; import type { UtcTimeInMs } from './date'; import type { DeepReadonly } from './deep'; import type { TestRunEvent } from './events'; import type { TestFilePath } from './paths'; import type { StringForLogs } from './string'; import type { TestMetaPlaceholder } from './userland'; /** * Lite test run object with userland metadata. */ export type LiteTestRun<TestMeta = TestMetaPlaceholder> = Readonly<{ endTimeInMs: UtcTimeInMs; mainParams: string; runError: RunError; runHash: RunHash; startTimeInMs: UtcTimeInMs; status: TestRunStatus; }> & TestStaticOptions<TestMeta>; /** * Reject test run. */ export type RejectTestRun = (error: E2edError) => void; /** * Test run error (in string presentation), if any. */ export type RunError = StringForLogs | string | undefined; /** * Hash string of each test run, generated by userland hook. * Used in HTML report as url-hash for test runs. */ export type RunHash = Brand<string, 'RunHash'>; /** * Unique id of each test run. */ export type RunId = Brand<string, 'RunId'>; /** * Test function itself. */ export type TestFn = (testController: PlaywrightTestArgs) => Promise<void>; /** * Test options with userland metadata. */ export type TestOptions<TestMeta = TestMetaPlaceholder> = DeepReadonly<{ enableCsp?: boolean; meta: TestMeta; takeFullPageScreenshotOnError?: boolean; takeViewportScreenshotOnError?: boolean; testIdleTimeout?: number; testTimeout?: number; } & ({ viewportHeight: number; viewportWidth: number; } | { viewportHeight?: undefined; viewportWidth?: undefined; })>; /** * The complete static test options, that is, the options * available from the code before the tests are run. */ export type TestStaticOptions<TestMeta = TestMetaPlaceholder> = Readonly<{ filePath: TestFilePath; name: string; options: TestOptions<TestMeta>; }>; /** * Completed test run object with userland metadata. * Not internal because it used in user hooks. */ export type TestRun<TestMeta = TestMetaPlaceholder> = Readonly<{ endTimeInMs: UtcTimeInMs; runError: RunError; startTimeInMs: UtcTimeInMs; }> & Omit<TestRunEvent<TestMeta>, 'onlog' | 'reject' | 'testFnWithReject' | 'utcTimeInMs'>; /** * Test function as part of public API, with userland metadata. */ export type TestFunction<TestMeta = TestMetaPlaceholder> = (name: string, options: TestOptions<TestMeta>, testFn: TestFn) => void;