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

test(ivy): add exhaustive inheritance tests #30442

Closed
wants to merge 4 commits into from

Conversation

benlesh
Copy link
Contributor

@benlesh benlesh commented May 13, 2019

  • Adds inheritance tests for many combinations of directive, component and bare class inheritance
  • Adds tests that are failing in ivy, but should work, marks them with xit and a TODO.
  • Removes render3 unit tests that cover the same things.

NOTE: There is a JIRA ticket filed for the tests marked with xit: https://angular-team.atlassian.net/browse/FW-1324

@benlesh benlesh added refactoring Issue that involves refactoring or code-cleanup target: major This PR is targeted for the next major release comp: ivy risk: low labels May 13, 2019
@benlesh benlesh requested a review from a team as a code owner May 13, 2019 22:05
@ngbot ngbot bot modified the milestone: needsTriage May 13, 2019
@benlesh benlesh added action: merge The PR is ready for merge by the caretaker and removed state: WIP labels May 13, 2019
@ngbot
Copy link

ngbot bot commented May 14, 2019

I see that you just added the PR action: merge label, but the following checks are still failing:
    failure status "angular" is failing

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken master, please try rebasing to master and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

Copy link
Member

@pkozlowski-opensource pkozlowski-opensource left a comment

Choose a reason for hiding this comment

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

@benlesh
Copy link
Contributor Author

benlesh commented May 14, 2019

@pkozlowski-opensource sorry, that link isn't working for me for some reason. What's the review?

@alxhub alxhub added the action: review The PR is still awaiting reviews from at least one requested reviewer label May 14, 2019
- Adds inheritance tests for many combinations of directive, component and bare class inheritance
- Adds tests that are failing in ivy, but should work, marks them with `xit` and a TODO.
- Removes render3 unit tests that cover the same things.
@benlesh benlesh added merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels May 15, 2019
@benlesh
Copy link
Contributor Author

benlesh commented May 15, 2019

Caretaker: @pkozlowski-opensource's concerns were addressed, and @mhevery is a global approver.

}

TestBed.configureTestingModule({declarations: [AppComp, SubDirective]});
TestBed.overrideComponent(

Choose a reason for hiding this comment

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

nit: would be probably shorter / more obvious to write as TestBed.overrideTemplate(AppComp, '<div subDir [someInput]="1"></div>')?

Applies to this line and all the other places below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am actually really against that sort of test writing. Tests should repeat themselves as much as possible, and have everything explicitly and concisely defined within the test block. Dry tests invite mistakes where another developer comes along and changes the shared testing functionality and could potentially break other tests in such a way that they still pass but are no longer valid. I was honestly uneasy even writing the lifecycle hooks inheritance tests the way I did.

Explicit, inline code, while verbose, is by its very nature more readable than code relying on code that exists many lines away and/or relies on underlying magic.

Copy link
Contributor

Choose a reason for hiding this comment

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

I gotta say I'm with Pawel on this one. I don't think adding the new Component invocation actually makes things clearer. I think it's confusing and doesn't actually align with how people write tests in the wild.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed offline: There was some confusion here. :)

The tests above were pre-existing and the diff made it look like I added new ones. I was confused about what was being asked, and everyone else was probably equally confused by my response. Here is a PR that is attempting to address that issue: #30522

const fixture = TestBed.createComponent(AppComp);
fixture.detectChanges();

expect(log).toEqual(['on changes!']);

Choose a reason for hiding this comment

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

nit: as a sanity check I would have a separate test that asserts that:

  • nothing is logged when there is no ngOnChanges() (otherwise all the tests can be made passing but pushing initial 'on changes!' to the mock log that you are using;
  • ngOnChanges() gets invoked when input changes.

One such test would be more than enough. Sorry for being pedantic but I like to have those sanity checks in place to make sure that we are not missing any obvious things.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't write these tests. They were simply moved by reformatting. It's probably worth noting the desired changes, and we can add them in a followup PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add a TODO for this?

});
});

