-
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
Conversation
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.
Looks great already! Thanks for picking this up! I've got a few remarks, but mostly small ones.
I like the idea of the different StrykerPreset
classes being able to ask additional questions. It is a clean way to separate them from the StrykerInitializer
class itself.
I would like to have a unit tests for the different Stryker initializers themselves. Can be small, just asserting a part of the configuration. If you want, I can help with that.
@@ -47,7 +47,6 @@ | |||
"devDependencies": { | |||
"@babel/types": "~7.1.2", | |||
"@types/babel__generator": "^7.0.0", | |||
"@types/babel__parser": "^7.0.0", |
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.
Why is this in the PR?
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.
package.json
Outdated
@@ -15,7 +15,7 @@ | |||
"@types/mkdirp": "^0.5.2", | |||
"@types/mocha": "^2.2.44", | |||
"@types/rimraf": "2.0.2", | |||
"@types/sinon": "^5.0.1", | |||
"@types/sinon": "5.0.5", |
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.
Why is this in the PR?
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.
same as above comment
packages/stryker/package.json
Outdated
@@ -83,7 +83,10 @@ | |||
"@types/node": "~10.11.4", | |||
"@types/prettier": "~1.13.1", | |||
"@types/progress": "~2.0.1", | |||
"stryker-api": "^0.21.5" | |||
"stryker-api": "^0.21.5", | |||
"stryker-html-reporter": "^0.16.7", |
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.
Can we remove these dependencies? We're planning to run Stryker on Stryker in the build in Februari
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.
I'll remove then, yes. These were accidentally generated while testing stryker init.
await this.fetchAdditionalConfig(npmDependencies)); | ||
this.installNpmDependencies(npmDependencies, selectedPackageManager); | ||
const selectedPreset = await this.selectPreset(); | ||
if (selectedPreset) { |
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?
this.installNpmDependencies(selectedPresetInstance.dependencies, selectedPackageManager); | ||
} | ||
else { | ||
const selectedTestRunner = await this.selectTestRunner(); |
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.
Idem for this else
branch
import PresetOption from './PresetOption'; | ||
|
||
const strykerPresets: PresetOption[] = [ | ||
{name: 'angular', create() { return new AngularPreset(); } }, |
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 remove this second layer? Seems complicated. Couldn't we create an array of StrykerPreset
classes here?
export default const strykerPresets = [ new AngularPreset(), new ReactPreset(), new VueJsPreset() ];
We could add the name
property to the StrykerPreset
class as an abstract property.
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.
The idea was to preserve memory by only instantiating a preset once it's needed. Hence the arrow functions.
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.
I understand, but you'll save a couple of bytes at most. I would rather have a piece of code that is better to understand and easier to maintain.
Ever heard of the phrase:
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.
but you'll save a couple of bytes at most.
Fair point. 😅
I implemented your suggestion here.
'stryker-typescript', | ||
'stryker-html-reporter' | ||
]; | ||
public conf = `{ |
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.
Can we add a reference to this conf object to keep it in sync with the handbook?
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.
Same goes for the other presets
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.
A better idea is to add a link to the specific handbook article at the top of the configuration file (in comments). That way, people know where to find more information.
@@ -0,0 +1,9 @@ | |||
abstract class StrykerPreset { | |||
public abstract dependencies: string[]; | |||
public abstract conf: string; |
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.
I don't like this api. There is an implicit dependency between the prompt()
method and the conf
and dependencies
properties. As in, you need to call prompt
before you can read the properties. Can we make the configuration and dependencies a return value of prompt
. Maybe we shouldn't call it prompt
anymore, because it does more. Maybe call it configure
? I'm open to suggestions.
@@ -0,0 +1,6 @@ | |||
import StrykerPreset from '../../src/initializer/presets/StrykerPreset'; | |||
|
|||
export class StrykerPresetMock extends StrykerPreset { |
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.
Can this class reside in the StrykerInitializerSpec
? Seems that it is only used there. I don't want helpers
to get cluttered with mocks that are only used once.
@@ -103,6 +116,77 @@ describe('StrykerInitializer', () => { | |||
expect(promptPackageManagers.choices).to.deep.eq(['npm', 'yarn']); | |||
}); | |||
|
|||
it('should immediately complete when a preset and package manager is chosen', async () => { |
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.
Great tests here! 👍
Pushed some changes that were suggested, but I'm not sure why the build is failing now. |
I don't know either. I've merged master and pushed to your branch. New build is running. EDIT: found the issue. |
* `StrykerPreset` -> `Preset` * `StrykerPresetConf` -> `PresetConfiguration`
I've committed a few more changes. Namely renamed some stuff, changed the abstract classes to interfaces where appropriate and added the handbook url to the outputted stryker.conf.js file. |
Thanks again for your help @Wmaarts |
Implementation of #1049
Small disclaimer
(my first time contributing to an open-source project, hope I'm doing this right. Also, I'm new to the stryker project. 😄 )
Summary
Implementation
Where?
Presets are defined in the stryker package under \src\initializer\presets.
Adding a new preset
Extends the StrykerPreset class like so:
Add your preset to StrykerPresets.ts like so:
Done. 👍
Shortcomings
npx stryker run
instead ofstryker run
, but when the angular preset is chosen the user is still told to usestryker run
.