Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixing some JSONP tests replacing /test/data/jsonp.php and
/test/data/jsonpfancyapi.php by NodeJS approach in server.js
  • Loading branch information
Israel Menis committed Oct 23, 2018
1 parent a26c9fe commit d9ea975
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
24 changes: 24 additions & 0 deletions server.js
Expand Up @@ -23,4 +23,28 @@ app.post('/test/method', function (req, res) {
res.send('{ "method": "post" }');
});

/*
* Get method for testing purposes.
*
* It replaces old /test/data/jsonp.php
*/
app.get('/test/jsonp', function (req, res) {
res.send(req.query.callback + '({ "data": {"lang": "en", "length": 25} });');
});

/*
* Get method for testing purposes.
*
* It replaces old /test/data/jsonpfancyapi.php
*/
app.get('/test/jsonpfancyapi', function (req, res) {
var callback = req.questy.callback;

if (!callback) {
res.send('Invalid Parameter');
} else {
res.send(callback + '({ "data": {"lang": "en", "length": 25} });');
}
});

app.listen(port);
10 changes: 5 additions & 5 deletions test/popcorn.unit.js
Expand Up @@ -5617,7 +5617,7 @@ if ( !/file/.test( location.protocol ) ) {

Popcorn.xhr({

url: "data/jsonp.php?callback=jsonp",
url: "jsonp?callback=jsonp",
dataType: "jsonp",
success: function( data ) {

Expand All @@ -5639,7 +5639,7 @@ if ( !/file/.test( location.protocol ) ) {

Popcorn.xhr.getJSONP(

"data/jsonp.php?callback=?",
"jsonp?callback=?",
function( data ) {

ok( data, "getJSONP returns data" );
Expand All @@ -5651,7 +5651,7 @@ if ( !/file/.test( location.protocol ) ) {

asyncTest( "JSONP xhr.getJSONP, strictly enforced parameter with callback placeholder", 1, function() {
Popcorn.xhr.getJSONP(
"data/jsonpfancyapi.php?jsonpfancyapi=?",
"jsonpfancyapi?jsonpfancyapi=?",
function( data ) {
ok( data, "getJSONP with placeholder callback name returns data" );
start();
Expand Down Expand Up @@ -5683,7 +5683,7 @@ if ( !/file/.test( location.protocol ) ) {

Popcorn.getJSONP(

"data/jsonp.php?callback=jsonp",
"jsonp?callback=jsonp",
function( data ) {

ok( data, "getJSONP returns data" );
Expand All @@ -5704,7 +5704,7 @@ if ( !/file/.test( location.protocol ) ) {

Popcorn.getJSONP(

"data/jsonp.php?nonsense=no?sense",
"jsonp?nonsense=no?sense",
function( data ) {

ok( data, "getJSONP returns data" );
Expand Down

0 comments on commit d9ea975

Please sign in to comment.