UNPKG

5.2 kBTypeScriptView Raw
1// TODO(rictic): just import these directly rather than doing this
2
3declare module 'wct' {
4 import * as events from 'events';
5 import * as http from 'http';
6 import * as wd from 'wd';
7 import * as express from 'express';
8
9 type Handler = (o: {}, callback: (err: any) => void) => void;
10
11 export interface BrowserDef extends wd.Capabilities {
12 id: number;
13 url: wd.ValidHost;
14 sessionId: string;
15 deviceName?: string;
16 }
17
18 export interface Stats {
19 status: string;
20 passing?: number;
21 pending?: number;
22 failing?: number;
23 }
24
25 export interface Config {
26 suites: string[];
27 output: NodeJS.WritableStream;
28 ttyOutput: boolean;
29 verbose: boolean;
30 quiet?: boolean;
31 expanded: boolean;
32 root: string;
33 testTimeout: number;
34 persistent: boolean;
35 extraScripts: string[];
36 clientOptions: {
37 root: string;
38 verbose?: boolean;
39 };
40 activeBrowsers: BrowserDef[];
41 browserOptions: {
42 [name: string]: wd.Capabilities;
43 };
44 plugins: (string | boolean)[] | {
45 [key: string]: ({
46 disabled: boolean;
47 } | boolean);
48 };
49 registerHooks: (wct: Context) => void;
50 enforceJsonConf: boolean;
51 webserver: {
52 port: number;
53 hostname: string;
54 pathMappings: {
55 [urlPath: string]: string;
56 }[];
57 urlPrefix: string;
58 webRunnerPath?: string;
59 webRunnerContent?: string;
60 staticContent?: {
61 [file: string]: string;
62 };
63 };
64 skipPlugins?: boolean;
65 sauce?: {};
66 remote?: {};
67 origSuites?: string[];
68 skipCleanup?: boolean;
69 simpleOutput?: boolean;
70 skipUpdateCheck?: boolean;
71 }
72
73 /**
74 * Exposes the current state of a WCT run, and emits events/hooks for anyone
75 * downstream to listen to.
76 *
77 * @param {Object} options Any initially specified options.
78 */
79 export class Context extends events.EventEmitter {
80 options: Config;
81 private _hookHandlers;
82 constructor(options: Config);
83 /**
84 * Registers a handler for a particular hook. Hooks are typically configured to
85 * run _before_ a particular behavior.
86 */
87 hook(name: string, handler: Handler): void;
88 /**
89 * Registers a handler that will run after any handlers registered so far.
90 *
91 * @param {string} name
92 * @param {function(!Object, function(*))} handler
93 */
94 hookLate(name: string, handler: Handler): void;
95 /**
96 * Once all registered handlers have run for the hook, your callback will be
97 * triggered. If any of the handlers indicates an error state, any subsequent
98 * handlers will be canceled, and the error will be passed to the callback for
99 * the hook.
100 *
101 * Any additional arguments passed between `name` and `done` will be passed to
102 * hooks (before the callback).
103 *
104 * @param {string} name
105 * @param {function(*)} done
106 * @return {!Context}
107 */
108 emitHook(name: 'prepare:webserver', app: express.Application, done: (err?: any) => void): Context;
109 emitHook(name: 'configure', done: (err?: any) => void): Context;
110 emitHook(name: 'prepare', done: (err?: any) => void): Context;
111 emitHook(name: 'cleanup', done: (err?: any) => void): Context;
112 emitHook(name: string, done: (err?: any) => void): Context;
113 emitHook(name: string, ...args: any[]): Context;
114 /**
115 * @param {function(*, Array<!Plugin>)} done Asynchronously loads the plugins
116 * requested by `options.plugins`.
117 */
118 plugins(done: (err: any, plugins?: Plugin[]) => void): void;
119 private _plugins();
120 /**
121 * @return {!Array<string>} The names of enabled plugins.
122 */
123 enabledPlugins(): string[];
124 /**
125 * @param {string} name
126 * @return {!Object}
127 */
128 pluginOptions(name: string): any;
129 static Context: typeof Context;
130 }
131
132 export interface Metadata {
133 'cli-options': Config;
134}
135 export interface PluginInterface {
136 (context: Context, pluginOptions: any, pluginMeta: Plugin): void;
137 }
138 /**
139 * A WCT plugin. This constructor is private. Plugins can be retrieved via
140 * `Plugin.get`.
141 */
142 export class Plugin {
143 name: string;
144 cliConfig: Config;
145 packageName: string;
146 metadata: Metadata;
147 constructor(packageName: string, metadata: Metadata);
148 /**
149 * @param {!Context} context The context that this plugin should be evaluated
150 * within.
151 * @param {function(*)} done
152 */
153 execute(context: Context, done: (message?: string) => void): void;
154 /**
155 * Retrieves a plugin by shorthand or module name (loading it as necessary).
156 *
157 * @param {string} name
158 * @param {function(*, Plugin)} done
159 */
160 static get(name: string, done: (err: any, plugin?: Plugin) => void): void;
161 /**
162 * @param {string} name
163 * @return {string} The short form of `name`.
164 */
165 static shortName(name: string): string;
166 static Plugin: typeof Plugin;
167 }
168
169}