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 respond() & readystatechange process flow #184

Merged

Conversation

codejedi365
Copy link
Contributor

Purpose

Fix the process flow where a readystatechange event should not be triggered after loadend event. When it does, it is incompatible with some network lib(like natty-fetch) stated in issue #165.

I found that the code was using fall through logic which caused the extra readystatechange event to be thrown after the loadend event inside of the readyStateChange() function. There was logic added to delineate from a finished XHR request and throw the loadend but not to stop processing the fall through logic. I added a return statement to prevent the drop through but note that a readystatechange did have to be added prior to the loadend otherwise some requests would not resolve and it was noticeable through other unit-tests.

I added 1 unit test to replicate the issue results.

Resolves: #165

How to verify

  1. Check out this branch
  2. Run npm install
  3. Revert fake-xhr library before bug fixes. git reset --hard HEAD~1
  4. Run npm test. This branch includes 1 new unit test to accompany the error so during this test run 1 of the tests will fail.
  5. Review & validate the test cases written to understand what scenarios are fixed & see writeup in issue.
  6. Checkout this branch again to pull in bug fixes. git pull
  7. Run npm test again. All tests will pass verifying there was no regression and the buggy scenarios were fixed.

\### Rationale
Added issue replication test for issue sinonjs#165 where readystatechange
event is occuring after loadend event occurs.
\### Rationale
The code was using fall through logic which caused the extra
readystatechange event to be thrown after the loadend event.  The logic
was there to delinate from a finished XHR request and throw the loadend
but not to stop processing. Note that a readystatechange did have to be
added prior to the loadend otherwise some requests would not resolve
and it was noticeable through other unit-tests. This commit has all
passing tests to include the one designed to replicate the issue of

Resolves sinonjs#165
@codecov
Copy link

codecov bot commented May 14, 2021

Codecov Report

Merging #184 (183eed9) into master (416866d) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #184      +/-   ##
==========================================
+ Coverage   91.29%   91.31%   +0.01%     
==========================================
  Files          13       13              
  Lines         609      610       +1     
==========================================
+ Hits          556      557       +1     
  Misses         53       53              
Flag Coverage Δ
unit 91.31% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
lib/fake-xhr/index.js 87.03% <100.00%> (+0.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 416866d...183eed9. Read the comment docs.

Copy link
Contributor

@fatso83 fatso83 left a comment

Choose a reason for hiding this comment

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

Beautiful PR, again. Just some minor quibble.

lib/fake-xhr/index.js Outdated Show resolved Hide resolved
### Rationale
Ensure logic is clear by avoiding empty return statements and
fall-through logic
@fatso83 fatso83 merged commit 70ca4ca into sinonjs:master May 21, 2021
@fatso83
Copy link
Contributor

fatso83 commented May 21, 2021

Perfect!

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.

readystatechange event should not be triggered after loadend
2 participants