UNPKG

@devicecloud.dev/dcd

Version:

Better cloud maestro testing

97 lines (96 loc) 3.4 kB
import { paths } from '../types/generated/schema.types'; type TestResult = paths['/results/{uploadId}']['get']['responses']['200']['content']['application/json']['results'][number]; /** * Custom error for run failures that includes the polling result */ export declare class RunFailedError extends Error { result: PollingResult; constructor(result: PollingResult); } export interface PollingOptions { apiKey: string; apiUrl: string; consoleUrl: string; debug?: boolean; json?: boolean; logger?: (message: string) => void; quiet?: boolean; uploadId: string; } /** Metadata for a test flow extracted from YAML config */ export interface TestMetadata { /** Flow name from YAML config 'name' field or filename without extension */ flowName: string; /** Tags from YAML config 'tags' field */ tags: string[]; } export interface PollingResult { consoleUrl: string; status: 'FAILED' | 'PASSED'; tests: Array<{ durationSeconds: null | number; failReason?: string; /** File path of the test (same as name, for clarity) */ fileName: string; /** Flow name from YAML config or filename without extension */ flowName: string; /** Test file name (unchanged for backwards compatibility) */ name: string; status: string; /** Tags from YAML config (empty array if none) */ tags: string[]; }>; uploadId: string; } /** * Service for polling test results from the API */ export declare class ResultsPollingService { private readonly MAX_SEQUENTIAL_FAILURES; private readonly POLL_INTERVAL_MS; /** * Poll for test results until all tests complete * @param results Initial test results from submission * @param options Polling configuration * @param testMetadata Optional metadata map for each test (flowName, tags) * @returns Promise that resolves with final test results or rejects if tests fail */ pollUntilComplete(results: TestResult[], options: PollingOptions, testMetadata?: Record<string, TestMetadata>): Promise<PollingResult>; private buildPollingResult; private calculateStatusSummary; private displayFinalResults; /** * Fetch results from API and log debug information * @param apiUrl API base URL * @param apiKey API authentication key * @param uploadId Upload ID to fetch results for * @param debug Whether debug logging is enabled * @param logger Optional logger function * @returns Promise resolving to test results */ private fetchAndLogResults; private filterLatestResults; /** * Handle completed tests and return final result * @param updatedResults Test results from API * @param options Completion handling options * @returns Promise resolving to final polling result */ private handleCompletedTests; private handlePollingError; /** * Initialize the polling display UI * @param json Whether to output in JSON format * @param logger Optional logger function for output * @returns void */ private initializePollingDisplay; /** * Sleep for the specified number of milliseconds * @param ms Number of milliseconds to sleep * @returns Promise that resolves after the delay */ private sleep; private updateDisplayStatus; } export {};