-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dependency injection): Add dependency injection for plugins (#1313)
This PR adds dependency injection to Stryker, in preparation of removing the side effects from the way we now load plugins. Instead of registering yourself to the correct factory (for example, by calling `ReporterFactory.instance().register`), it relies on plugins exporting a property called `strykerPlugins`. Just to be clear: this PR does fix not the issue reported in #667. It only adds the dependency injection mechanism to Stryker. We still need to do PR's for each package (can go relatively fast) The content of this PR: 1. Add a dependency injection framework called `typed-inject` to the packages folder; A type safe dependency injection framework 1. Add a package `stryker-api/di` which contains dependency injection related interfaces to help plugins know what to (type-safely) inject 1. Add `typed-inject` as a dependency to the core Stryker package and use it. Reporter plugins are loaded via this new mechanism. 1. Alter the `PluginLoader` in order to enable dependency injection in all plugins. It is still backward compatible with the old way of loading plugins. 1. Add a package to contain generic test helpers called `@stryker-mutator/test-helpers`. This package contains a `testInjector` to help inject common stuff into injectables for testability purposes. 1. It updated the `BroadcastReporter` and all build-in reporters to now use the new dependency injection mechanism.
- Loading branch information
Showing
160 changed files
with
2,562 additions
and
703 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
"tslib": "~1.9.3" | ||
}, | ||
"devDependencies": { | ||
"surrial": "~0.1.1" | ||
"surrial": "~0.1.1", | ||
"typed-inject": "0.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './src/plugin/Contexts'; | ||
export * from './src/plugin/Plugins'; | ||
export * from './src/plugin/PluginKind'; | ||
export * from './src/plugin/tokens'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { LoggerFactoryMethod, Logger } from '../../logging'; | ||
import { StrykerOptions } from '../../core'; | ||
import { PluginResolver } from './Plugins'; | ||
import { Config } from '../../config'; | ||
import { PluginKind } from './PluginKind'; | ||
import { commonTokens } from './tokens'; | ||
|
||
/** | ||
* The basic dependency injection context within Stryker | ||
*/ | ||
export interface BaseContext { | ||
[commonTokens.getLogger]: LoggerFactoryMethod; | ||
[commonTokens.logger]: Logger; | ||
[commonTokens.pluginResolver]: PluginResolver; | ||
} | ||
|
||
/** | ||
* The dependency injection context for most of Stryker's plugins. | ||
* Can inject basic stuff as well as the Stryker options | ||
*/ | ||
export interface OptionsContext extends BaseContext { | ||
[commonTokens.options]: StrykerOptions; | ||
/** | ||
* @deprecated This is just here to migrate between old and new plugins. Don't use this! Use `options` instead | ||
*/ | ||
[commonTokens.config]: Config; | ||
} | ||
|
||
/** | ||
* The dependency injection context for a `TranspilerPlugin` | ||
*/ | ||
export interface TranspilerPluginContext extends OptionsContext { | ||
[commonTokens.produceSourceMaps]: boolean; | ||
} | ||
|
||
/** | ||
* The dependency injection context for a `TestRunnerPlugin` | ||
*/ | ||
export interface TestRunnerPluginContext extends OptionsContext { | ||
[commonTokens.sandboxFileNames]: ReadonlyArray<string>; | ||
} | ||
|
||
/** | ||
* Lookup type for plugin contexts by kind. | ||
*/ | ||
export interface PluginContexts { | ||
[PluginKind.ConfigEditor]: BaseContext; | ||
[PluginKind.Mutator]: OptionsContext; | ||
[PluginKind.Reporter]: OptionsContext; | ||
[PluginKind.TestFramework]: OptionsContext; | ||
[PluginKind.TestRunner]: TestRunnerPluginContext; | ||
[PluginKind.Transpiler]: TranspilerPluginContext; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* The plugin kinds supported by Stryker | ||
*/ | ||
export enum PluginKind { | ||
ConfigEditor = 'ConfigEditor', | ||
TestRunner = 'TestRunner', | ||
TestFramework = 'TestFramework', | ||
Transpiler = 'Transpiler', | ||
Mutator = 'Mutator', | ||
Reporter = 'Reporter' | ||
} |
Oops, something went wrong.