Skip to content

Commit

Permalink
feat(core): add appendPlugins command-line option (#2385)
Browse files Browse the repository at this point in the history
Add `--appendPlugins` command-line option that can append plugins without overriding the (default) `plugins`. This is a way for tools to add plugins without affecting anything else.
  • Loading branch information
Garethp authored Sep 25, 2020
1 parent 4a82553 commit 0dec9b8
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 2 deletions.
9 changes: 7 additions & 2 deletions e2e/test/jasmine-ts-node/stryker.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
"testRunner": "jasmine",
"concurrency": 2,
"coverageAnalysis": "perTest",
"reporters": ["event-recorder", "clear-text"],
"reporters": [
"event-recorder",
"clear-text"
],
"appendPlugins": [
"@stryker-mutator/typescript-checker"
],
"plugins": [
"@stryker-mutator/typescript-checker",
"@stryker-mutator/jasmine-runner"
]
}
8 changes: 8 additions & 0 deletions packages/api/schema/stryker-core.json
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,14 @@
"@stryker-mutator/*"
]
},
"appendPlugins": {
"description": "A list of additional plugins you want Stryker to load (`require`) without overwriting the (default) `plugins`.",
"type": "array",
"items": {
"type": "string"
},
"default": []
},
"reporters": {
"description": "With reporters, you can set the reporters for stryker to use.",
"type": "array",
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/StrykerCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ export default class StrykerCli {
.option('--testRunner <name>', 'The name of the test runner you want to use')
.option('--reporters <name>', 'A comma separated list of the names of the reporter(s) you want to use', list)
.option('--plugins <listOfPlugins>', 'A list of plugins you want stryker to load (`require`).', list)
.option(
'--appendPlugins <listOfPlugions>',
'A list of additional plugins you want Stryker to load (`require`) without overwriting the (default) `plugins`.',
list
)
.option('--timeoutMS <number>', 'Tweak the absolute timeout used to wait for a test runner to complete', parseInt)
.option('--timeoutFactor <number>', 'Tweak the standard deviation relative to the normal test run of a mutated test', parseFloat)
.option('--maxConcurrentTestRunners <n>', 'Set the number of max concurrent test runner to spawn (default: cpuCount)', parseInt)
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/di/buildMainInjector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function createPluginResolverProvider(parent: CliOptionsProvider): Plugin

function pluginDescriptorsFactory(options: StrykerOptions): readonly string[] {
options.plugins.push(require.resolve('../reporters'));
options.plugins = options.plugins.concat(options.appendPlugins);
return options.plugins;
}
pluginDescriptorsFactory.inject = tokens(commonTokens.options);
1 change: 1 addition & 0 deletions packages/core/test/unit/StrykerCli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe(StrykerCli.name, () => {
[['--mutate', 'foo.js,bar.js'], { mutate: ['foo.js', 'bar.js'] }],
[['--reporters', 'foo,bar'], { reporters: ['foo', 'bar'] }],
[['--plugins', 'foo,bar'], { plugins: ['foo', 'bar'] }],
[['--appendPlugins', 'foo,bar'], { appendPlugins: ['foo', 'bar'] }],
[['--timeoutMS', '42'], { timeoutMS: 42 }],
[['--timeoutFactor', '42'], { timeoutFactor: 42 }],
[['--maxConcurrentTestRunners', '42'], { maxConcurrentTestRunners: 42 }],
Expand Down
12 changes: 12 additions & 0 deletions packages/core/test/unit/config/OptionsValidator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ describe(OptionsValidator.name, () => {
});
});

describe('appendPlugins', () => {
it('should be invalid with non-array plugins', () => {
breakConfig('appendPlugins', '@stryker-mutator/typescript');
actValidationErrors('Config option "appendPlugins" has the wrong type. It should be a array, but was a string.');
});

it('should be invalid with non-string array elements', () => {
breakConfig('appendPlugins', ['stryker-jest', 0]);
actValidationErrors('Config option "appendPlugins[1]" has the wrong type. It should be a string, but was a number.');
});
});

describe('mutator', () => {
it('should be invalid with non-string mutator', () => {
(testInjector.options.mutator as any) = 1;
Expand Down

0 comments on commit 0dec9b8

Please sign in to comment.