This repository was archived by the owner on Feb 26, 2024. It is now read-only.
feat(test): can handle non zone aware task in promise within AsyncTestZoneSpec #1014
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.
fix #1013.
currently if there are some
asynctask which is notzone aware,AsyncTestZoneSpecwill not handle it. such as,this case will fail because
jsonpis not azone awareasync operation, so finished will be still be false, whenAsyncTestZonethink allmicroTasksandmacroTaskshave been done (but jsonp is still running).We can't handle all
non zone awareasync task, so when such kind of issue occurs, we can help user useZone.prototype.scheduleMicroTaskorZone.prototype.scheduleMacroTaskto handle them.But some case is much more confusing the user with
promise, such as,now even with the
promiseandpromise.then, the case still failed. Becausejsonpis notzone aware.new Promise((res, rej) => jsonp(...))will not trigger anyasyncoperation (promise itself it notasync).promise.thenis also notasyncuntil thepromiseis resolved.But the asyncTestZone will think all
asyncfinished (in this case, no async happened) beforepromise.thenis invoked and schedule a microTask. So the test case will still fail.We can still handle this issue by make those
non zone awaretask tozone aware, but it will cost time, and in most case, user callpromise.then, they believe promise will be resolved or rejected, so I thinkzone.jsmay handle it more friendly.in this PR, if there is such case.
I will increase a chainedPromise number in AsyncTestZoneSpec. And when the chainedPromise's parent resolved and
schedulea microTask, I will decrease the number, and whenAsyncTestZoneSpeccheck whether should callfinish or notnot only checkhasPendingMicroTask/MacoTaskbut also check is there anypromise.thenwaiting fornon zone awarepromise.@mhevery , could you take a look about this idea is ok or not? thank you!