1 | import * as chai from 'chai';
|
2 | import { Handle, CancellablePromise } from '@theintern/common';
|
3 | import Suite from '../Suite';
|
4 | import Test from '../Test';
|
5 | import ErrorFormatter, { ErrorFormatOptions } from '../common/ErrorFormatter';
|
6 | import { BenchmarkConfig, Config, PluginDescriptor, ReporterDescriptor } from '../common/config';
|
7 | import { ObjectInterface } from '../interfaces/object';
|
8 | import { TddInterface } from '../interfaces/tdd';
|
9 | import { BddInterface } from '../interfaces/bdd';
|
10 | import { BenchmarkInterface } from '../interfaces/benchmark';
|
11 | import { RuntimeEnvironment } from '../types';
|
12 | export interface Executor {
|
13 | readonly config: Config;
|
14 | readonly suites: Suite[];
|
15 | addSuite(factory: (parentSuite: Suite) => void): void;
|
16 | configure(options: {
|
17 | [key: string]: any;
|
18 | }): void;
|
19 | emit<T extends NoDataEvents>(eventName: T): CancellablePromise<void>;
|
20 | emit<T extends keyof Events>(eventName: T, data: Events[T]): CancellablePromise<void>;
|
21 | formatError(error: Error, options?: ErrorFormatOptions): string;
|
22 | log(...args: any[]): CancellablePromise<void>;
|
23 | on<T extends keyof Events>(eventName: T, listener: Listener<Events[T]>): Handle;
|
24 | on(listener: Listener<{
|
25 | name: string;
|
26 | data?: any;
|
27 | }>): Handle;
|
28 | }
|
29 | export default abstract class BaseExecutor<E extends Events, C extends Config, P extends Plugins> implements Executor {
|
30 | protected _config: C;
|
31 | protected _rootSuite: Suite;
|
32 | protected _events: InternEvent<E>[];
|
33 | protected _errorFormatter: ErrorFormatter | undefined;
|
34 | protected _hasSuiteErrors: boolean;
|
35 | protected _hasTestErrors: boolean;
|
36 | protected _hasEmittedErrors: boolean;
|
37 | protected _loader: Loader;
|
38 | protected _loaderOptions: any;
|
39 | protected _loaderInit: Promise<Loader> | undefined;
|
40 | protected _loadingPlugins: {
|
41 | name: string;
|
42 | init: CancellablePromise<void>;
|
43 | }[];
|
44 | protected _loadingPluginOptions: any | undefined;
|
45 | protected _listeners: {
|
46 | [event: string]: Listener<any>[];
|
47 | };
|
48 | protected _plugins: {
|
49 | [name: string]: any;
|
50 | };
|
51 | protected _reporters: Reporter[];
|
52 | protected _runTask: CancellablePromise<void> | undefined;
|
53 | protected _reportersInitialized: boolean;
|
54 | constructor(options?: {
|
55 | [key in keyof C]?: any;
|
56 | });
|
57 | abstract get environment(): RuntimeEnvironment;
|
58 | get config(): C;
|
59 | get suites(): Suite[];
|
60 | formatError(error: Error, options?: ErrorFormatOptions): string;
|
61 | abstract loadScript(script: string | string[]): CancellablePromise<void>;
|
62 | addSuite(factory: (parentSuite: Suite) => void): void;
|
63 | configure(options: {
|
64 | [key in keyof C]?: any;
|
65 | }): void;
|
66 | emit<T extends NoDataEvents>(eventName: T): CancellablePromise<void>;
|
67 | emit<T extends keyof E>(eventName: T, data: E[T]): CancellablePromise<void>;
|
68 | getInterface(name: 'object'): ObjectInterface;
|
69 | getInterface(name: 'tdd'): TddInterface;
|
70 | getInterface(name: 'bdd'): BddInterface;
|
71 | getInterface(name: 'benchmark'): BenchmarkInterface;
|
72 | getPlugin<Y extends keyof P>(type: Y, name: string): P[Y];
|
73 | getPlugin(name: 'chai'): typeof chai;
|
74 | getPlugin(name: 'interface.object'): ObjectInterface;
|
75 | getPlugin(name: 'interface.tdd'): TddInterface;
|
76 | getPlugin(name: 'interface.bdd'): BddInterface;
|
77 | getPlugin(name: 'interface.benchmark'): BenchmarkInterface;
|
78 | getPlugin<T>(name: string): T;
|
79 | log(...args: any[]): CancellablePromise<void>;
|
80 | on<T extends keyof E>(eventName: T, listener: Listener<E[T]>): Handle;
|
81 | on(listener: Listener<{
|
82 | name: string;
|
83 | data?: any;
|
84 | }>): Handle;
|
85 | registerInterface(name: string, iface: any): void;
|
86 | registerLoader(init: LoaderInit): void;
|
87 | registerPlugin<T extends keyof P>(type: T, name: string, init: PluginInitializer<P[T]>): void;
|
88 | registerPlugin(name: string, init: PluginInitializer): void;
|
89 | registerReporter(name: string, init: ReporterInitializer): void;
|
90 | run(): CancellablePromise<void>;
|
91 | protected _afterRun(): CancellablePromise<void>;
|
92 | protected _assignPlugin(name: string, plugin: any): void;
|
93 | protected _beforeRun(): CancellablePromise<boolean>;
|
94 | protected _initReporters(): CancellablePromise<void>;
|
95 | protected _drainEventQueue(): CancellablePromise<void>;
|
96 | protected _emitCoverage(source?: string): CancellablePromise<void> | undefined;
|
97 | protected _loadLoader(): Promise<void>;
|
98 | protected _loadPluginsWithLoader(): CancellablePromise<void>;
|
99 | protected _loadPlugins(): CancellablePromise<void>;
|
100 | protected _loadScripts(scripts: PluginDescriptor[], loader: (script: string) => Promise<void>): CancellablePromise<void>;
|
101 | protected _loadSuites(): CancellablePromise<void>;
|
102 | protected _processOption(key: keyof C, value: any): void;
|
103 | protected _resolveConfig(): CancellablePromise<void>;
|
104 | protected _runTests(): CancellablePromise<void>;
|
105 | }
|
106 | export { BenchmarkConfig, Config, PluginDescriptor, ReporterDescriptor };
|
107 | export interface InternEvent<E extends Events> {
|
108 | eventName: keyof E;
|
109 | data?: any;
|
110 | }
|
111 | export { Handle };
|
112 | export interface Listener<T> {
|
113 | (arg: T): void | Promise<any>;
|
114 | }
|
115 | export interface CoverageMessage {
|
116 | sessionId?: string;
|
117 | source?: string;
|
118 | coverage: any;
|
119 | }
|
120 | export interface DeprecationMessage {
|
121 | original: string;
|
122 | replacement?: string;
|
123 | message?: string;
|
124 | }
|
125 | export interface ExecutorEvent {
|
126 | name: keyof Events;
|
127 | data: any;
|
128 | }
|
129 | export interface Events {
|
130 | '*': ExecutorEvent;
|
131 | afterRun: void;
|
132 | beforeRun: void;
|
133 | coverage: CoverageMessage;
|
134 | deprecated: DeprecationMessage;
|
135 | error: Error;
|
136 | log: string;
|
137 | runEnd: void;
|
138 | runStart: void;
|
139 | suiteAdd: Suite;
|
140 | suiteEnd: Suite;
|
141 | suiteStart: Suite;
|
142 | testAdd: Test;
|
143 | testEnd: Test;
|
144 | testStart: Test;
|
145 | warning: string;
|
146 | }
|
147 | export declare type NoDataEvents = 'runStart' | 'runEnd' | 'beforeRun' | 'afterRun';
|
148 | export interface Plugins {
|
149 | reporter: ReporterInitializer;
|
150 | }
|
151 | export interface Loader {
|
152 | (modules: string[]): Promise<void>;
|
153 | }
|
154 | export interface LoaderInit {
|
155 | (options: {
|
156 | [key: string]: any;
|
157 | }): Promise<Loader> | Loader;
|
158 | }
|
159 | export interface PluginInitializer<T extends any = any> {
|
160 | (options?: {
|
161 | [key: string]: any;
|
162 | }): CancellablePromise<T> | T;
|
163 | }
|
164 | export interface ReporterInitializer {
|
165 | (options?: any): Reporter;
|
166 | }
|
167 | export interface Reporter {
|
168 | }
|