import type { TestInfo } from '@playwright/test'; import type { Entry, HarLookupParamsTransformFunction, HarLookupResultTransformFunction } from '../../har'; export type MockNetworkFixtureBuilderParams = { /** * Update dumps or not * @defaultValue `false` */ shouldUpdate: boolean; /** * Always update dumps if they are missing * @defaultValue `false` */ forceUpdateIfHarMissing?: boolean; /** * Custom timeout for updating tests. Milliseconds. * Useful for long updates */ updateTimeout?: number; /** * Archive dumps * @defaultValue true */ zip?: boolean; /** *The address pattern of requests that will be written to .har. Inappropriate requests will be skipped. * @param baseURL string The base address of the page. * @returns string | RegExp Regular expression prepared template; Glob or RegExp. */ url: (baseURL: string) => string | RegExp; /** * Custom path to the dump file. Overrides the path generated by dumpsPath. * @param params Parameters for constructing a path: * @param params.testInfo TestInfo information about the current test * @param params.zip Flag to use zip archive for .har * * @returns string path to dump file */ dumpsFilePath?: (params: { testInfo: TestInfo; zip: boolean; }) => string; /** * Additional headers that will be removed before writing the request to .har * By default, the following headers are removed: `cookie`, `x-csrf-token`, `content-security-policy`, `Session_id` */ headersToRemove?: string[]; /** * Additional set-cookie values for which set-cookie headers will be removed * By default, set-cookies are removed for the following values: with`CSRF-TOKEN` */ setCookieToRemove?: string[]; /** * Callback for processing requests and responses by saving to .har. Useful for various post-processing of requests: cleaning, changing format, etc. * By default, sensitive headers are removed + the base url of the request is changed to a stub * @param entry The entry in .har that will be written * @param baseURL The base URL of the test */ onHarEntryWillWrite?: (entry: Entry, baseURL: string) => void; /** * Callback to process requests and responses written in .har before they are used * Useful for reverting changes made in onHarEntryWillWrite * By default, the base url templates are replaced with the actual baseUrl of the test * @param entry The entry in .har that will be used * @param baseURL The base URL of the test */ onHarEntryWillRead?: (entry: Entry, baseURL: string) => void; /** * Callback for changing search parameters of queries in .har * @param params The lookup parameters * @param baseURL The base URL of the test */ onTransformHarLookupParams?: (params: Parameters[0], baseURL: string) => ReturnType; /** * Callback for transforming the search query result into .har * @param result The lookup result * @param params The lookup parameters * @param baseURL The base URL of the test */ onTransformHarLookupResult?: (result: Parameters[0], params: Parameters[1], baseURL: string) => ReturnType; /** * Flag to enable or disable adding the x-tests-duplicate-id header for identical requests * By default, the header is not added * @defaultValue `false` */ shouldMarkIdenticalRequests?: boolean; }; export type MockNetworkTestArgs = { isMockingEnabled: boolean; }; export type MockNetworkTestOptions = { enableNetworkMocking: boolean; }; export type MockNetworkWorkerArgs = {}; export type MockNetworkWorkerOptions = {}; export type MockNetworkTestFixtures = MockNetworkTestArgs & MockNetworkTestOptions; export type MockNetworkWorkerFixtures = MockNetworkWorkerArgs & MockNetworkWorkerOptions; export type MockNetworkFixtures = MockNetworkTestFixtures & MockNetworkWorkerFixtures;