/
checker-facade.ts
57 lines (47 loc) · 1.66 KB
/
checker-facade.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { Checker, CheckResult, CheckStatus } from '@stryker-mutator/api/check';
import { Mutant, StrykerOptions } from '@stryker-mutator/api/core';
import { tokens, Disposable } from 'typed-inject';
import { commonTokens } from '@stryker-mutator/api/plugin';
import ChildProcessProxy from '../child-proxy/child-process-proxy';
import { LoggingClientContext } from '../logging';
import { coreTokens } from '../di';
import { Worker } from '../concurrent/pool';
import { CheckerWorker } from './checker-worker';
createCheckerFactory.inject = tokens(commonTokens.options, coreTokens.loggingContext);
export function createCheckerFactory(options: StrykerOptions, loggingContext: LoggingClientContext): () => Checker {
return () => new CheckerFacade(options, loggingContext);
}
export class CheckerFacade implements Checker, Disposable, Worker {
private readonly childProcess?: ChildProcessProxy<CheckerWorker>;
constructor(options: StrykerOptions, loggingContext: LoggingClientContext) {
if (options.checkers.length) {
this.childProcess = ChildProcessProxy.create(
require.resolve('./checker-worker'),
loggingContext,
options,
{},
process.cwd(),
CheckerWorker,
[]
);
}
}
public async dispose() {
if (this.childProcess) {
await this.childProcess.dispose();
}
}
public async init(): Promise<void> {
if (this.childProcess) {
return this.childProcess.proxy.init();
}
}
public async check(mutant: Mutant): Promise<CheckResult> {
if (this.childProcess) {
return this.childProcess.proxy.check(mutant);
}
return {
status: CheckStatus.Passed,
};
}
}