Skip to content

Commit

Permalink
feat(api): Deprecated Config in favor of StrykerOptions
Browse files Browse the repository at this point in the history
* Deprecate `Config`, use `StrykerOptions` instead (no `set` method)
* Deprecate `ConfigEditor`, use `OptionsEditor` instead
  • Loading branch information
nicojs committed Apr 19, 2020
1 parent 25943f7 commit dccdd91
Show file tree
Hide file tree
Showing 45 changed files with 343 additions and 678 deletions.
4 changes: 2 additions & 2 deletions packages/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ You can extend Stryker in a number of ways.
2. Create a custom `Reporter`
3. Create a `TestFramework` for a test framework
4. Create a `TestRunner` to bridge the gap between your test runner and Stryker
5. Create a custom way of configuring Stryker by creating a `ConfigEditor`
5. Create a custom way of configuring Stryker by creating an `OptionsEditor`

All extension points work in the same basic way.

1. Create a `constructor function` (or `class`)
2. Register the `constructor function` to the correct `Factory`.

More info comming soon. In the mean time, take a look at the [Stryker homepage](https://stryker-mutator.io).
For more info, please take a look at the [Stryker handbook](https://github.com/stryker-mutator/stryker-handbook/blob/master/stryker/api/plugins.md#plugins).
1 change: 0 additions & 1 deletion packages/api/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { default as Config } from './src/config/Config';
export { default as ConfigEditor } from './src/config/ConfigEditor';
export { default as defaultTempDirName } from './src/config/DefaultTempDirName';
3 changes: 3 additions & 0 deletions packages/api/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ export { default as Location } from './src/core/Location';
export { default as Range } from './src/core/Range';
export * from './src-generated/core';
export * from './src/core/ReportTypes';
export * from './src/core/StrykerOptionsSchema';
export * from './src/core/PartialStrykerOptions';
export * from './src/core/OptionsEditor';
4 changes: 2 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scripts": {
"generate": "node tasks/generate-json-schema-to-ts.js",
"stryker": "node ../core/bin/stryker run",
"test": "nyc --exclude-after-remap=false --exclude 'testResources/**/*.js' --check-coverage --reporter=html --report-dir=reports/coverage --lines 85 --functions 85 --branches 85 npm run mocha",
"test": "nyc --exclude-after-remap=false --exclude 'testResources/**/*.js' --check-coverage --reporter=html --report-dir=reports/coverage --lines 85 --functions 85 --branches 80 npm run mocha",
"mocha": "mocha \"test/helpers/**/*.js\" \"test/unit/**/*.js\" && mocha --timeout 60000 \"test/helpers/**/*.js\" \"test/integration/**/*.js\""
},
"keywords": [
Expand Down Expand Up @@ -45,6 +45,6 @@
},
"devDependencies": {
"@types/node": "^13.7.1",
"typed-inject": "~2.1.1"
"typed-inject": "~2.2.1"
}
}
6 changes: 1 addition & 5 deletions packages/api/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@ export * from './src/plugin/Plugins';
export * from './src/plugin/PluginKind';
export * from './src/plugin/tokens';
export * from './src/plugin/Scope';
export * from 'typed-inject/src/api/Injectable';
export * from 'typed-inject/src/api/Injector';
export { InjectionToken } from 'typed-inject/src/api/InjectionToken';
export * from 'typed-inject/src/api/CorrespondingType';
export * from 'typed-inject/src/api/Disposable';
export { Injectable, Injector, InjectionToken, CorrespondingType, Disposable } from 'typed-inject';
68 changes: 5 additions & 63 deletions packages/api/src/config/Config.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,9 @@
import { LogLevel, MutationScoreThresholds, MutatorDescriptor, StrykerOptions, DashboardOptions, ReportType } from '../../core';

import defaultTempDirName from './DefaultTempDirName';
import { StrykerOptions } from '../../core';
import { PartialStrykerOptions } from '../../core';

