-
Notifications
You must be signed in to change notification settings - Fork 250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(Stryker CLI 'init'): Support for preset configuration during 'stryker init' #1248
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
532b7de
Dependency changes
Wmaarts 0ec20a8
Prompt for selecting preset config, with simple tests
Wmaarts 0a9ac36
Refactoring and reworking prompting preset logic
Wmaarts 69abf2a
Reincluded stryker.conf.js in stryker package after accidentally dele…
Wmaarts 491100f
Merge remote-tracking branch 'upstream/master'
Wmaarts c4d57fd
Remove unnecessary dependencies
Wmaarts e3e9518
Refactoring of StrykerPreset api.
Wmaarts bdbb16a
Refactor StrykerPreset list to remove arrow function. Also removes th…
Wmaarts 530bf49
Preset-specific test cases for Angular, React and VueJs
Wmaarts dc4f84c
Merge branch 'master' into feat/support-presets
nicojs 79cfe60
Reset stryker-api as a dev dependency of stryker
nicojs 0715195
Rename some things
nicojs 2c7e8ab
Add handbook url to the stryker configuration file
nicojs 520f39e
Fix typing of the prompPresets returned promise
nicojs d8bff5c
Format files using editorconfig
nicojs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we introduce a function here in the
then
branch?