Skip to content

Conversation

@mgol
Copy link
Member

@mgol mgol commented Jul 22, 2020

return expectNoWarning( assert, "dataType: \"json\"",
function() {
return jQuery.ajax( {
url: url( "data/null.json" ),
Copy link
Member Author

Choose a reason for hiding this comment

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

This file just contains null which is both valid JSON & JS. Quite handy!

Comment on lines +104 to +119
// Invoke tests sequentially as they're async and early tests could get warnings
// from later ones.
function run( tests ) {
var test = tests[ 0 ];
return test().then( function() {
if ( tests.length > 1 ) {
return run( tests.slice( 1 ) );
}
} );
} );
}

run( tests )
.then( function() {
done();
} );
} );
Copy link
Member Author

Choose a reason for hiding this comment

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

This is quite a lot of boilerplate but we don't have that many tests so I'm not sure if this is the moment to generalize it... If there's a way to simplify, I'm all ears. :)

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with it, if it really gets out of hand we can refactor some other time.

<script src="testinit.js"></script>
<script>
TestManager.loadProject( "jquery", "git" );
TestManager.loadProject( "jquery", "3.x-git" );
Copy link
Member Author

Choose a reason for hiding this comment

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

I can separate these changes if you want.

// Register this prefilter before the jQuery one. Otherwise, a promoted
// request is transformed into one with the script dataType and we can't
// catch it anymore.
jQuery.ajaxPrefilter( "+json", function( s ) {
Copy link
Member Author

Choose a reason for hiding this comment

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

The special + handling is not documented at https://api.jquery.com/jQuery.ajaxPrefilter/, I found it by reading source. 🙈

Comment on lines +104 to +119
// Invoke tests sequentially as they're async and early tests could get warnings
// from later ones.
function run( tests ) {
var test = tests[ 0 ];
return test().then( function() {
if ( tests.length > 1 ) {
return run( tests.slice( 1 ) );
}
} );
} );
}

run( tests )
.then( function() {
done();
} );
} );
Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with it, if it really gets out of hand we can refactor some other time.

test/migrate.js Outdated
}

if ( result && result.then ) {
return jQuery.when(
Copy link
Member Author

Choose a reason for hiding this comment

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

Note to self - jQuery.when is unavailable in jQuery 4.x Slim. Perhaps it's better to use a Promise polyfill like native-promise-only that we already use in Core tests.

@mgol
Copy link
Member Author

mgol commented Aug 25, 2020

@dmethvin I added one commit switching jQuery.when to Promise.resolve using a Promise polyfill. This works with the Core 4.x slim build. Let me know if this is still good to land.

Copy link
Member

@dmethvin dmethvin left a comment

Choose a reason for hiding this comment

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

Seems like the easiest way to make this work in slim, LGTM.

@mgol mgol merged commit e9a11f7 into jquery:master Aug 31, 2020
@mgol mgol deleted the json-to-jsonp branch August 31, 2020 22:03
mgol added a commit to mgol/jquery-migrate that referenced this pull request Dec 2, 2021
mgol added a commit that referenced this pull request Dec 30, 2021
The warning landed in gh-376 but I forgot to document it.

Fixes gh-443
Closes gh-447
Ref gh-376

Co-authored-by: Dave Methvin <[email protected]>
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.

Detect and warn about Ajax JSON requests promoted to JSONP

3 participants