This repository has been 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
async
task which is notzone aware
,AsyncTestZoneSpec
will not handle it. such as,this case will fail because
jsonp
is not azone aware
async operation, so finished will be still be false, whenAsyncTestZone
think allmicroTasks
andmacroTasks
have been done (but jsonp is still running).We can't handle all
non zone aware
async task, so when such kind of issue occurs, we can help user useZone.prototype.scheduleMicroTask
orZone.prototype.scheduleMacroTask
to handle them.But some case is much more confusing the user with
promise
, such as,now even with the
promise
andpromise.then
, the case still failed. Becausejsonp
is notzone aware
.new Promise((res, rej) => jsonp(...))
will not trigger anyasync
operation (promise itself it notasync
).promise.then
is also notasync
until thepromise
is resolved.But the asyncTestZone will think all
async
finished (in this case, no async happened) beforepromise.then
is invoked and schedule a microTask. So the test case will still fail.We can still handle this issue by make those
non zone aware
task 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.js
may 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
schedule
a microTask, I will decrease the number, and whenAsyncTestZoneSpec
check whether should callfinish or not
not only checkhasPendingMicroTask/MacoTask
but also check is there anypromise.then
waiting fornon zone aware
promise.@mhevery , could you take a look about this idea is ok or not? thank you!