Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dependency injection): Add dependency injection for plugins #1313

Merged
merged 40 commits into from
Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
eb51b11
Add dependency injection idea
nicojs Dec 26, 2018
b5d16e8
Merge branch 'master' into 667-remove-side-effects
nicojs Dec 28, 2018
f000155
Merge branch 'master' into 667-remove-side-effects
nicojs Dec 29, 2018
9a532c7
Started with implementation of new pugin mechanism.
nicojs Dec 30, 2018
4137cde
Finish up the broadcast reporter migration
nicojs Dec 30, 2018
7842052
Let the logger be injected in the HtmlReporter
nicojs Dec 30, 2018
c265402
test(TestInjector): Implement and use TestInjector
nicojs Dec 31, 2018
f4cd5d8
Add the ability to inject values into a tree of dependencies.
nicojs Jan 1, 2019
50a01a6
Improve HTML reporter typings
nicojs Jan 2, 2019
9647484
Rename CorrespondingTypes
nicojs Jan 2, 2019
3bc1785
Refactor all the things.
nicojs Jan 7, 2019
22c1902
Test: Add unit tests for `StrykerError` and `errorToString`
nicojs Jan 7, 2019
48acafa
Test: Update tests for stryker-api
nicojs Jan 7, 2019
014a167
Add npmignore and npmrc to typed-inject
nicojs Jan 7, 2019
e5d230b
Rename - plugins -> Plugins part 1
nicojs Jan 7, 2019
4fac5ee
Rename - plugins -> Plugins part 2
nicojs Jan 7, 2019
a609213
Update plugin loader to load from correct node_modules directory
nicojs Jan 7, 2019
8f66a39
Add typed-inject to local install of e2e tests
nicojs Jan 7, 2019
46711ed
Add missing dependency to `polymer-project` e2e test
nicojs Jan 7, 2019
a781d7c
Add missing dependency to `jest-react` e2e test
nicojs Jan 7, 2019
b22365d
Remove stryker-api dependency from stryker-util
nicojs Jan 7, 2019
90f0fcb
docs(typed-inject): Add README
nicojs Jan 8, 2019
8be8358
docs(typed-inject): Add "magic tokens" section to readme
nicojs Jan 8, 2019
dfeb4b0
docs(typed-html): add gh markdown table
nicojs Jan 8, 2019
dabc80a
test(typed-inject): Add integration tests
nicojs Jan 8, 2019
f9dfc62
test(typed-inject): Add more unit and integration tests
nicojs Jan 8, 2019
bb1ff55
refactor(stryker-api): Rename stryker-api/di to stryker-api/plugin an…
nicojs Jan 9, 2019
ef8fb92
Merge branch 'master' into 667-remove-side-effects
nicojs Jan 9, 2019
a159897
refactor(html-reporter): Revert back html reporter in order to presen…
nicojs Jan 9, 2019
ce338cc
fix(plugin-loader): Fix dynamicly loading of deprecated plugins
nicojs Jan 9, 2019
266c1b6
feat(plugins): Make sure you can also create a plugin with a factory …
nicojs Jan 10, 2019
37a2e68
refactor(plugins): Move all stryker plugin stuff back to stryker-api
nicojs Jan 11, 2019
2dc8ed6
docs(api): Document the plugin api
nicojs Jan 11, 2019
416fadf
refactor: Change naming of plugin contexts and methods for declaring …
nicojs Jan 11, 2019
74608ae
feat(di): Create a `PluginCreator` that can be reused for all plugin …
nicojs Jan 17, 2019
6da9395
Fix typo in typed-inject readme (#1321)
hugo-vrijswijk Jan 17, 2019
3f62298
docs(review-comments): Implement review comments
nicojs Jan 22, 2019
52a976c
docs(typed-inject): Fix typo in readme
nicojs Jan 22, 2019
a7abc07
docs(readme): fix typo's
nicojs Jan 22, 2019
bd05310
Merge branch 'master' into 667-remove-side-effects
nicojs Jan 23, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"@stryker-mutator/util": "../packages/stryker-util",
"stryker-typescript": "../packages/stryker-typescript",
"stryker-vue-mutator": "../packages/stryker-vue-mutator",
"stryker-webpack-transpiler": "../packages/stryker-webpack-transpiler"
"stryker-webpack-transpiler": "../packages/stryker-webpack-transpiler",
"typed-inject": "../packages/typed-inject"
}
}
28 changes: 21 additions & 7 deletions e2e/test/angular-project/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion e2e/test/angular-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"stryker": "../../../packages/stryker",
"stryker-karma-runner": "../../../packages/stryker-karma-runner",
"stryker-typescript": "../../../packages/stryker-typescript",
"@stryker-mutator/util": "../../../packages/stryker-util"
"@stryker-mutator/util": "../../../packages/stryker-util",
"typed-inject": "../../../packages/typed-inject"
}
}
3 changes: 2 additions & 1 deletion e2e/test/jest-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"stryker": "../../../packages/stryker",
"stryker-javascript-mutator": "../../../packages/stryker-javascript-mutator",
"stryker-jest-runner": "../../../packages/stryker-jest-runner",
"@stryker-mutator/util": "../../../packages/stryker-util"
"@stryker-mutator/util": "../../../packages/stryker-util",
"typed-inject": "../../../packages/typed-inject"
}
}
3 changes: 2 additions & 1 deletion e2e/test/polymer-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"stryker": "../../../packages/stryker",
"stryker-wct-runner": "../../../packages/stryker-wct-runner",
"stryker-javascript-mutator": "../../../packages/stryker-javascript-mutator",
"@stryker-mutator/util": "../../../packages/stryker-util"
"@stryker-mutator/util": "../../../packages/stryker-util",
"typed-inject": "../../../packages/typed-inject"
},
"scripts": {
"prepare": "install-local",
Expand Down
3 changes: 2 additions & 1 deletion e2e/test/vue-javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@
"stryker-javascript-mutator": "../../../packages/stryker-javascript-mutator",
"stryker-karma-runner": "../../../packages/stryker-karma-runner",
"stryker-vue-mutator": "../../../packages/stryker-vue-mutator",
"@stryker-mutator/util": "../../../packages/stryker-util"
"@stryker-mutator/util": "../../../packages/stryker-util",
"typed-inject": "../../../packages/typed-inject"
},
"engines": {
"node": ">= 6.0.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/stryker-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"tslib": "~1.9.3"
},
"devDependencies": {
"surrial": "~0.1.1"
"surrial": "~0.1.1",
"typed-inject": "0.0.0"
}
}
4 changes: 4 additions & 0 deletions packages/stryker-api/plugin.ts
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';
2 changes: 1 addition & 1 deletion packages/stryker-api/src/config/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class Config implements StrykerOptions {
};
public allowConsoleColors: boolean = true;

