import * as chai from 'chai'; import { Handle, CancellablePromise } from '@theintern/common'; import Suite from '../Suite'; import Test from '../Test'; import ErrorFormatter, { ErrorFormatOptions } from '../common/ErrorFormatter'; import { BenchmarkConfig, Config, PluginDescriptor, ReporterDescriptor } from '../common/config'; import { ObjectInterface } from '../interfaces/object'; import { TddInterface } from '../interfaces/tdd'; import { BddInterface } from '../interfaces/bdd'; import { BenchmarkInterface } from '../interfaces/benchmark'; import { RuntimeEnvironment } from '../types'; export interface Executor { readonly config: Config; readonly suites: Suite[]; addSuite(factory: (parentSuite: Suite) => void): void; configure(options: { [key: string]: any; }): void; emit(eventName: T): CancellablePromise; emit(eventName: T, data: Events[T]): CancellablePromise; formatError(error: Error, options?: ErrorFormatOptions): string; log(...args: any[]): CancellablePromise; on(eventName: T, listener: Listener): Handle; on(listener: Listener<{ name: string; data?: any; }>): Handle; } export default abstract class BaseExecutor implements Executor { protected _config: C; protected _rootSuite: Suite; protected _events: InternEvent[]; protected _errorFormatter: ErrorFormatter | undefined; protected _hasSuiteErrors: boolean; protected _hasTestErrors: boolean; protected _hasEmittedErrors: boolean; protected _loader: Loader; protected _loaderOptions: any; protected _loaderInit: Promise | undefined; protected _loadingPlugins: { name: string; init: CancellablePromise; }[]; protected _loadingPluginOptions: any | undefined; protected _listeners: { [event: string]: Listener[]; }; protected _plugins: { [name: string]: any; }; protected _reporters: Reporter[]; protected _runTask: CancellablePromise | undefined; protected _reportersInitialized: boolean; constructor(options?: { [key in keyof C]?: any; }); abstract get environment(): RuntimeEnvironment; get config(): C; get suites(): Suite[]; formatError(error: Error, options?: ErrorFormatOptions): string; abstract loadScript(script: string | string[]): CancellablePromise; addSuite(factory: (parentSuite: Suite) => void): void; configure(options: { [key in keyof C]?: any; }): void; emit(eventName: T): CancellablePromise; emit(eventName: T, data: E[T]): CancellablePromise; getInterface(name: 'object'): ObjectInterface; getInterface(name: 'tdd'): TddInterface; getInterface(name: 'bdd'): BddInterface; getInterface(name: 'benchmark'): BenchmarkInterface; getPlugin(type: Y, name: string): P[Y]; getPlugin(name: 'chai'): typeof chai; getPlugin(name: 'interface.object'): ObjectInterface; getPlugin(name: 'interface.tdd'): TddInterface; getPlugin(name: 'interface.bdd'): BddInterface; getPlugin(name: 'interface.benchmark'): BenchmarkInterface; getPlugin(name: string): T; log(...args: any[]): CancellablePromise; on(eventName: T, listener: Listener): Handle; on(listener: Listener<{ name: string; data?: any; }>): Handle; registerInterface(name: string, iface: any): void; registerLoader(init: LoaderInit): void; registerPlugin(type: T, name: string, init: PluginInitializer): void; registerPlugin(name: string, init: PluginInitializer): void; registerReporter(name: string, init: ReporterInitializer): void; run(): CancellablePromise; protected _afterRun(): CancellablePromise; protected _assignPlugin(name: string, plugin: any): void; protected _beforeRun(): CancellablePromise; protected _initReporters(): CancellablePromise; protected _drainEventQueue(): CancellablePromise; protected _emitCoverage(source?: string): CancellablePromise | undefined; protected _loadLoader(): Promise; protected _loadPluginsWithLoader(): CancellablePromise; protected _loadPlugins(): CancellablePromise; protected _loadScripts(scripts: PluginDescriptor[], loader: (script: string) => Promise): CancellablePromise; protected _loadSuites(): CancellablePromise; protected _processOption(key: keyof C, value: any): void; protected _resolveConfig(): CancellablePromise; protected _runTests(): CancellablePromise; } export { BenchmarkConfig, Config, PluginDescriptor, ReporterDescriptor }; export interface InternEvent { eventName: keyof E; data?: any; } export { Handle }; export interface Listener { (arg: T): void | Promise; } export interface CoverageMessage { sessionId?: string; source?: string; coverage: any; } export interface DeprecationMessage { original: string; replacement?: string; message?: string; } export interface ExecutorEvent { name: keyof Events; data: any; } export interface Events { '*': ExecutorEvent; afterRun: void; beforeRun: void; coverage: CoverageMessage; deprecated: DeprecationMessage; error: Error; log: string; runEnd: void; runStart: void; suiteAdd: Suite; suiteEnd: Suite; suiteStart: Suite; testAdd: Test; testEnd: Test; testStart: Test; warning: string; } export declare type NoDataEvents = 'runStart' | 'runEnd' | 'beforeRun' | 'afterRun'; export interface Plugins { reporter: ReporterInitializer; } export interface Loader { (modules: string[]): Promise; } export interface LoaderInit { (options: { [key: string]: any; }): Promise | Loader; } export interface PluginInitializer { (options?: { [key: string]: any; }): CancellablePromise | T; } export interface ReporterInitializer { (options?: any): Reporter; } export interface Reporter { }