UNPKG

cumulocity-cypress

Version:
89 lines (88 loc) 3.36 kB
import { C8yPact, C8yPactSaveKeys } from "../c8ypact"; export interface C8yPactAdapterOptions { /** Enable loading of JavaScript pact files (.js, .cjs). Defaults to false. */ enableJavaScript?: boolean; } /** * Using C8yPactFileAdapter you can implement your own adapter to load and save pacts using any format you want. * This allows loading pact objects from different sources, such as HAR files, pact.io, etc. * * The default adapter is C8yPactDefaultFileAdapter which loads and saves pact objects from/to * json files using C8yPact objects. Default location is cypress/fixtures/c8ypact folder. */ export interface C8yPactFileAdapter { /** * Loads all pact objects. The key must be the pact id used in C8yPact.id. */ loadPacts: () => { [key: string]: C8yPact; }; /** * Loads a pact object by id from file. */ loadPact: (id: string) => C8yPact | null; /** * Saves a pact object. */ savePact: (pact: C8yPact) => void; /** * Deletes a pact object or file. */ deletePact: (id: string) => void; /** * Gets the folder where the pact files are stored. */ getFolder: () => string; /** * Checks if a pact exists for a given id. */ pactExists(id: string): boolean; /** * Provides some custom description of the adapter. * @example C8yPactFileAdapter */ description(): string; } /** * Default implementation of C8yPactFileAdapter which loads and saves C8yPact objects * Provide location of the files using folder option. Default location is * cypress/fixtures/c8ypact folder. * * This adapter supports loading of JSON and YAML pact files (.json, .yaml, .yml). When * saviing pact files, it saves them as JSON files (.json). * * By using C8yPactAdapterOptions you can enable loading of JavaScript pact files (.js, .cjs). * Use with caution, as this can lead to security issues if the files are not trusted. */ export declare class C8yPactDefaultFileAdapter implements C8yPactFileAdapter { folder: string; private enabledExtensions; /** * Creates an instance of C8yPactDefaultFileAdapter. * * @param folder - The folder where pact files are stored. Can be an absolute or relative path. * @param options - Optional configuration for the adapter. * @param options.enableJavaScript - If true, enables loading of JavaScript pact files (.js, .cjs). Defaults to false. */ constructor(folder: string, options?: C8yPactAdapterOptions); description(): string; getFolder(): string; loadPacts(): { [key: string]: C8yPact; }; loadPact(id: string): C8yPact | null; pactExists(id: string): boolean; savePact(pact: C8yPact | Pick<C8yPact, C8yPactSaveKeys>): void; deletePact(id: string): void; readPactFiles(): string[]; /** * @deprecated Use readPactFiles() instead. */ readJsonFiles(): string[]; protected deleteJsonFiles(): void; protected loadPactObjects(): (C8yPact | null)[]; protected loadPactFromFile(filePath: string): C8yPact | null; protected createFolderRecursive(f: string): string | undefined; protected toAbsolutePath(f: string): string; protected isNodeError<T extends new (...args: any) => Error>(error: any, type: T): error is InstanceType<T> & NodeJS.ErrnoException; }