public set(newConfig: StrykerOptions) {
public set(newConfig: Partial<StrykerOptions>) {
if (newConfig) {
Object.keys(newConfig).forEach(key => {
if (typeof newConfig[key] !== 'undefined') {
Expand Down
32 changes: 16 additions & 16 deletions packages/stryker-api/src/core/StrykerOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface StrykerOptions {
/**
* A list of globbing expression used for selecting the files that should be mutated.
*/
mutate?: string[];
mutate: string[];

/**
* With `files` you can choose which files should be included in your test runner sandbox.
Expand All @@ -32,7 +32,7 @@ interface StrykerOptions {
* all the CPU cores of your machine. Default: infinity, Stryker will decide for you and tries to use
* all CPUs in your machine optimally.
*/
maxConcurrentTestRunners?: number;
maxConcurrentTestRunners: number;

/**
* A location to a config file. That file should export a function which accepts a "config" object which it uses to configure stryker
Expand All @@ -45,9 +45,9 @@ interface StrykerOptions {
testFramework?: string;

/**
* The name of the test runner to use (default is the same name as the testFramework)
* The name of the test runner to use (default is 'command')
*/
testRunner?: string;
testRunner: string;

/**
* The mutant generator to use to generate mutants based on your input file.
Expand All @@ -61,7 +61,7 @@ interface StrykerOptions {
* * The `excludedMutations` property is mandatory and contains the names of the specific mutation types to exclude from testing.
* * The values must match the given names of the mutations. For example: 'BinaryExpression', 'BooleanSubstitution', etc.
*/
mutator?: string | MutatorDescriptor;
mutator: string | MutatorDescriptor;

/**
* The names of the transpilers to use (in order). Default: [].
Expand All @@ -80,12 +80,12 @@ interface StrykerOptions {
*
* Transpilers should ignore files marked with `transpiled = false`. See `files` array.
*/
transpilers?: string[];
transpilers: string[];

/**
* Thresholds for mutation score.
*/
thresholds?: Partial<MutationScoreThresholds>;
thresholds: MutationScoreThresholds;

/**
* Indicates which coverage analysis strategy to use.
Expand All @@ -95,7 +95,7 @@ interface StrykerOptions {
* 'all': Analyse the coverage for the entire test suite.
* 'off': Don't use coverage analysis
*/
coverageAnalysis?: 'perTest' | 'all' | 'off';
coverageAnalysis: 'perTest' | 'all' | 'off';

/**
* DEPRECATED PROPERTY. Please use the `reporters` property
Expand All @@ -106,24 +106,24 @@ interface StrykerOptions {
* Possible values: 'clear-text', 'progress'.
* Load more plugins to be able to use more reporters
*/
reporters?: string[];
reporters: string[];

/**
* The log level for logging to a file. If defined, stryker will output a log file called "stryker.log".
* Default: "off"
*/
fileLogLevel?: LogLevel;
fileLogLevel: LogLevel;

/**
* The log level for logging to the console. Default: "info".
*/
logLevel?: LogLevel;
logLevel: LogLevel;

/**
* Indicates whether or not to symlink the node_modules folder inside the sandbox folder(s).
* Default: true
*/
symlinkNodeModules?: boolean;
symlinkNodeModules: boolean;

/**
* DEPRECATED PROPERTY. Please use the `timeoutMS` property
Expand All @@ -132,17 +132,17 @@ interface StrykerOptions {
/**
* Amount of additional time, in milliseconds, the mutation test is allowed to run
*/
timeoutMS?: number;
timeoutMS: number;

/**
* The factor is applied on top of the other timeouts when during mutation testing
*/
timeoutFactor?: number;
timeoutFactor: number;

/**
* A list of plugins. These plugins will be imported ('required') by Stryker upon loading.
*/
plugins?: string[];
plugins: string[];

/**
* DEPRECATED
Expand All @@ -154,7 +154,7 @@ interface StrykerOptions {
* Indicates whether or not to use colors in console.
* Default: true
*/
allowConsoleColors?: boolean;
allowConsoleColors: boolean;
}

export default StrykerOptions;
53 changes: 53 additions & 0 deletions packages/stryker-api/src/plugin/Contexts.ts
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;
}
11 changes: 11 additions & 0 deletions packages/stryker-api/src/plugin/PluginKind.ts
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'
}
Loading