-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Fix ngMock window.inject() error stack trace reporting on repeated or non-initial injection function calls for the master branch (issue #13594) #13598
base: master
Are you sure you want to change the base?
Conversation
2009aa0
to
4e5b9d7
Compare
Hi, I took a quick look at your PRs. Looking good so far. However, with all these commits it's hard to see what exactly belongs together What I would like to see is one commit per fix - that means the commit includes the fix, the tests and any refactorings. If you can create a new PR for the master branch with these changes, that would be great. |
Pull request #13593, that this one is based on, has only two commits: So that one should be reviewed & merged first. What is left for this pull request are:
Now, if you really feel that would help in some way, we can easily just squash it all together into:
though you can see the effects of all of these squashed together easily on the In the end - it is just one fix per pull request as it is now. |
I've taken another look at this. Sorry for the slow turnaround. The problem in #13593 I understand, but for these changes I can't really see the real world scenario where it would happen that you have multiple calls to inject() inside a single spec ( usually the spec wraps a single |
This pull request does not really introduce anything new into angular code. It only corrects handling that is already there (one line change removing too early clean-up) and adds missing tests for it. 😄 Here are a couple of scenarios in which I often see multiple Scenario 1As a project's test suite grows, I find that it is often the case where some test utility functions get created. And some of them make use of specific angular-based services that they need to Scenario 2One test code organization patterns I've often encountered (and which is actually real close to the example given in angular docs here) is this:
But really, even without considering such scenarios, the behaviour as implemented right now is inconsistent and seems to say - doing this is allowed, but it is not allowed, or rather, you can do it, and it will most likely work, but possibly won't do exactly what you'd expect, and we don't define or document what will happen. 😄 Saying I don't want to test using As for the tests in this pull request, they have intentionally been prepared so they are each self-contained in a single |
The second scenario makes perfect sense. I just had a hard time visualizing the setup from the abstract tests. While trying to recreate the scenario, I've come across another issue. In the following plnkr, I have the example setup you provided: two specs, one inject in a beforeEach and another one in the second spec. Both inject the same service that is throwing on a fn that is called inside the spec. However, in the first spec, we don't get the inject part in the stacktrace (so no inject location is provided), but in the second spec we have it. From what I understand we should have the inject stack trace in both cases. Do you agree? I have included your fix in the plnkr, so this is an issue that happens with your fix too. |
Busy atm, but certainly curious and will take a look. If you like we can sync up over Skype (my login there is |
@jurko-gospodnetic Sry, I didn't have time on the weekend, but we can sync on the coming weekend if you want |
Cool, just contact me over Skype when you're online. 👍 |
3d8060f
to
0739ee3
Compare
Split up `ngMock` `window.inject` tests into tests on browsers supporting fetching current stack trace information and those not supporting it, as we plan on adding new test specs to the first group. Required making the test inject caller function more flexible so it can be easily configured in different tests without unnecessary code duplication.
…ment The results of this function, when called outside of a specific test spec context, should not be reused in multiple tests as they may have stored state that can cause unwanted test spec interaction. This explains why we may need to wrap some tests into their own separate test suites instead of grouping them all under a single shared one.
…apper usage Explicitly commented on why we use an extra function wrapper around the test inject Error throwing code, and how not using it would make our tests give us false positives on certain browsers, e.g. Firefox.
…vocations Failed injection functions should consistently include their respective window.inject() call location information in their stack trace, even on repeated invocations & when they have been passed as a non-initial parameter to their window.inject() call.
…alls Injection function throwing an Error should update the thrown Error's stack trace information with the window.inject() call location information, on its initial as well as repeated invocations.
… functions Injection function throwing an Error should update the thrown Error's stack trace information with the window.inject() call location information even when multiple injection functions are passed to the window.inject() call and non-initial provided function fails. Closes angular#13594.
0739ee3
to
3a09c6d
Compare
@Narretz I took a look at that plunkr you left a link to, and I don't really see anything wrong with the behaviour shown.
Nope. The behaviour seems correct. The first spec does not fail inside any service injection function, while the second one does. Also, the behaviour presented in that plunkr does not really have anything to do with the changes done in this pull request as neither do any of the failing/throwing service injection functions get called multiple times nor do any of the There are actually two
and here is a more detailed description of what happens when each of our failing test specs get run:
To see the difference with or without the patch applied, you might want to replace the second test case with something like this:
Which, without the patch applied, should make:
while with the patch applied, both should correctly display the |
Fixes & adds tests for issue #13594 for the angular
master
branch.Does the same work as pull request #13597 does on the angular
1.4.x
branch.window.inject()
function updates stack trace information forError
objects thrown from injection functions passed to it with stack trace for thewindow.inject()
calling location. However this functionality was broken and did not work correctly in the following cases:window.inject()
call and a non-initial one throws anError
This pull request actually builds on and thus includes pull request #13593, as newly added test specs are integrated into the test structure set up by the base pull request. That's why you should first review & merge that pull request, or ignore its commits when reviewing this one.