import type { TopLevelConfig } from '@wixc3/engine-core'; import { type DisposableItem, type DisposableOptions, Disposables } from '@wixc3/patterns'; import playwright from 'playwright-core'; import { spawnSync, type SpawnSyncOptions } from 'node:child_process'; import { getRunningFeature } from '@wixc3/engine-cli'; export interface IFeatureExecutionOptions { /** * feature file name scoped to feature root directory. * if feature name is the same as folder name, scoping is unnecessary. * @example given the following structure: * * --my-feature * -- feature * -- my-feature.feature.ts * -- my-feature2.feature.ts * -- fixtures * -- my-feature-fixture.feature.ts * possible feature names will be: * `my-feature` * `my-feature/my-feature1` * `my-feature/my-feature-fixture` */ featureName?: string; /** * configuration file name scoped to feature root directory. * * @example given the following structure: * --my-feature * -- feature * -- my-feature.feature.ts * -- production.config.ts * -- fixtures * -- dev.config.ts * possible feature names will be: * `my-feature/production` * `my-feature/dev` * */ configName?: string; /** * query parameters to open the page with */ queryParams?: Record; /** * runtime options that will be provided to the node environments */ runOptions?: Record; /** * Allows providing a Top level config * If configName was provided, the matching configurations will be overriden by the config provided */ config?: TopLevelConfig; /** Passed down to `browser.newContext()` */ browserContextOptions?: playwright.BrowserContextOptions; /** * Creates a playwright trace file for the test */ tracing?: boolean | Tracing; /** * Creates a playwright trace file for the test */ navigationOptions?: Parameters[1]; /** * Error messages that are allowed to stay unhandled without failing the tests. * strings are tested for exact match. */ allowedErrors?: Array; /** * console.error allowed errors (defaults to false) */ consoleLogAllowedErrors?: boolean; /** * @defaultValue 20_000 */ featureDisposeTimeout?: number; /** * tracing disposal timeout * @defaultValue 20_000 */ saveTraceTimeout?: number; /** * path to a directory where the fixture will be copied from */ fixturePath?: string; /** * link node_modules for the fixture to the project */ dependencies?: { type: 'link'; path: string; } | { type: 'yarn'; } | { type: 'npm'; }; /** * hook to manage initial fixture creation each hook is inherited from the suite level individually */ hooks?: { afterFixtureCopy?: () => Promise | void; afterInstall?: () => Promise | void; }; } export interface IWithFeatureOptions extends Omit, playwright.LaunchOptions { /** * If we want to test the engine against a running application, provide the port of the application. * It can be extracted from the log printed after 'engine run' */ runningApplicationPort?: number; /** Specify directory where features will be looked up within the package */ featureDiscoveryRoot?: string; /** * add tracing for the entire suite, the name of the test will be used as the zip name */ tracing?: boolean | Omit; /** * Take screenshots of failed tests, file name is the test title + hash, the file path is the output folder + the test's titlePath */ takeScreenshotsOfFailed?: boolean | Pick; /** * Keeps the page open and the feature running for the all the tests in the suite */ persist?: boolean; /** * Prebuild the engine before running the tests */ buildFlow?: 'prebuilt' | 'lazy'; /** * If true, the run will be allowed to use stale build artifacts */ allowStale?: boolean; /** * resets the browser context before each test */ resetContextBetweenTests?: boolean; } export interface Tracing { /** * path to a directory where the trace file will be saved * @defaultValue process.cwd() */ outPath?: string; /** * should trace include screenshots * @defaultValue true */ screenshots?: boolean; /** * should trace include snapshots * @defaultValue true */ snapshots?: boolean; /** * name of the trace file * @defaultValue random string */ name?: string; } export type WithFeatureApi = { /** * Opens a browser page with the feature loaded * @param options - options to override the suite options * @returns a promise that resolves to the page and the response */ getLoadedFeature: (options?: IFeatureExecutionOptions) => Promise<{ page: playwright.Page; response: playwright.Response | null; getMetrics: () => Promise<{ marks: PerformanceEntry[]; measures: PerformanceEntry[]; }>; }>; /** * @deprecated use `disposables` instead */ disposeAfter: (disposable: DisposableItem, options?: Omit) => void; /** * Add a disposable to be disposed after the test. * by default this will add the disposable to the `FINALE` group * if running in persist mode, the disposable will be disposed after the suite */ disposables: Disposables; /** * spawn a node environment */ spawnProcessingEnv: typeof getRunningFeature; /** * spawn a child process */ spawnSync: (command: string, args?: string[], spawnOptions?: SpawnSyncOptions) => ReturnType; /** * ensure a the path to the test temp directory exists and return it. */ ensureProjectPath: () => string; /** * Manually call taking a screenshot for the current test if it failed */ takeScreenshotIfFailed: (page: playwright.Page, options?: Pick) => Promise; }; export declare const TRACING_DISPOSABLES = "TRACING_DISPOSABLES"; export declare const PAGE_DISPOSABLES = "PAGE_DISPOSABLES"; export declare const WITH_FEATURE_DISPOSABLES = "WITH_FEATURE_DISPOSABLES"; export declare const ENGINE_DISPOSABLES = "ENGINE_DISPOSABLES"; export declare const FINALE = "FINALE"; export declare function withFeature(withFeatureOptions?: IWithFeatureOptions): WithFeatureApi; export declare function screenShotMessage(sanitizedFilePath: string): string; export declare function sanitizeFilePath(filePath: string): string; export declare const spawnSyncSafe: (...args: Parameters) => import("child_process").SpawnSyncReturns>; //# sourceMappingURL=with-feature.d.ts.map