diff --git a/karma/karma-tests.ts b/karma/karma-tests.ts index 7dbd533b59..31a3948275 100644 --- a/karma/karma-tests.ts +++ b/karma/karma-tests.ts @@ -43,6 +43,14 @@ server.on('browser_register', function (browser: any) { console.log('A new browser was registered'); }); +server.on('run_complete', (browsers, results) => { + results.disconnected = false; + results.error = false; + results.exitCode = 0; + results.failed = 9; + results.success = 10; +}); + //var runner = require('karma').runner; => cannot use this syntax otherwise runner is of type any karma.runner.run({port: 9876}, function(exitCode: number) { console.log('Karma has exited with ' + exitCode); diff --git a/karma/karma.d.ts b/karma/karma.d.ts index 455d1df911..e0fcfba7b9 100644 --- a/karma/karma.d.ts +++ b/karma/karma.d.ts @@ -34,7 +34,7 @@ declare module 'karma' { interface LauncherStatic { generateId(): string; //TODO: injector should be of type `di.Injector` - new(emitter: NodeJS.EventEmitter, injector: any): Launcher; + new (emitter: NodeJS.EventEmitter, injector: any): Launcher; } interface Launcher { @@ -53,11 +53,19 @@ declare module 'karma' { } interface Runner { - run(options?: ConfigOptions|ConfigFile, callback?: ServerCallback): void; + run(options?: ConfigOptions | ConfigFile, callback?: ServerCallback): void; + } + + interface TestResults { + disconnected: boolean; + error: boolean; + exitCode: number; + failed: number; + success: number; } interface Server extends NodeJS.EventEmitter { - new(options?: ConfigOptions|ConfigFile, callback?: ServerCallback): Server; + new (options?: ConfigOptions | ConfigFile, callback?: ServerCallback): Server; /** * Start the server */ @@ -72,6 +80,13 @@ declare module 'karma' { */ refreshFiles(): Promise; + on(event: string, listener: Function): this; + + /** + * Listen to the 'run_complete' event. + */ + on(event: 'run_complete', listener: (browsers: any, results: TestResults ) => void): this; + ///** // * Backward-compatibility with karma-intellij bundled with WebStorm. // * Deprecated since version 0.13, to be removed in 0.14 @@ -191,7 +206,7 @@ declare module 'karma' { * @default [] * @description List of files/patterns to load in the browser. */ - files?: (FilePattern|string)[]; + files?: (FilePattern | string)[]; /** * @default [] * @description List of test frameworks you want to use. Typically, you will set this to ['jasmine'], ['mocha'] or ['qunit']... @@ -257,7 +272,7 @@ declare module 'karma' { * but your interactive debugging does not. * */ - preprocessors?: { [name: string]: string|string[] } + preprocessors?: { [name: string]: string | string[] } /** * @default 'http:' * Possible Values: