1 | // Type definitions for karma v0.13.9
|
2 | // Project: https://github.com/karma-runner/karma
|
3 | // Definitions by: Tanguy Krotoff <https://github.com/tkrotoff>
|
4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
5 | // TypeScript Version: 2.3
|
6 |
|
7 | /// <reference types="node" />
|
8 |
|
9 | // See Karma public API https://karma-runner.github.io/0.13/dev/public-api.html
|
10 | import Promise = require('bluebird');
|
11 | import https = require('https');
|
12 | import log4js = require('log4js');
|
13 |
|
14 | declare namespace karma {
|
15 | interface Karma {
|
16 | /**
|
17 | * `start` method is deprecated since 0.13. It will be removed in 0.14.
|
18 | * Please use
|
19 | * <code>
|
20 | * server = new Server(config, [done])
|
21 | * server.start()
|
22 | * </code>
|
23 | * instead.
|
24 | */
|
25 | server: DeprecatedServer;
|
26 | Server: Server;
|
27 | runner: Runner;
|
28 | stopper: Stopper;
|
29 | launcher: Launcher;
|
30 | VERSION: string;
|
31 | constants: Constants;
|
32 | }
|
33 |
|
34 | interface Constants {
|
35 | VERSION: string;
|
36 | DEFAULT_PORT: number;
|
37 | DEFAULT_HOSTNAME: string;
|
38 | DEFAULT_LISTEN_ADDR: string;
|
39 | LOG_DISABLE: string;
|
40 | LOG_ERROR: string;
|
41 | LOG_WARN: string;
|
42 | LOG_INFO: string;
|
43 | LOG_DEBUG: string;
|
44 | LOG_LOG: string;
|
45 | LOG_PRIORITIES: string[];
|
46 | COLOR_PATTERN: string;
|
47 | NO_COLOR_PATTERN: string;
|
48 | CONSOLE_APPENDER: {
|
49 | type: string;
|
50 | layout: {
|
51 | type: string;
|
52 | pattern: string;
|
53 | };
|
54 | };
|
55 | EXIT_CODE: string;
|
56 | }
|
57 |
|
58 | interface LauncherStatic {
|
59 | generateId(): string;
|
60 | //TODO: injector should be of type `di.Injector`
|
61 | new (emitter: NodeJS.EventEmitter, injector: any): Launcher;
|
62 | }
|
63 |
|
64 | interface Launcher {
|
65 | Launcher: LauncherStatic;
|
66 | //TODO: Can this return value ever be typified?
|
67 | launch(names: string[], protocol: string, hostname: string, port: number, urlRoot: string): any[];
|
68 | kill(id: string, callback: Function): boolean;
|
69 | restart(id: string): boolean;
|
70 | killAll(callback: Function): void;
|
71 | areAllCaptured(): boolean;
|
72 | markCaptured(id: string): void;
|
73 | }
|
74 |
|
75 | interface DeprecatedServer {
|
76 | start(options?: any, callback?: ServerCallback): void;
|
77 | }
|
78 |
|
79 | interface Runner {
|
80 | run(options?: ConfigOptions | ConfigFile, callback?: ServerCallback): void;
|
81 | }
|
82 |
|
83 |
|
84 | interface Stopper {
|
85 | /**
|
86 | * This function will signal a running server to stop. The equivalent of karma stop.
|
87 | */
|
88 | stop(options?: ConfigOptions, callback?: ServerCallback): void;
|
89 | }
|
90 |
|
91 |
|
92 | interface TestResults {
|
93 | disconnected: boolean;
|
94 | error: boolean;
|
95 | exitCode: number;
|
96 | failed: number;
|
97 | success: number;
|
98 | }
|
99 |
|
100 | interface Server extends NodeJS.EventEmitter {
|
101 | new (options?: ConfigOptions | ConfigFile, callback?: ServerCallback): Server;
|
102 | /**
|
103 | * Start the server
|
104 | */
|
105 | start(): void;
|
106 | /**
|
107 | * Get properties from the injector
|
108 | * @param token
|
109 | */
|
110 | get(token: string): any;
|
111 | /**
|
112 | * Force a refresh of the file list
|
113 | */
|
114 | refreshFiles(): Promise<any>;
|
115 |
|
116 | on(event: string, listener: Function): this;
|
117 |
|
118 | /**
|
119 | * Listen to the 'run_complete' event.
|
120 | */
|
121 | on(event: 'run_complete', listener: (browsers: any, results: TestResults) => void): this;
|
122 |
|
123 | ///**
|
124 | // * Backward-compatibility with karma-intellij bundled with WebStorm.
|
125 | // * Deprecated since version 0.13, to be removed in 0.14
|
126 | // */
|
127 | //static start(): void;
|
128 | }
|
129 |
|
130 | interface ServerCallback {
|
131 | (exitCode: number): void;
|
132 | }
|
133 |
|
134 | interface Config {
|
135 | set: (config: ConfigOptions) => void;
|
136 | LOG_DISABLE: string;
|
137 | LOG_ERROR: string;
|
138 | LOG_WARN: string;
|
139 | LOG_INFO: string;
|
140 | LOG_DEBUG: string;
|
141 | }
|
142 |
|
143 | interface ConfigFile {
|
144 | configFile: string;
|
145 | }
|
146 |
|
147 | interface ConfigOptions {
|
148 | /**
|
149 | * @description Enable or disable watching files and executing the tests whenever one of these files changes.
|
150 | * @default true
|
151 | */
|
152 | autoWatch?: boolean;
|
153 | /**
|
154 | * @description When Karma is watching the files for changes, it tries to batch multiple changes into a single run
|
155 | * so that the test runner doesn't try to start and restart running tests more than it should.
|
156 | * The configuration setting tells Karma how long to wait (in milliseconds) after any changes have occurred
|
157 | * before starting the test process again.
|
158 | * @default 250
|
159 | */
|
160 | autoWatchBatchDelay?: number;
|
161 | /**
|
162 | * @default ''
|
163 | * @description The root path location that will be used to resolve all relative paths defined in <code>files</code> and <code>exclude</code>.
|
164 | * If the basePath configuration is a relative path then it will be resolved to
|
165 | * the <code>__dirname</code> of the configuration file.
|
166 | */
|
167 | basePath?: string;
|
168 | /**
|
169 | * @default 2000
|
170 | * @description How long does Karma wait for a browser to reconnect (in ms).
|
171 | * <p>
|
172 | * With a flaky connection it is pretty common that the browser disconnects,
|
173 | * but the actual test execution is still running without any problems. Karma does not treat a disconnection
|
174 | * as immediate failure and will wait <code>browserDisconnectTimeout</code> (ms).
|
175 | * If the browser reconnects during that time, everything is fine.
|
176 | * </p>
|
177 | */
|
178 | browserDisconnectTimeout?: number;
|
179 | /**
|
180 | * @default 0
|
181 | * @description The number of disconnections tolerated.
|
182 | * <p>
|
183 | * The <code>disconnectTolerance</code> value represents the maximum number of tries a browser will attempt
|
184 | * in the case of a disconnection. Usually any disconnection is considered a failure,
|
185 | * but this option allows you to define a tolerance level when there is a flaky network link between
|
186 | * the Karma server and the browsers.
|
187 | * </p>
|
188 | */
|
189 | browserDisconnectTolerance?: number;
|
190 | /**
|
191 | * @default 10000
|
192 | * @description How long will Karma wait for a message from a browser before disconnecting from it (in ms).
|
193 | * <p>
|
194 | * If, during test execution, Karma does not receive any message from a browser within
|
195 | * <code>browserNoActivityTimeout</code> (ms), it will disconnect from the browser
|
196 | * </p>
|
197 | */
|
198 | browserNoActivityTimeout?: number;
|
199 | /**
|
200 | * @default []
|
201 | * Possible Values:
|
202 | * <ul>
|
203 | * <li>Chrome (launcher comes installed with Karma)</li>
|
204 | * <li>ChromeCanary (launcher comes installed with Karma)</li>
|
205 | * <li>PhantomJS (launcher comes installed with Karma)</li>
|
206 | * <li>Firefox (launcher requires karma-firefox-launcher plugin)</li>
|
207 | * <li>Opera (launcher requires karma-opera-launcher plugin)</li>
|
208 | * <li>Internet Explorer (launcher requires karma-ie-launcher plugin)</li>
|
209 | * <li>Safari (launcher requires karma-safari-launcher plugin)</li>
|
210 | * </ul>
|
211 | * @description A list of browsers to launch and capture. When Karma starts up, it will also start up each browser
|
212 | * which is placed within this setting. Once Karma is shut down, it will shut down these browsers as well.
|
213 | * You can capture any browser manually by opening the browser and visiting the URL where
|
214 | * the Karma web server is listening (by default it is <code>http://localhost:9876/</code>).
|
215 | */
|
216 | browsers?: string[];
|
217 | /**
|
218 | * @default 60000
|
219 | * @description Timeout for capturing a browser (in ms).
|
220 | * <p>
|
221 | * The <code>captureTimeout</code> value represents the maximum boot-up time allowed for a
|
222 | * browser to start and connect to Karma. If any browser does not get captured within the timeout, Karma
|
223 | * will kill it and try to launch it again and, after three attempts to capture it, Karma will give up.
|
224 | * </p>
|
225 | */
|
226 | captureTimeout?: number;
|
227 | client?: ClientOptions;
|
228 | /**
|
229 | * @default true
|
230 | * @description Enable or disable colors in the output (reporters and logs).
|
231 | */
|
232 | colors?: boolean;
|
233 | /**
|
234 | * @default 'Infinity'
|
235 | * @description How many browsers Karma launches in parallel.
|
236 | * Especially on services like SauceLabs and Browserstack, it makes sense only to launch a limited
|
237 | * amount of browsers at once, and only start more when those have finished. Using this configuration,
|
238 | * you can specify how many browsers should be running at once at any given point in time.
|
239 | */
|
240 | concurrency?: number;
|
241 | /**
|
242 | * @default []
|
243 | * @description List of files/patterns to exclude from loaded files.
|
244 | */
|
245 | exclude?: string[];
|
246 | /**
|
247 | * @default []
|
248 | * @description List of files/patterns to load in the browser.
|
249 | */
|
250 | files?: (FilePattern | string)[];
|
251 | /**
|
252 | * @default []
|
253 | * @description List of test frameworks you want to use. Typically, you will set this to ['jasmine'], ['mocha'] or ['qunit']...
|
254 | * Please note just about all frameworks in Karma require an additional plugin/framework library to be installed (via NPM).
|
255 | */
|
256 | frameworks?: string[];
|
257 | /**
|
258 | * @default 'localhost'
|
259 | * @description Hostname to be used when capturing browsers.
|
260 | */
|
261 | hostname?: string;
|
262 | /**
|
263 | * @default {}
|
264 | * @description Options object to be used by Node's https class.
|
265 | * Object description can be found in the
|
266 | * [NodeJS.org API docs](https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener)
|
267 | */
|
268 | httpsServerOptions?: https.ServerOptions;
|
269 | /**
|
270 | * @default config.LOG_INFO
|
271 | * Possible values:
|
272 | * <ul>
|
273 | * <li>config.LOG_DISABLE</li>
|
274 | * <li>config.LOG_ERROR</li>
|
275 | * <li>config.LOG_WARN</li>
|
276 | * <li>config.LOG_INFO</li>
|
277 | * <li>config.LOG_DEBUG</li>
|
278 | * </ul>
|
279 | * @description Level of logging.
|
280 | */
|
281 | logLevel?: string;
|
282 | /**
|
283 | * @default [{type: 'console'}]
|
284 | * @description A list of log appenders to be used. See the documentation for [log4js] for more information.
|
285 | */
|
286 | loggers?: log4js.AppenderConfigBase[];
|
287 | /**
|
288 | * @default ['karma-*']
|
289 | * @description List of plugins to load. A plugin can be a string (in which case it will be required
|
290 | * by Karma) or an inlined plugin - Object.
|
291 | * By default, Karma loads all sibling NPM modules which have a name starting with karma-*.
|
292 | * Note: Just about all plugins in Karma require an additional library to be installed (via NPM).
|
293 | */
|
294 | plugins?: any[];
|
295 | /**
|
296 | * @default 9876
|
297 | * @description The port where the web server will be listening.
|
298 | */
|
299 | port?: number;
|
300 | /**
|
301 | * @default {'**\/*.coffee': 'coffee'}
|
302 | * @description A map of preprocessors to use.
|
303 | *
|
304 | * Preprocessors can be loaded through [plugins].
|
305 | *
|
306 | * Note: Just about all preprocessors in Karma (other than CoffeeScript and some other defaults)
|
307 | * require an additional library to be installed (via NPM).
|
308 | *
|
309 | * Be aware that preprocessors may be transforming the files and file types that are available at run time. For instance,
|
310 | * if you are using the "coverage" preprocessor on your source files, if you then attempt to interactively debug
|
311 | * your tests, you'll discover that your expected source code is completely changed from what you expected. Because
|
312 | * of that, you'll want to engineer this so that your automated builds use the coverage entry in the "reporters" list,
|
313 | * but your interactive debugging does not.
|
314 | *
|
315 | */
|
316 | preprocessors?: { [name: string]: string | string[] }
|
317 | /**
|
318 | * @default 'http:'
|
319 | * Possible Values:
|
320 | * <ul>
|
321 | * <li>http:</li>
|
322 | * <li>https:</li>
|
323 | * </ul>
|
324 | * @description Protocol used for running the Karma webserver.
|
325 | * Determines the use of the Node http or https class.
|
326 | * Note: Using <code>'https:'</code> requires you to specify <code>httpsServerOptions</code>.
|
327 | */
|
328 | protocol?: string;
|
329 | /**
|
330 | * @default {}
|
331 | * @description A map of path-proxy pairs.
|
332 | */
|
333 | proxies?: { [path: string]: string }
|
334 | /**
|
335 | * @default true
|
336 | * @description Whether or not Karma or any browsers should raise an error when an inavlid SSL certificate is found.
|
337 | */
|
338 | proxyValidateSSL?: boolean;
|
339 | /**
|
340 | * @default 0
|
341 | * @description Karma will report all the tests that are slower than given time limit (in ms).
|
342 | * This is disabled by default (since the default value is 0).
|
343 | */
|
344 | reportSlowerThan?: number;
|
345 | /**
|
346 | * @default ['progress']
|
347 | * Possible Values:
|
348 | * <ul>
|
349 | * <li>dots</li>
|
350 | * <li>progress</li>
|
351 | * </ul>
|
352 | * @description A list of reporters to use.
|
353 | * Additional reporters, such as growl, junit, teamcity or coverage can be loaded through plugins.
|
354 | * Note: Just about all additional reporters in Karma (other than progress) require an additional library to be installed (via NPM).
|
355 | */
|
356 | reporters?: string[];
|
357 | /**
|
358 | * @default false
|
359 | * @description Continuous Integration mode.
|
360 | * If true, Karma will start and capture all configured browsers, run tests and then exit with an exit code of 0 or 1 depending
|
361 | * on whether all tests passed or any tests failed.
|
362 | */
|
363 | singleRun?: boolean;
|
364 | /**
|
365 | * @default ['polling', 'websocket']
|
366 | * @description An array of allowed transport methods between the browser and testing server. This configuration setting
|
367 | * is handed off to [socket.io](http://socket.io/) (which manages the communication
|
368 | * between browsers and the testing server).
|
369 | */
|
370 | transports?: string[];
|
371 | /**
|
372 | * @default '/'
|
373 | * @description The base url, where Karma runs.
|
374 | * All of Karma's urls get prefixed with the urlRoot. This is helpful when using proxies, as
|
375 | * sometimes you might want to proxy a url that is already taken by Karma.
|
376 | */
|
377 | urlRoot?: string;
|
378 | }
|
379 |
|
380 | interface ClientOptions {
|
381 | /**
|
382 | * @default undefined
|
383 | * @description When karma run is passed additional arguments on the command-line, they
|
384 | * are passed through to the test adapter as karma.config.args (an array of strings).
|
385 | * The client.args option allows you to set this value for actions other than run.
|
386 | * How this value is used is up to your test adapter - you should check your adapter's
|
387 | * documentation to see how (and if) it uses this value.
|
388 | */
|
389 | args?: string[];
|
390 | /**
|
391 | * @default true
|
392 | * @description Run the tests inside an iFrame or a new window
|
393 | * If true, Karma runs the tests inside an iFrame. If false, Karma runs the tests in a new window. Some tests may not run in an
|
394 | * iFrame and may need a new window to run.
|
395 | */
|
396 | useIframe?: boolean;
|
397 | /**
|
398 | * @default true
|
399 | * @description Capture all console output and pipe it to the terminal.
|
400 | */
|
401 | captureConsole?: boolean;
|
402 | }
|
403 |
|
404 | interface FilePattern {
|
405 | /**
|
406 | * The pattern to use for matching. This property is mandatory.
|
407 | */
|
408 | pattern: string;
|
409 | /**
|
410 | * @default true
|
411 | * @description If <code>autoWatch</code> is true all files that have set watched to true will be watched
|
412 | * for changes.
|
413 | */
|
414 | watched?: boolean;
|
415 | /**
|
416 | * @default true
|
417 | * @description Should the files be included in the browser using <script> tag? Use false if you want to
|
418 | * load them manually, eg. using Require.js.
|
419 | */
|
420 | included?: boolean;
|
421 | /**
|
422 | * @default true
|
423 | * @description Should the files be served by Karma's webserver?
|
424 | */
|
425 | served?: boolean;
|
426 | /**
|
427 | * @default false
|
428 | * @description Should the files be served from disk on each request by Karma's webserver?
|
429 | */
|
430 | nocache?: boolean;
|
431 | }
|
432 | }
|
433 |
|
434 | declare var karma: karma.Karma;
|
435 |
|
436 | export = karma;
|