/**
* When configuring stryker, every option is optional
* Including deep properties like `dashboard.project`.
* That's why we use a `DeepPartial` mapped type here.
* @deprecated Use `StrykerOptions` instead
*/
type DeepPartial<T> = {
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
};

export default class Config implements StrykerOptions {
[customConfig: string]: any;

public files: string[];
public mutate: string[] = [
'{src,lib}/**/*.js?(x)',
'!{src,lib}/**/__tests__/**/*.js?(x)',
'!{src,lib}/**/?(*.)+(spec|test).js?(x)',
'!{src,lib}/**/*+(Spec|Test).js?(x)'
];

public logLevel: LogLevel = LogLevel.Information;
public fileLogLevel: LogLevel = LogLevel.Off;
public timeoutMS = 5000;
public timeoutFactor = 1.5;
public plugins: string[] = ['@stryker-mutator/*'];
public reporters: string[] = ['html', 'progress', 'clear-text'];
public coverageAnalysis: 'perTest' | 'all' | 'off' = 'off';
public testRunner: string = 'command';
public testFramework: string;
public mutator: string | MutatorDescriptor = 'javascript';
public transpilers: string[] = [];
public maxConcurrentTestRunners: number = Infinity;
public symlinkNodeModules: boolean = true;
public thresholds: MutationScoreThresholds = {
break: null,
high: 80,
low: 60
};

public allowConsoleColors: boolean = true;
/**
* The options for the 'dashboard' reporter
*/
public dashboard: DashboardOptions = {
baseUrl: 'https://dashboard.stryker-mutator.io/api/reports',
reportType: ReportType.Full
};
public tempDirName: string = defaultTempDirName;

public set(newConfig: DeepPartial<StrykerOptions>) {
if (newConfig) {
Object.keys(newConfig).forEach(key => {
if (newConfig[key] !== undefined) {
if (key === 'dashboard') {
this[key] = { ...this[key], ...newConfig[key] };
} else {
this[key] = newConfig[key];
}
}
});
}
}
export default interface Config extends StrykerOptions {
set(newConfig: PartialStrykerOptions): void;
}
5 changes: 3 additions & 2 deletions packages/api/src/config/ConfigEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import Config from './Config';
* any previous ConfigEditor can be passed thru to the next. Please not that
* editing of the configuration object is done by reference.
*
* @deprecated Please use `OptionsEditor` instead
*/
interface ConfigEditor {
/**
* Extending classes only need to implement the edit method, this method
* receives a writable config object that can be editted in any way.
* Please be aware that editting is done via object reference. Therefore
* receives a writable config object that can be edited in any way.
* Please be aware that editing is done via object reference. Therefore
* the return type is void.
*
* @param config: The stryker configuration object
Expand Down
3 changes: 0 additions & 3 deletions packages/api/src/config/DefaultTempDirName.ts

This file was deleted.

22 changes: 22 additions & 0 deletions packages/api/src/core/OptionsEditor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { StrykerOptions } from '../../core';

/**
* Represents an OptionsEditor plugin
*
* OptionEditors can change the content of the stryker options at runtime.
* OptionEditors are implemented as a chain of OptionEditors, the result of
* any previous ConfigEditor can be passed thru to the next. Please not that
* editing of the configuration object is done by reference.
*
*/
export interface OptionsEditor {
/**
* Extending classes only need to implement the edit method, this method
* receives a writable config object that can be edited in any way.
* Please be aware that editing is done via object reference. Therefore
* the return type is void.
*
* @param options: The stryker configuration object
*/
edit(options: StrykerOptions): void;
}
12 changes: 12 additions & 0 deletions packages/api/src/core/PartialStrykerOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { StrykerOptions } from '../../src-generated/core';

/**
* When configuring stryker, every option is optional
* Including deep properties like `dashboard.project`.
* That's why we use a `DeepPartial` mapped type here.
*/
export type PartialStrykerOptions = DeepPartial<StrykerOptions>;

type DeepPartial<T> = {
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
};
1 change: 1 addition & 0 deletions packages/api/src/plugin/Contexts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface TestRunnerPluginContext extends OptionsContext {
*/
export interface PluginContexts {
[PluginKind.ConfigEditor]: BaseContext;
[PluginKind.OptionsEditor]: BaseContext;
[PluginKind.Mutator]: OptionsContext;
[PluginKind.Reporter]: OptionsContext;
[PluginKind.TestFramework]: OptionsContext;
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/plugin/PluginKind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
* The plugin kinds supported by Stryker
*/
export enum PluginKind {
/**
* @deprecated, please use `OptionsEditor`
*/
ConfigEditor = 'ConfigEditor',
OptionsEditor = 'OptionsEditor',
TestRunner = 'TestRunner',
TestFramework = 'TestFramework',
Transpiler = 'Transpiler',
Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/plugin/Plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Reporter } from '../../report';
import { TestFramework } from '../../test_framework';
import { TestRunner } from '../../test_runner';
import { Transpiler } from '../../transpile';
import { OptionsEditor } from '../core/OptionsEditor';

import { PluginContexts } from './Contexts';
import { PluginKind } from './PluginKind';
Expand Down Expand Up @@ -83,6 +84,7 @@ export function declareFactoryPlugin<TPluginKind extends PluginKind, Tokens exte
*/
export interface PluginInterfaces {
[PluginKind.ConfigEditor]: ConfigEditor;
[PluginKind.OptionsEditor]: OptionsEditor;
[PluginKind.Mutator]: Mutator;
[PluginKind.Reporter]: Reporter;
[PluginKind.TestFramework]: TestFramework;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ describe('we have a module using stryker', () => {
});
};
arrangeActAndAssertModule('core', ['files', 'file']);
arrangeActAndAssertModule('config', ["plugins: [ '@stryker-mutator/*' ]"]);
arrangeActAndAssertModule('test_framework', ['done']);
arrangeActAndAssertModule('mutant', ["mutatorName: 'foo'"]);
arrangeActAndAssertModule('report', ['status: 3', 'Mutant status runtime error: RuntimeError', 'transpile error: TranspileError']);
Expand Down
97 changes: 0 additions & 97 deletions packages/api/test/unit/config/Config.spec.ts

This file was deleted.

12 changes: 0 additions & 12 deletions packages/api/testResources/module/useConfig.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/api/testResources/module/useMutant.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Config } from '@stryker-mutator/api/config';
import { File } from '@stryker-mutator/api/core';
import { Mutant, Mutator } from '@stryker-mutator/api/mutant';

Expand Down
2 changes: 1 addition & 1 deletion packages/api/tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
"path": "./tsconfig.src.json"
}
]
}
}
5 changes: 2 additions & 3 deletions packages/core/src/child-proxy/ChildProcessProxyWorker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as path from 'path';

import { Config } from '@stryker-mutator/api/config';
import { File } from '@stryker-mutator/api/core';
import { File, StrykerOptions } from '@stryker-mutator/api/core';
import { errorToString } from '@stryker-mutator/util';
import { getLogger, Logger } from 'log4js';

Expand Down Expand Up @@ -35,7 +34,7 @@ export default class ChildProcessProxyWorker {
LogConfigurator.configureChildProcess(message.loggingContext);
this.log = getLogger(ChildProcessProxyWorker.name);
this.handlePromiseRejections();
let injector = buildChildProcessInjector((message.options as unknown) as Config);
let injector = buildChildProcessInjector(message.options);
const locals = message.additionalInjectableValues as any;
for (const token of Object.keys(locals)) {
injector = injector.provideValue(token, locals[token]);
Expand Down
22 changes: 0 additions & 22 deletions packages/core/src/config/ConfigEditorApplier.ts

This file was deleted.

Loading

0 comments on commit dccdd91

Please sign in to comment.