diff --git a/types/karma-parallel/index.d.ts b/types/karma-parallel/index.d.ts new file mode 100644 index 0000000000..20dfe9937e --- /dev/null +++ b/types/karma-parallel/index.d.ts @@ -0,0 +1,59 @@ +// Type definitions for karma-parallel 0.3 +// Project: https://github.com/joeljeske/karma-parallel#readme +// Definitions by: Piotr Błażejewicz (Peter Blazejewicz) +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.2 + +import 'karma'; + +declare module 'karma' { + interface ConfigOptions { + /** + * Options for this plugin + * see {@link https://github.com/joeljeske/karma-parallel#options} + */ + parallelOptions?: ParallelOptions; + } + interface ParallelOptions { + /** + * regex or function used to determine if a reporter needs to only received aggregated events from the browser shards. + * It is used to ensure coverage reporting is accurate amongst all the shards of a browser + * It is also useful for some programmatic reporters such as junit reporters that need to operate on a single set of test outputs and not once for each shard. + * Set to null to disable aggregated reporting + */ + aggregatedReporterTest?: ((reporter: object) => boolean) | RegExp | null; + /** + * The number of browser instances to use to test. + * If you test on multiple types of browsers, this spin up the number of executors for each browser type + * @default cpu_cores-1 + */ + executors?: number; + /** + * This plugin works by overriding the test suite describe() function. + * When it encounters a describe, it must decide if it will skip the tests inside of it, or not + * @default 'round-robin' + */ + shardStrategy?: 'round-robin' | 'description-length' | 'custom'; + /** + * Custom function that will determine if a describe block should run in the current executor. + * It is a function that is serialized and re-constructed on each executor. + * The function will be called for every top level describe block and should return true if the describe block should run for a the current executor + */ + customShardStrategy?: (options: ShardStrategOptions) => boolean; + } + + interface ShardStrategOptions { + /** + * the total number of executors + */ + readonly executors: number; + /** + * the 0-based index of the current executor + */ + readonly shardIndex: number; + /** + * the string passed to the describe block (useful for gaining context of the current description) + */ + readonly description: string; + } +} diff --git a/types/karma-parallel/karma-parallel-tests.ts b/types/karma-parallel/karma-parallel-tests.ts new file mode 100644 index 0000000000..96b480b841 --- /dev/null +++ b/types/karma-parallel/karma-parallel-tests.ts @@ -0,0 +1,33 @@ +import karma = require('karma'); + +const configTest = (config: karma.Config) => { + config.set({ + // NOTE: 'parallel' must be the first framework in the list + frameworks: ['parallel', 'mocha' /* or 'jasmine' */], + files: ['test/**/*.js'], + plugins: [ + // add karma-parallel to the plugins if you encounter something like "karma parallel No provider for framework:parallel" + require('karma-parallel'), + ], + parallelOptions: { + executors: 4, // Defaults to cpu-count - 1 + shardStrategy: 'round-robin', + customShardStrategy: config => { + config.executors; // $ExpectType number + config.shardIndex; // $ExpectType number + config.description; // $ExpectType string + window.parallelDescribeCount = window.parallelDescribeCount || 0; + window.parallelDescribeCount++; + return window.parallelDescribeCount % config.executors === config.shardIndex; + }, + aggregatedReporterTest: /coverage|istanbul|junit/i, + }, + }); +}; + +// required by window prop definition +declare global { + interface Window { + parallelDescribeCount?: number; + } +} diff --git a/types/karma-parallel/tsconfig.json b/types/karma-parallel/tsconfig.json new file mode 100644 index 0000000000..467326df97 --- /dev/null +++ b/types/karma-parallel/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "DOM" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "karma-parallel-tests.ts" + ] +} diff --git a/types/karma-parallel/tslint.json b/types/karma-parallel/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/karma-parallel/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }