Skip to content
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

fix(schematics): avoid lastIndexOf error while creating store schematics (#1659) #1666

Merged
merged 1 commit into from
Apr 3, 2019

Conversation

EnricoVogt
Copy link
Contributor

@EnricoVogt EnricoVogt commented Mar 29, 2019

fix(schematics): avoid lastIndexOf error while creating store schematics (#1659)

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Closes #1659

What is the new behavior?

Now its possible to create a store schematic without a name if its called with the "--root" flag, otherwise a name is necessary.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

@ngrxbot
Copy link
Collaborator

ngrxbot commented Mar 29, 2019

Preview docs changes for 3d06428 at https://previews.ngrx.io/pr1666-3d06428/

@King-i
Copy link
Contributor

King-i commented Mar 29, 2019

My 2 cents is if name is a required parameter then it may be better for it to be specified in schema.json under required which will prevent a user being able to run the schematic as stated in the schematics specifications, checking if the value was provided but having it declared as a required type in schema.ts defeats the purpose of the type system and the configuration via schema, if unit tests are required to confirm that schema.json matches schema.ts then that can be done via a AST read and compare?

@EnricoVogt
Copy link
Contributor Author

EnricoVogt commented Mar 30, 2019

I think the name parameter should not be required. If you create a rootstate (--root) the name is definitely not used. For my part i wont write something that is not necessary.

I have an open mind for other solutions.
I will wait for a advice how to solve it.

@brandonroberts
@timdeschryver

@King-i
Copy link
Contributor

King-i commented Mar 30, 2019

If that's the case then no it shouldn't be set as required, however the definition says its required, so therefore the schema interface needs to be updated to have name set as optional, which may have caught this bug in the original unit tests in the first place. Also parseName is a utility function used in multiple projects, changing the signature of this function to accept an empty string as default could introduce unintended consequences elsewhere?

@ngrxbot
Copy link
Collaborator

ngrxbot commented Mar 31, 2019

Preview docs changes for 1f251ad at https://previews.ngrx.io/pr1666-1f251ad/

name: undefined,
};

expect(function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(function() {
expect(() => {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

} catch (err) {
thrownError = err;
}
expect(thrownError).toBeDefined();
Copy link
Member

@timdeschryver timdeschryver Apr 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(thrownError).toBeDefined();
expect(() => {
schematicRunner.runSchematic('store', options, appTree);
}).toThrowError('Please provide a name for the feature state');

Also, remove the try catch

Copy link
Contributor Author

@EnricoVogt EnricoVogt Apr 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this for my test now. There is another test "should fail if specified module does not exist" which use also the try catch - should i change this too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in the PR, you can open up a new PR if you would like to

@ngrxbot
Copy link
Collaborator

ngrxbot commented Apr 1, 2019

Preview docs changes for 1a70cc3 at https://previews.ngrx.io/pr1666-1a70cc3/

Copy link
Member

@timdeschryver timdeschryver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@brandonroberts brandonroberts merged commit 3b9b890 into ngrx:master Apr 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Schematics-Store: lastIndexOf
5 participants