Skip to content

Commit

Permalink
simplify types
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiosantoscode committed Nov 2, 2018
1 parent 96e6180 commit 48e4ac9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
6 changes: 0 additions & 6 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,3 @@ export interface ICLICompilers {
compilers: string[];
extensions: string[];
}

export type Task = () => Promise<any>;
export interface ITaskOutput<T> {
task: Task;
output?: T;
}
19 changes: 5 additions & 14 deletions src/main/mocha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
ISubprocessRunnerMessage,
ISubprocessSyncedData,
ISuite,
ITaskOutput,
} from '../interfaces';

const debugLog = debug('mocha-parallel-tests');
Expand Down Expand Up @@ -84,9 +83,9 @@ export default class MochaWrapper extends Mocha {
runner.fullStackTrace = fullStackTrace;
runner.asyncOnly = asyncOnly;

const tasks: Array<() => Promise<ITaskOutput<ISubprocessResult>>> = [];
const tasks: Array<() => Promise<ISubprocessResult>> = [];
for (const file of this.files) {
const task = () => this.spawnTestProcess(file, task);
const task = () => this.spawnTestProcess(file);
tasks.push(task);
}

Expand Down Expand Up @@ -135,11 +134,7 @@ export default class MochaWrapper extends Mocha {

Promise.all(tasks.map(async (task) => {
const res = await task();
const output = res.output;
assert(output);
if (output) {
onTaskFinished(output);
}
onTaskFinished(res);
})).then(() => {
debugLog('All tests finished processing');

Expand Down Expand Up @@ -177,8 +172,8 @@ export default class MochaWrapper extends Mocha {
return retriesTests as IRetriedTest[];
}

private async spawnTestProcess(file: string, task: any): Promise<ITaskOutput<ISubprocessResult>> {
const output: ISubprocessResult = await new Promise<ISubprocessResult>(async (resolve, reject) => {
private async spawnTestProcess(file: string): Promise<ISubprocessResult> {
return new Promise<ISubprocessResult>(async (resolve, reject) => {
const resolvedFilePath = pathResolve(file);

const testOptions: {[key: string]: any} = { test: resolvedFilePath };
Expand Down Expand Up @@ -284,9 +279,5 @@ export default class MochaWrapper extends Mocha {
return null;
}
});
return {
output,
task,
};
}
}

0 comments on commit 48e4ac9

Please sign in to comment.