From d9ea9754d664769cf21f3e71f56a1956d68546c4 Mon Sep 17 00:00:00 2001 From: Israel Menis Date: Tue, 23 Oct 2018 19:18:29 +0200 Subject: [PATCH] Fixing some JSONP tests replacing /test/data/jsonp.php and /test/data/jsonpfancyapi.php by NodeJS approach in server.js --- server.js | 24 ++++++++++++++++++++++++ test/popcorn.unit.js | 10 +++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/server.js b/server.js index ac1affd9c..7b4cee2a6 100644 --- a/server.js +++ b/server.js @@ -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); \ No newline at end of file diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index bf3a0ac37..a90f2b00c 100644 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -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 ) { @@ -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" ); @@ -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(); @@ -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" ); @@ -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" );