Tests: Fix flakiness in the "jQuery.ajax() - JSONP - Same Domain" test #4687
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.
Summary
The "jQuery.ajax() - JSONP - Same Domain" test is firing a request with
a duplicate "callback" parameter, something like (simplified):
There was a difference in how the PHP & Node.js implementations of the jsonp
action in the mock server handled situations like that. The PHP implementation
was using the latest parameter while the Node.js one was turning it into an
array but the code didn't handle this situation. Because of how JavaScript
stringifies arrays, while the PHP implementation injected the following code:
the Node.js one was injecting the following one:
This is a comma expression in JavaScript; it so turned out that in the majority
of cases both callbacks were identical so it was more like:
which evaluates to
jQuery_1(payload)
whenjQuery_1
is defined, making thetest go as expected. In many cases, though, especially on Travis, the callbacks
were different, triggering an
Uncaught ReferenceError
error & requiringfrequent manual re-runs of Travis builds.
This commit fixes the logic in the mock Node.js server, adding special handling
for arrays.
Checklist
If needed, a docs issue/PR was created at https://github.com/jquery/api.jquery.com