-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Stryker CLI 'init'): Support for preset configuration during 'st…
…ryker init' (#1248) Add a question to the `init` command: ``` Are you using one of these frameworks? Then select a preset configuration. (Use arrow keys) > angular-cli react vueJs ────────────── None/other ``` If you choose a preset, preset specific questions may be asked. If all is well, Stryker will work out-of-the box.
- Loading branch information
Showing
12 changed files
with
605 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { AngularPreset } from './presets/AngularPreset'; | ||
import { ReactPreset } from './presets/ReactPreset'; | ||
import Preset from './presets/Preset'; | ||
import { VueJsPreset } from './presets/VueJsPreset'; | ||
|
||
// Add new presets here | ||
const strykerPresets: Preset[] = [ new AngularPreset(), new ReactPreset(), new VueJsPreset() ]; | ||
export default strykerPresets; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import Preset from './Preset'; | ||
import PresetConfiguration from './PresetConfiguration'; | ||
import * as os from 'os'; | ||
|
||
const handbookUrl = 'https://github.com/stryker-mutator/stryker-handbook/blob/master/stryker/guides/angular.md#angular'; | ||
|
||
export class AngularPreset implements Preset { | ||
public readonly name = 'angular-cli'; | ||
// Please keep config in sync with handbook | ||
private readonly dependencies = [ | ||
'stryker', | ||
'stryker-karma-runner', | ||
'stryker-typescript', | ||
'stryker-html-reporter' | ||
]; | ||
private readonly config = `{ | ||
mutate: [ | ||
'src/**/*.ts', | ||
'!src/**/*.spec.ts', | ||
'!src/test.ts', | ||
'!src/environments/*.ts' | ||
], | ||
mutator: 'typescript', | ||
testRunner: 'karma', | ||
karma: { | ||
configFile: 'src/karma.conf.js', | ||
projectType: 'angular-cli', | ||
config: { | ||
browsers: ['ChromeHeadless'] | ||
} | ||
}, | ||
reporters: ['progress', 'clear-text', 'html'], | ||
maxConcurrentTestRunners: ${Math.floor(os.cpus().length / 2)}, // Recommended to use about half of your available cores when running stryker with angular. | ||
coverageAnalysis: 'off' | ||
}`; | ||
public async createConfig(): Promise<PresetConfiguration> { | ||
return { config: this.config, handbookUrl, dependencies: this.dependencies }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import PresetConfig from './PresetConfiguration'; | ||
|
||
interface Preset { | ||
readonly name: string; | ||
createConfig(): Promise<PresetConfig>; | ||
} | ||
export default Preset; |
5 changes: 5 additions & 0 deletions
5
packages/stryker/src/initializer/presets/PresetConfiguration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default interface PresetConfiguration { | ||
config: string; | ||
handbookUrl: string; | ||
dependencies: string[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import Preset from './Preset'; | ||
import inquirer = require('inquirer'); | ||
import PresetConfiguration from './PresetConfiguration'; | ||
|
||
const handbookUrl = 'https://github.com/stryker-mutator/stryker-handbook/blob/master/stryker/guides/react.md#react'; | ||
|
||
/** | ||
* More information can be found in the Stryker handbook: | ||
* https://github.com/stryker-mutator/stryker-handbook/blob/master/stryker/guides/react.md#react | ||
*/ | ||
export class ReactPreset implements Preset { | ||
public readonly name = 'react'; | ||
private readonly generalDependencies = [ | ||
'stryker', | ||
'stryker-jest-runner', | ||
'stryker-html-reporter' | ||
]; | ||
|
||
private readonly sharedConfig = `testRunner: 'jest', | ||
reporters: ['progress', 'clear-text', 'html'], | ||
coverageAnalysis: 'off', | ||
jest: { | ||
projectType: 'react' | ||
} | ||
`; | ||
|
||
private readonly tsxDependencies = ['stryker-typescript', ...this.generalDependencies]; | ||
private readonly tsxConf = `{ | ||
mutate: ['src/**/*.ts?(x)', '!src/**/*@(.test|.spec|Spec).ts?(x)'], | ||
mutator: 'typescript', | ||
${this.sharedConfig} | ||
}`; | ||
|
||
private readonly jsxDependencies = ['stryker-javascript-mutator', ...this.generalDependencies]; | ||
private readonly jsxConf = `{ | ||
mutate: ['src/**/*.js?(x)', '!src/**/*@(.test|.spec|Spec).js?(x)'], | ||
mutator: 'javascript', | ||
${this.sharedConfig} | ||
}`; | ||
|
||
public async createConfig(): Promise<PresetConfiguration> { | ||
const choices: inquirer.ChoiceType[] = ['JSX', 'TSX']; | ||
const answers = await inquirer.prompt<{ choice: string }>({ | ||
choices, | ||
message: 'Is your project a JSX project or a TSX project?', | ||
name: 'choice', | ||
type: 'list' | ||
}); | ||
return this.load(answers.choice); | ||
} | ||
private load(choice: string): PresetConfiguration { | ||
if (choice === 'JSX') { | ||
return { config: this.jsxConf, handbookUrl, dependencies: this.jsxDependencies }; | ||
} else if (choice === 'TSX') { | ||
return { config: this.tsxConf, handbookUrl, dependencies: this.tsxDependencies }; | ||
} else { | ||
throw new Error(`Invalid project type ${choice}`); | ||
} | ||
} | ||
} |
Oops, something went wrong.