Skip to content

Commit

Permalink
fix(config): deprecate function based config (#2499)
Browse files Browse the repository at this point in the history
add deprecation warning for function based config

BREAKING CHANGE: exporting a function from stryker.conf.js is deprecated. Please export your config as an object instead, or use a stryker.conf.json file.

Co-authored-by: Nico Jansen <jansennico@gmail.com>
  • Loading branch information
Bartosz Leoniak and nicojs authored Sep 26, 2020
1 parent c8dcecd commit 8ea3c18
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 45 deletions.
7 changes: 2 additions & 5 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ assignees: ''

<!--- Please place your stryker config below. Feel free to change paths in the files and mutate arrays if you cannot share them. -->

```js
module.exports = function(config){
config.set({
....
});
```json
{
}
```

Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/config/ConfigReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export default class ConfigReader {
const configModule = this.loadConfigModule();
let options: StrykerOptions;
if (typeof configModule === 'function') {
this.log.warn(
'Usage of `module.export = function(config) {}` is deprecated. Please use `module.export = {}` or a "stryker.conf.json" file. For more details, see https://stryker-mutator.io/blog/2020-03-11/stryker-version-3#new-config-format'
);
options = defaultOptions();
configModule(createConfig(options));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,16 @@ describe(ConfigReader.name, () => {
expect(() => sut.readConfig()).throws('Invalid config file. Inner error: SyntaxError: Unexpected identifier');
});
});

describe('deprecation informations', () => {
it('should report deprecation on module.export = function(config) {}', () => {
sut = createSut({ configFile: 'testResources/config-reader/deprecatedFunction.conf.js' });
sut.readConfig();

expect(testInjector.logger.warn).calledWithMatch(
'Usage of `module.export = function(config) {}` is deprecated. Please use `module.export = {}` or a "stryker.conf.json" file. For more details, see https://stryker-mutator.io/blog/2020-03-11/stryker-version-3#new-config-format'
);
});
});
});
});
44 changes: 21 additions & 23 deletions packages/core/testResources/config-reader/deprecated.conf.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
module.exports = function(config){
config.set({
mutator: {
name: 'javascript',
excludedMutations: [
'ArrayLiteral',
'ArrayNewExpression',
'BinaryExpression',
'Block',
'BooleanSubstitution',
'DoStatement',
'ForStatement',
'IfStatement',
'PrefixUnaryExpression',
'PostfixUnaryExpression',
'SwitchCase',
'WhileStatement',
'ObjectLiteral',
'ArrowFunctionMutator'
]
}
});
};
module.exports = {
mutator: {
name: 'javascript',
excludedMutations: [
'ArrayLiteral',
'ArrayNewExpression',
'BinaryExpression',
'Block',
'BooleanSubstitution',
'DoStatement',
'ForStatement',
'IfStatement',
'PrefixUnaryExpression',
'PostfixUnaryExpression',
'SwitchCase',
'WhileStatement',
'ObjectLiteral',
'ArrowFunctionMutator'
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = function(config){
config.set({
'valid': 'config',
'should': 'be',
'read': true,
'type': 'js'
});
};
14 changes: 6 additions & 8 deletions packages/core/testResources/config-reader/js/stryker.conf.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

module.exports = function(config){
config.set({
'valid': 'config',
'should': 'be',
'read': true,
'type': 'js'
});
};
module.exports = {
'valid': 'config',
'should': 'be',
'read': true,
'type': 'js'
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

module.exports = function(config){
config.set({
'valid': 'config',
'should': 'be',
'read': true,
'type': 'js'
});
};
module.exports = {
'valid': 'config',
'should': 'be',
'read': true,
'type': 'js'
}
2 changes: 1 addition & 1 deletion packages/jasmine-runner/.mocharc.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"require": ["test/setup.js"],
"timeout": 10000
"timeout": 30000
}

0 comments on commit 8ea3c18

Please sign in to comment.