UNPKG

3.44 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const typed_inject_1 = require("typed-inject");
4const plugin_1 = require("@stryker-mutator/api/plugin");
5const logging_1 = require("./logging");
6const process_1 = require("./process");
7const di_1 = require("./di");
8const errors_1 = require("./errors");
9/**
10 * The main Stryker class.
11 * It provides a single `runMutationTest()` function which runs mutation testing:
12 */
13class Stryker {
14 /**
15 * @constructor
16 * @param cliOptions The cli options.
17 * @param injectorFactory The injector factory, for testing purposes only
18 */
19 constructor(cliOptions, injectorFactory = typed_inject_1.createInjector) {
20 this.cliOptions = cliOptions;
21 this.injectorFactory = injectorFactory;
22 }
23 async runMutationTest() {
24 const rootInjector = this.injectorFactory();
25 const loggerProvider = di_1.provideLogger(rootInjector);
26 try {
27 // 1. Prepare. Load Stryker configuration, load the input files and starts the logging server
28 const prepareExecutor = loggerProvider.provideValue(di_1.coreTokens.cliOptions, this.cliOptions).injectClass(process_1.PrepareExecutor);
29 const mutantInstrumenterInjector = await prepareExecutor.execute();
30 try {
31 // 2. Mutate and instrument the files and write to the sandbox.
32 const mutantInstrumenter = mutantInstrumenterInjector.injectClass(process_1.MutantInstrumenterExecutor);
33 const dryRunExecutorInjector = await mutantInstrumenter.execute();
34 // 3. Perform a 'dry run' (initial test run). Runs the tests without active mutants and collects coverage.
35 const dryRunExecutor = dryRunExecutorInjector.injectClass(process_1.DryRunExecutor);
36 const mutationRunExecutorInjector = await dryRunExecutor.execute();
37 // 4. Actual mutation testing. Will check every mutant and if valid run it in an available test runner.
38 const mutationRunExecutor = mutationRunExecutorInjector.injectClass(process_1.MutationTestExecutor);
39 const mutantResults = await mutationRunExecutor.execute();
40 return mutantResults;
41 }
42 catch (error) {
43 const log = loggerProvider.resolve(plugin_1.commonTokens.getLogger)(Stryker.name);
44 log.debug('Not removing the temp dir because an error occurred');
45 mutantInstrumenterInjector.resolve(di_1.coreTokens.temporaryDirectory).removeDuringDisposal = false;
46 throw error;
47 }
48 }
49 catch (error) {
50 const log = loggerProvider.resolve(plugin_1.commonTokens.getLogger)(Stryker.name);
51 const cause = errors_1.retrieveCause(error);
52 if (cause instanceof errors_1.ConfigError) {
53 log.error(cause.message);
54 }
55 else {
56 log.error(error);
57 if (!log.isTraceEnabled()) {
58 log.info('Trouble figuring out what went wrong? Try `npx stryker run --fileLogLevel trace --logLevel debug` to get some more info.');
59 }
60 }
61 throw cause;
62 }
63 finally {
64 await rootInjector.dispose();
65 await logging_1.LogConfigurator.shutdown();
66 }
67 }
68}
69exports.default = Stryker;
70//# sourceMappingURL=Stryker.js.map
\No newline at end of file