it('should inherit inputs', () => {
Copy link
Member

Choose a reason for hiding this comment

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

sounds like it should be a separate describe as we are "switching" from lifecycle hooks to inputs / outputs

Choose a reason for hiding this comment

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

would be great to add more sanity tests for inputs with the same name present in super and sub classes and with different:

  • type
  • alias

In those cases we've got a clear collision and we should be resolving somehow but I'm not sure what VE / ivy is doing atm. Same applies to outputs.

Could you please add tests for those cases (I'm not sure we need them for all the inheritance cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that we should add more tests. Can we do this in a follow up PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODOs added in #30522


it('should compose host bindings (non-style related)', () => {
class SuperDirective {
@HostBinding('title')

Choose a reason for hiding this comment

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

I haven't seen any test for host expressed as host: {...} . Also can't find any tests for "host listener". Could you please add those? Again, I don't think we need those tests for each and every inheritance case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it sounds important, but I'd like to add these in a follow up PR. Unfortunately, we'd probably want to add them for each inheritance case to be thorough.

@pkozlowski-opensource
Copy link
Member

@benlesh good efforts on tests here. I've left some comments but generally speaking I think that we've got 2 axis to cover here:

  • various inheritance combinations;
  • various inherited features.

From what I can see this PR is "various inheritance combinations" reach but a bit light on "various inherited features". Personally I would prefer to see more comprehensive tests for a single feature (I left notes for cases that were coming to my mind when I was going through the code) and then just sanity checks for various inheritance combinations. Otherwise I I feel like we are repeating same tests over and over again without going too deep into any particular area. I'm saying this since if I recall that @alxhub discovered several places where ivy and VE differ and I don't see this reflected in your tests.

Anyway, good tests here, but I think that we can improve by going deeper and scale back on duplication for each various inheritance combinations. WDYT?

@benlesh
Copy link
Contributor Author

benlesh commented May 16, 2019

@pkozlowski-opensource I agree that there are a lot more tests to add. This PR was just an improvement over the very small number of render3 tests we had, and was already a little out of scope to the point where I was a bit concerned I was taking time away from other important team goals.

We should probably catalog the ideas you have here for more tests and circle back to them in a separate PR. We definitely still have some dark spaces.

Copy link
Member

@pkozlowski-opensource pkozlowski-opensource left a comment

Choose a reason for hiding this comment

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

@pkozlowski-opensource I agree that there are a lot more tests to add. This PR was just an improvement over the very small number of render3 tests we had, and was already a little out of scope to the point where I was a bit concerned I was taking time away from other important team goals.
We should probably catalog the ideas you have here for more tests and circle back to them in a separate PR. We definitely still have some dark spaces.

I'm totally cool with adding more tests in a separate PR - I was enumerating all those case while reading code assuming that you are after exhaustive coverage. Also my comments about describe were assuming that you are going to add more tests.

LGTM as this PR clearly improves things but could you please create a JIRA issue with missing tests?

@jasonaden jasonaden closed this in 3f7e823 May 16, 2019
Copy link
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

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

@benlesh Can you do these in a follow-up PR? I wasn't done reviewing.

}

TestBed.configureTestingModule({declarations: [AppComp, SubDirective]});
TestBed.overrideComponent(
Copy link
Contributor

Choose a reason for hiding this comment

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

I gotta say I'm with Pawel on this one. I don't think adding the new Component invocation actually makes things clearer. I think it's confusing and doesn't actually align with how people write tests in the wild.

const fixture = TestBed.createComponent(AppComp);
fixture.detectChanges();

expect(log).toEqual(['on changes!']);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add a TODO for this?

@benlesh
Copy link
Contributor Author

benlesh commented May 16, 2019

Follow up PR is here #30522

BioPhoton pushed a commit to BioPhoton/angular that referenced this pull request May 21, 2019
- Adds inheritance tests for many combinations of directive, component and bare class inheritance
- Adds tests that are failing in ivy, but should work, marks them with `xit` and a TODO.
- Removes render3 unit tests that cover the same things.

PR Close angular#30442
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note refactoring Issue that involves refactoring or code-cleanup risk: low target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants