Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7b0864d

Browse files
authored
Tests: Fix flakiness in the "jQuery.ajax() - JSONP - Same Domain" test
The "jQuery.ajax() - JSONP - Same Domain" test is firing a request witha duplicate "callback" parameter, something like (simplified):```mock.php?action=jsonp&callback=jQuery_1&callback=jQuery_2```There was a difference in how the PHP & Node.js implementations of the jsonpaction in the mock server handled situations like that. The PHP implementationwas using the latest parameter while the Node.js one was turning it into anarray but the code didn't handle this situation. Because of how JavaScriptstringifies arrays, while the PHP implementation injected the following code:```jsjQuery_2(payload)```the Node.js one was injecting the following one:```jsjQuery_1,jQuery_2(payload)```This is a comma expression in JavaScript; it so turned out that in the majorityof cases both callbacks were identical so it was more like:```jsjQuery_1,jQuery_1(payload)```which evaluates to `jQuery_1(payload)` when `jQuery_1` is defined, making thetest go as expected. In many cases, though, especially on Travis, the callbackswere 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 handlingfor arrays.Closesgh-4687
1 parenta62309e commit7b0864d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

‎test/middleware-mockserver.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ var mocks = {
9393
},
9494
jsonp:function(req,resp,next){
9595
varcallback;
96-
if(req.query.callback){
96+
if(Array.isArray(req.query.callback)){
97+
callback=Promise.resolve(req.query.callback[req.query.callback.length-1]);
98+
}elseif(req.query.callback){
9799
callback=Promise.resolve(req.query.callback);
98100
}elseif(req.method==="GET"){
99101
callback=Promise.resolve(req.url.match(/^.+\/([^\/?.]+)\?.+$/)[1]);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp