Skip to content

Commit

Permalink
refactor: change ConfigWriter interface name to ConfigEditor (#357)
Browse files Browse the repository at this point in the history
* Rename `ConfigWriter` -> `ConfigEditor`
* Rename `ConfigWriterFactory` -> `ConfigEditorFactory`
* Rename `ConfigEditor.write` -> `ConfigEditor.edit`
* Also renamed all classes that implement `ConfigWriter`

BREAKING CHANGE: Public api for `ConfigWriter` is renamed to `ConfigEditor`. The corresponding `write` method is renamed to `edit`. If you're using custom `ConfigWriter` plugins you should rename the `write` method to `edit`. Please update the `stryker-mocha-framework` and `stryker-karma-runner` to the latest versions as they provide the new `ConfigEditor` plugin.
  • Loading branch information
sharikovvladislav authored and nicojs committed Aug 17, 2017
1 parent 2ef22a4 commit ec4ae03
Show file tree
Hide file tree
Showing 24 changed files with 108 additions and 102 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"typescript": "^2.2.2"
},
"scripts": {
"clean": "lerna run prebuild",
"postinstall": "lerna bootstrap && link-parent-bin",
"prebuild": "npm run clean-integration-test",
"build": "lerna run build",
Expand Down
2 changes: 1 addition & 1 deletion packages/stryker-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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 `ConfigWriter`
5. Create a custom way of configuring Stryker by creating a `ConfigEditor`

All extension points work in the same basic way.

Expand Down
4 changes: 2 additions & 2 deletions packages/stryker-api/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export {default as Config} from './src/config/Config';
export {default as ConfigWriter} from './src/config/ConfigWriter';
export {default as ConfigWriterFactory} from './src/config/ConfigWriterFactory';
export {default as ConfigEditor} from './src/config/ConfigEditor';
export {default as ConfigEditorFactory} from './src/config/ConfigEditorFactory';
3 changes: 2 additions & 1 deletion packages/stryker-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "The api for the extendable JavaScript mutation testing framework Stryker",
"scripts": {
"start": "tsc -w",
"prebuild": "rimraf \"+(*.js|*.map)\" \"src/**/+(*.js|*.map)\" \"test/**/+(*.js|*.map)\" \"testResources/module/+(*.js|*.map)\" \"testResources/module/node_modules/stryker-api\"",
"clean": "rimraf \"+(*.d.ts|*.js|*.map)\" \"src/**/+(*.d.ts|*.js|*.map)\" \"test/**/+(*.d.ts|*.js|*.map)\" \"testResources/module/+(*.d.ts|*.js|*.map)\" \"testResources/module/node_modules/stryker-api\" .nyc_output reports",
"prebuild": "npm run clean",
"build": "tsc -p .",
"postbuild": "tslint -p tsconfig.json",
"test": "nyc --reporter=html --report-dir=reports/coverage --check-coverage --lines 90 --functions 68 --branches 64 mocha \"test/**/*.js\""
Expand Down
7 changes: 7 additions & 0 deletions packages/stryker-api/src/config/ConfigEditor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Config from './Config';

interface ConfigEditor {
edit(config: Config): void;
}

export default ConfigEditor;
26 changes: 26 additions & 0 deletions packages/stryker-api/src/config/ConfigEditorFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {Factory} from '../../core';
import ConfigEditor from './ConfigEditor';

namespace ConfigEditorFactory {

/**
* Represents a Factory for ConfigEditors.
*/
class ConfigEditorFactory extends Factory<void, ConfigEditor> {

constructor() {
super('config-reader');
}
}

let configEditorFactory = new ConfigEditorFactory();

/**
* Returns the current instance of the ConfigEditorFactory.
*/
export function instance() {
return <Factory<void, ConfigEditor>>configEditorFactory;
}
}

export default ConfigEditorFactory;
7 changes: 0 additions & 7 deletions packages/stryker-api/src/config/ConfigWriter.ts

This file was deleted.

26 changes: 0 additions & 26 deletions packages/stryker-api/src/config/ConfigWriterFactory.ts

This file was deleted.

12 changes: 6 additions & 6 deletions packages/stryker-api/testResources/module/useConfig.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {Config, ConfigWriter, ConfigWriterFactory} from 'stryker-api/config';
import {Config, ConfigEditor, ConfigEditorFactory} from 'stryker-api/config';

let config: Config = new Config();

class MyConfigWriter {
class MyConfigEditor {
constructor() {
}

write(config: Config) {
edit(config: Config) {
config.set({ 'myConfig': true });
}
}

ConfigWriterFactory.instance().register('myConfigWriter', MyConfigWriter);
let myConfigWriter = ConfigWriterFactory.instance().create('myConfigWriter', undefined);
myConfigWriter.write(config);
ConfigEditorFactory.instance().register('myConfigEditor', MyConfigEditor);
let myConfigEditor = ConfigEditorFactory.instance().create('myConfigEditor', undefined);
myConfigEditor.edit(config);
console.log(config);
2 changes: 1 addition & 1 deletion packages/stryker-html-reporter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "src/index.js",
"typings": "src/index.d.ts",
"scripts": {
"clean": "rimraf \"+(test|src)/!(resources)/**/*+(.d.ts|.js|.map)\" \"+(test|src)/*+(.d.ts|.js|.map)\" coverage",
"clean": "rimraf \"+(test|src)/!(resources)/**/*+(.d.ts|.js|.map)\" \"+(test|src)/*+(.d.ts|.js|.map)\" .nyc_output reports coverage",
"prebuild": "npm run clean",
"build": "tsc -p . && node tasks/clientResources.js && browserify src/resources/stryker.js -o resources/stryker.js",
"postbuild": "tslint -p tsconfig.json",
Expand Down
3 changes: 2 additions & 1 deletion packages/stryker-jasmine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "src/index.js",
"scripts": {
"start": "tsc -w",
"prebuild": "rimraf \"src/**/+(*.js|*.map)\" \"test/**/+(*.js|*.map)\"",
"clean": "rimraf \"src/**/+(*.d.ts|*.js|*.map)\" \"test/**/+(*.d.ts|*.js|*.map)\" .nyc_output reports",
"prebuild": "npm run clean",
"build": "tsc -p .",
"postbuild": "tslint -p tsconfig.json",
"test": "nyc --reporter=html --report-dir=reports/coverage --check-coverage --lines 100 --functions 100 --branches 100 mocha \"test/**/*.js\""
Expand Down
3 changes: 2 additions & 1 deletion packages/stryker-karma-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "src/index.js",
"scripts": {
"start": "tsc -w",
"prebuild": "rimraf \"+(test|src)/**/*+(.d.ts|.js|.map)\" coverage",
"clean": "rimraf \"+(test|src)/**/*+(.d.ts|.js|.map)\" .nyc_output reports coverage",
"prebuild": "npm run clean",
"build": "tsc -p .",
"postbuild": "tslint -p tsconfig.json",
"test": "nyc --reporter=html --report-dir=reports/coverage --check-coverage --lines 80 --functions 80 --branches 75 mocha \"test/**/*.js\""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import * as log4js from 'log4js';
import * as karma from 'karma';
import { InputFileDescriptor } from 'stryker-api/core';
import { ConfigWriter, Config as StrykerConfig } from 'stryker-api/config';
import { ConfigEditor, Config as StrykerConfig } from 'stryker-api/config';
import KarmaConfigReader from './KarmaConfigReader';

const log = log4js.getLogger('KarmaConfigWriter');
const log = log4js.getLogger('KarmaConfigEditor');

export default class KarmaConfigWriter implements ConfigWriter {
write(strykerConfig: StrykerConfig) {
export default class KarmaConfigEditor implements ConfigEditor {
edit(strykerConfig: StrykerConfig) {
const karmaConfig = new KarmaConfigReader(strykerConfig['karmaConfigFile']).read();
if (karmaConfig) {
KarmaConfigWriter.importFiles(strykerConfig, karmaConfig);
KarmaConfigWriter.importDefaultKarmaConfig(strykerConfig, karmaConfig);
KarmaConfigEditor.importFiles(strykerConfig, karmaConfig);
KarmaConfigEditor.importDefaultKarmaConfig(strykerConfig, karmaConfig);
}
}

Expand All @@ -23,7 +23,7 @@ export default class KarmaConfigWriter implements ConfigWriter {
const files: (karma.FilePattern | string)[] = karmaConfig.files;
const exclude: string[] = karmaConfig.exclude;
if (files && Array.isArray(files)) {
const karmaFiles = files.map(KarmaConfigWriter.toInputFileDescriptor);
const karmaFiles = files.map(KarmaConfigEditor.toInputFileDescriptor);
log.debug(`Importing following files from karma.conf file to stryker: ${JSON.stringify(karmaFiles)}`);
strykerConfig.files = strykerConfig.files.concat(karmaFiles);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/stryker-karma-runner/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TestRunnerFactory } from 'stryker-api/test_runner';
import { ConfigWriterFactory } from 'stryker-api/config';
import { ConfigEditorFactory } from 'stryker-api/config';
import KarmaTestRunner from './KarmaTestRunner';
import KarmaConfigWriter from './KarmaConfigWriter';
import KarmaConfigEditor from './KarmaConfigEditor';

TestRunnerFactory.instance().register('karma', KarmaTestRunner);
ConfigWriterFactory.instance().register('karma', KarmaConfigWriter);
ConfigEditorFactory.instance().register('karma', KarmaConfigEditor);
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import * as path from 'path';
import { Config } from 'stryker-api/config';
import KarmaConfigWriter from '../../src/KarmaConfigWriter';
import KarmaConfigEditor from '../../src/KarmaConfigEditor';

function resolve(filePath: string) {
return path.resolve(`testResources/configs/${filePath}`).replace(/\\/g, '/');
Expand All @@ -13,11 +13,11 @@ function strykerConfig(karmaConfigPath: string) {
return config;
}

describe('KarmaConfigWriter', () => {
describe('KarmaConfigEditor', () => {

it('should override the stryker `files` property when no `files` were present', () => {
const config = strykerConfig('testResources/configs/files-karma.conf.js');
new KarmaConfigWriter().write(config);
new KarmaConfigEditor().edit(config);
expect(config.files).to.deep.eq([
{ included: true, mutated: false, pattern: resolve('src/**/*.js') },
{ included: false, mutated: false, pattern: resolve('resources/**/*.js') },
Expand All @@ -29,14 +29,14 @@ describe('KarmaConfigWriter', () => {
it('should add to the stryker `files` property when `files` were already present', () => {
const config = strykerConfig('testResources/configs/files-karma.conf.js');
config.files = ['some file'];
new KarmaConfigWriter().write(config);
new KarmaConfigEditor().edit(config);
expect(config.files).to.have.length(6);
expect(config.files[0]).to.be.eq('some file');
});

it('should fill the "karmaConfig" object if no "karmaConfig" object was present', () => {
const config = strykerConfig(resolve('example-karma.conf.js'));
new KarmaConfigWriter().write(config);
new KarmaConfigEditor().edit(config);

const expectedConfig: any = {
basePath: '',
Expand Down Expand Up @@ -65,7 +65,7 @@ describe('KarmaConfigWriter', () => {

it('should not do anything if no "karmaConfigFile" property is present', () => {
const config = new Config();
new KarmaConfigWriter().write(config);
new KarmaConfigEditor().edit(config);
expect(config.files).to.not.be.ok;
expect(config['karmaConfig']).to.not.be.ok;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import * as sinon from 'sinon';
import { expect } from 'chai';
import * as karmaConfigReaderModule from '../../src/KarmaConfigReader';
import KarmaConfigWriter from '../../src/KarmaConfigWriter';
import KarmaConfigEditor from '../../src/KarmaConfigEditor';
import { Config } from 'stryker-api/config';

describe('KarmaConfigWriter', () => {
let sut: KarmaConfigWriter;
describe('KarmaConfigEditor', () => {
let sut: KarmaConfigEditor;
let sandbox: sinon.SinonSandbox;
let karmaConfigReader: { read: sinon.SinonStub };
let config: Config;

beforeEach(() => {
sut = new KarmaConfigWriter();
sut = new KarmaConfigEditor();
sandbox = sinon.sandbox.create();
karmaConfigReader = { read: sandbox.stub() };
sandbox.stub(karmaConfigReaderModule, 'default').returns(karmaConfigReader);
Expand All @@ -24,15 +24,15 @@ describe('KarmaConfigWriter', () => {
describe('write', () => {

it('should create karmaConfigReader using "karmaConfigFile"', () => {
sut.write(config);
sut.edit(config);
expect(karmaConfigReaderModule.default).to.have.been.calledWith('expectedFile');
expect(karmaConfigReaderModule.default).to.have.been.calledWithNew;
});

describe('without readable config', () => {

it('should not override the runner', () => {
sut.write(config);
sut.edit(config);
expect(config.testRunner).to.be.undefined;
});
});
Expand All @@ -46,46 +46,46 @@ describe('KarmaConfigWriter', () => {
});

it('should not override the runner if it was not provided already, as it could result in strange behavior', () => {
sut.write(config);
sut.edit(config);
expect(config.testRunner).to.be.undefined;
});

it('should not override the runner if it was provided already', () => {
config.testRunner = 'harry';
sut.write(config);
sut.edit(config);
expect(config.testRunner).to.be.eq('harry');
});

it('should import files', () => {
karmaConfig.files = [{ pattern: 'somePattern' }];
sut.write(config);
sut.edit(config);
expect(config.files).to.be.deep.eq([{ pattern: 'somePattern', mutated: false, included: false }]);
});

it('should not completely override files', () => {
karmaConfig.files = [{ pattern: 'somePattern' }];
config.files = ['someFile'];
sut.write(config);
sut.edit(config);
expect(config.files).to.be.deep.eq(['someFile', { pattern: 'somePattern', mutated: false, included: false }]);
});

it('should exclude the excluded files', () => {
karmaConfig.exclude = ['someFile'];
sut.write(config);
sut.edit(config);
expect(config.files).to.be.deep.eq(['!someFile']);
});

it('should add karmaConfig to the options', () => {
karmaConfig.something = 'blaat';
sut.write(config);
sut.edit(config);
expect(config['karmaConfig']).to.be.eq(karmaConfig);
});

it('should not override existing karmaConfig', () => {
config['karmaConfig'] = { value: 'overriden' };
karmaConfig.value = 'base';
karmaConfig.theAnswer = 42;
sut.write(config);
sut.edit(config);
expect(config['karmaConfig'].value).to.be.eq('overriden');
expect(config['karmaConfig'].theAnswer).to.be.eq(42);
});
Expand Down
3 changes: 2 additions & 1 deletion packages/stryker-mocha-framework/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "src/index.js",
"scripts": {
"start": "tsc -w",
"prebuild": "rimraf \"+(test|src)/**/*+(.d.ts|.js|.map)\" coverage",
"clean": "rimraf \"+(test|src)/**/*+(.d.ts|.js|.map)\" reports .nyc_output coverage",
"prebuild": "npm run clean",
"build": "tsc -p .",
"postbuild": "tslint -p tsconfig.json",
"test": "nyc --reporter=html --report-dir=reports/coverage --check-coverage --lines 100 --functions 100 --branches 100 mocha \"test/**/*.js\""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Config, ConfigWriter } from 'stryker-api/config';
import { Config, ConfigEditor } from 'stryker-api/config';
import * as log4js from 'log4js';

export default class MochaConfigWriter implements ConfigWriter {
export default class MochaConfigEditor implements ConfigEditor {
private log: log4js.Logger;

constructor() {
this.log = log4js.getLogger('MochaConfigWriter');
this.log = log4js.getLogger('MochaConfigEditor');
}

write(config: Config) {
edit(config: Config) {
if (config.coverageAnalysis === 'perTest' && config.testRunner !== 'mocha') {
this.log.warn(`Framework "mocha" with coverageAnalysis "perTest" is only supported with the "mocha" test runner (not "${config.testRunner}"). Downgrading to coverageAnalysis "all".`);
config.coverageAnalysis = 'all';
Expand Down
6 changes: 3 additions & 3 deletions packages/stryker-mocha-framework/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ConfigWriterFactory } from 'stryker-api/config';
import { ConfigEditorFactory } from 'stryker-api/config';
import { TestFrameworkFactory } from 'stryker-api/test_framework';

import MochaConfigWriter from './MochaConfigWriter';
import MochaConfigEditor from './MochaConfigEditor';
import MochaTestFramework from './MochaTestFramework';

TestFrameworkFactory.instance().register('mocha', MochaTestFramework);
ConfigWriterFactory.instance().register('mocha', MochaConfigWriter);
ConfigEditorFactory.instance().register('mocha', MochaConfigEditor);
Loading

0 comments on commit ec4ae03

Please sign in to comment.