cumulocity-cypress
Version:
Cypress commands for Cumulocity IoT
98 lines (97 loc) • 3.78 kB
TypeScript
import debug from "debug";
import { C8yPactObject, C8yPactSaveKeys } from "../c8ypact";
export interface C8yPactAdapterOptions {
/** Enable loading of JavaScript pact files (.js, .cjs). Defaults to false. */
enableJavaScript?: boolean;
/** Optional id to use for example for logging purposes. */
id?: string;
}
/**
* 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.
*
* Alternative adapters:
* - C8yPactHARFileAdapter: Reads/writes HAR (HTTP Archive) format for use with external tools
*/
export interface C8yPactFileAdapter {
/**
* Loads all pact objects. The key must be the pact id used in C8yPact.id.
*/
loadPacts: () => {
[key: string]: C8yPactObject;
};
/**
* Loads a pact object by id from file.
*/
loadPact: (id: string) => C8yPactObject | null;
/**
* Saves a pact object.
*/
savePact: (pact: C8yPactObject) => 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;
protected enabledExtensions: string[];
protected fileExtension: string;
protected readonly id: string;
protected readonly log: debug.Debugger;
/**
* 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]: C8yPactObject;
};
loadPact(id: string): C8yPactObject | null;
pactExists(id: string): boolean;
savePact(pact: C8yPactObject | Pick<C8yPactObject, C8yPactSaveKeys>): void;
deletePact(id: string): void;
readPactFiles(): string[];
/**
* @deprecated Use readPactFiles() instead.
*/
readJsonFiles(): string[];
protected deleteJsonFiles(): void;
protected loadPactObjects(): (C8yPactObject | null)[];
protected loadPactFromFile(filePath: string): C8yPactObject | 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;
}