Commit 2a499e62 authored by Romain Courteaud's avatar Romain Courteaud

Fix sinon fake server usage.

parent e571f2f6
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
* *
* @author Gustavo Machado (@machadogj), Jose Romaniello (@jfroma) * @author Gustavo Machado (@machadogj), Jose Romaniello (@jfroma)
* Modified version of sinon-qunit from Christian Johansen * Modified version of sinon-qunit from Christian Johansen
* Modified version of sinon-qunit from Romain Courteaud
* *
* (The BSD License) * (The BSD License)
* *
...@@ -46,24 +45,11 @@ sinon.config = { ...@@ -46,24 +45,11 @@ sinon.config = {
injectIntoThis: true, injectIntoThis: true,
injectInto: null, injectInto: null,
properties: ["spy", "stub", "mock", "clock", "sandbox"], properties: ["spy", "stub", "mock", "clock", "sandbox"],
// useFakeTimers: true,
// useFakeServer: false
useFakeTimers: false, useFakeTimers: false,
useFakeServer: true useFakeServer: true
}; };
(function (global) { (function (global) {
var qTest = QUnit.test;
QUnit.test = global.test = function (testName, expected, callback, async) {
if (arguments.length === 2) {
callback = expected;
expected = null;
}
return qTest(testName, expected, sinon.test(callback), async);
};
var qModule = QUnit.module; var qModule = QUnit.module;
var setup = function () { var setup = function () {
......
/*global window, document, QUnit, jQuery, renderJS, RenderJSGadget */ /*global window, document, QUnit, jQuery, renderJS, RenderJSGadget, sinon */
/*jslint indent: 2, maxerr: 3, maxlen: 79 */ /*jslint indent: 2, maxerr: 3, maxlen: 79 */
"use strict"; "use strict";
(function (document, $, renderJS, QUnit) { (function (document, $, renderJS, QUnit, sinon) {
var test = QUnit.test, var test = QUnit.test,
stop = QUnit.stop, stop = QUnit.stop,
start = QUnit.start, start = QUnit.start,
...@@ -285,7 +285,7 @@ ...@@ -285,7 +285,7 @@
}); });
test('Ajax error reject the promise', function () { test('Ajax error reject the promise', function () {
// Check that declareGadgetKlass fails if ajax fails // Check that declareGadgetKlass fails if ajax fails
var server = this.sandbox.useFakeServer(), var server = sinon.fakeServer.create(),
url = 'https://example.org/files/qunittest/test'; url = 'https://example.org/files/qunittest/test';
server.respondWith("GET", url, [404, { server.respondWith("GET", url, [404, {
...@@ -308,7 +308,7 @@ ...@@ -308,7 +308,7 @@
test('Non HTML reject the promise', function () { test('Non HTML reject the promise', function () {
// Check that declareGadgetKlass fails if non html is retrieved // Check that declareGadgetKlass fails if non html is retrieved
var server = this.sandbox.useFakeServer(), var server = sinon.fakeServer.create(),
url = 'https://example.org/files/qunittest/test'; url = 'https://example.org/files/qunittest/test';
server.respondWith("GET", url, [200, { server.respondWith("GET", url, [200, {
...@@ -333,7 +333,7 @@ ...@@ -333,7 +333,7 @@
test('HTML parsing failure reject the promise', function () { test('HTML parsing failure reject the promise', function () {
// Check that declareGadgetKlass fails if the html can not be parsed // Check that declareGadgetKlass fails if the html can not be parsed
var server = this.sandbox.useFakeServer(), var server = sinon.fakeServer.create(),
url = 'https://example.org/files/qunittest/test', url = 'https://example.org/files/qunittest/test',
mock; mock;
...@@ -365,7 +365,7 @@ ...@@ -365,7 +365,7 @@
test('Klass creation', function () { test('Klass creation', function () {
// Check that declareGadgetKlass returns a subclass of RenderJSGadget // Check that declareGadgetKlass returns a subclass of RenderJSGadget
// and contains all extracted properties on the prototype // and contains all extracted properties on the prototype
var server = this.sandbox.useFakeServer(), var server = sinon.fakeServer.create(),
url = 'https://example.org/files/qunittest/test', url = 'https://example.org/files/qunittest/test',
mock; mock;
...@@ -404,7 +404,7 @@ ...@@ -404,7 +404,7 @@
test('Klass is not reloaded if called twice', function () { test('Klass is not reloaded if called twice', function () {
// Check that declareGadgetKlass does not reload the gadget // Check that declareGadgetKlass does not reload the gadget
// if it has already been loaded // if it has already been loaded
var server = this.sandbox.useFakeServer(), var server = sinon.fakeServer.create(),
url = 'https://example.org/files/qunittest/test', url = 'https://example.org/files/qunittest/test',
mock; mock;
...@@ -714,7 +714,7 @@ ...@@ -714,7 +714,7 @@
test('clearGadgetKlassList leads to gadget reload', function () { test('clearGadgetKlassList leads to gadget reload', function () {
// Check that declareGadgetKlass reload the gadget // Check that declareGadgetKlass reload the gadget
// after clearGadgetKlassList is called // after clearGadgetKlassList is called
var server = this.sandbox.useFakeServer(), var server = sinon.fakeServer.create(),
url = 'https://example.org/files/qunittest/test', url = 'https://example.org/files/qunittest/test',
mock; mock;
...@@ -1199,7 +1199,7 @@ ...@@ -1199,7 +1199,7 @@
test('returns a Promise', function () { test('returns a Promise', function () {
// Check that declareGadget return a Promise // Check that declareGadget return a Promise
var gadget = new RenderJSGadget(), var gadget = new RenderJSGadget(),
server = this.sandbox.useFakeServer(), server = sinon.fakeServer.create(),
url = 'https://example.org/files/qunittest/test', url = 'https://example.org/files/qunittest/test',
html = "<html>" + html = "<html>" +
"<body>" + "<body>" +
...@@ -1223,7 +1223,7 @@ ...@@ -1223,7 +1223,7 @@
test('provide a gadget instance as callback parameter', function () { test('provide a gadget instance as callback parameter', function () {
// Check that declare gadget returns the gadget // Check that declare gadget returns the gadget
var gadget = new RenderJSGadget(), var gadget = new RenderJSGadget(),
server = this.sandbox.useFakeServer(), server = sinon.fakeServer.create(),
url = 'https://example.org/files/qunittest/test', url = 'https://example.org/files/qunittest/test',
html = "<html>" + html = "<html>" +
"<body>" + "<body>" +
...@@ -1262,13 +1262,16 @@ ...@@ -1262,13 +1262,16 @@
test('load dependency before returning gadget', function () { test('load dependency before returning gadget', function () {
// Check that dependencies are loaded before gadget creation // Check that dependencies are loaded before gadget creation
var gadget = new RenderJSGadget(), var gadget = new RenderJSGadget(),
server = this.sandbox.useFakeServer(), server = sinon.fakeServer.create(),
html_url = 'https://example.org/files/qunittest/test2.html', html_url = 'https://example.org/files/qunittest/test2.html',
js1_url = "data:application/javascript;base64," + js1_url = "data:application/javascript;base64," +
window.btoa( window.btoa(
"$('#qunit-fixture').find('div').first().text('youhou');" "$('#qunit-fixture').find('div').first().text('youhou');"
), ),
js2_url = js1_url, js2_url = "data:application/javascript;base64," +
window.btoa(
"$('#qunit-fixture').find('div').first().text('youhou2');"
),
css1_url = "data:text/plain;base64," + css1_url = "data:text/plain;base64," +
window.btoa(""), window.btoa(""),
css2_url = css1_url, css2_url = css1_url,
...@@ -1303,7 +1306,7 @@ ...@@ -1303,7 +1306,7 @@
gadget.declareGadget(html_url, $('#qunit-fixture').find("div").last()) gadget.declareGadget(html_url, $('#qunit-fixture').find("div").last())
.done(function (new_gadget) { .done(function (new_gadget) {
equal($('#qunit-fixture').html(), equal($('#qunit-fixture').html(),
"<div>youhou</div><div><p>Bar content</p></div>"); "<div>youhou2</div><div><p>Bar content</p></div>");
ok(spy_js.calledTwice, "JS count " + spy_js.callCount); ok(spy_js.calledTwice, "JS count " + spy_js.callCount);
equal(spy_js.firstCall.args[0], js1_url, "First JS call"); equal(spy_js.firstCall.args[0], js1_url, "First JS call");
equal(spy_js.secondCall.args[0], js2_url, "Second JS call"); equal(spy_js.secondCall.args[0], js2_url, "Second JS call");
...@@ -1323,7 +1326,7 @@ ...@@ -1323,7 +1326,7 @@
test('Fail if klass can not be loaded', function () { test('Fail if klass can not be loaded', function () {
// Check that gadget is not created if klass is can not be loaded // Check that gadget is not created if klass is can not be loaded
var gadget = new RenderJSGadget(), var gadget = new RenderJSGadget(),
server = this.sandbox.useFakeServer(), server = sinon.fakeServer.create(),
html_url = 'https://example.org/files/qunittest/test3.html'; html_url = 'https://example.org/files/qunittest/test3.html';
server.respondWith("GET", html_url, [404, { server.respondWith("GET", html_url, [404, {
...@@ -1347,7 +1350,7 @@ ...@@ -1347,7 +1350,7 @@
test('Fail if js can not be loaded', function () { test('Fail if js can not be loaded', function () {
// Check that dependencies are loaded before gadget creation // Check that dependencies are loaded before gadget creation
var gadget = new RenderJSGadget(), var gadget = new RenderJSGadget(),
server = this.sandbox.useFakeServer(), server = sinon.fakeServer.create(),
html_url = 'https://example.org/files/qunittest/test2.html', html_url = 'https://example.org/files/qunittest/test2.html',
js1_url = 'foo://bar2', js1_url = 'foo://bar2',
mock; mock;
...@@ -1379,7 +1382,7 @@ ...@@ -1379,7 +1382,7 @@
test('Do not load gadget dependency twice', function () { test('Do not load gadget dependency twice', function () {
// Check that dependencies are not reloaded if 2 gadgets are created // Check that dependencies are not reloaded if 2 gadgets are created
var gadget = new RenderJSGadget(), var gadget = new RenderJSGadget(),
server = this.sandbox.useFakeServer(), server = sinon.fakeServer.create(),
html_url = 'https://example.org/files/qunittest/test2.html', html_url = 'https://example.org/files/qunittest/test2.html',
js1_url = "data:application/javascript;base64," + js1_url = "data:application/javascript;base64," +
window.btoa( window.btoa(
...@@ -1430,7 +1433,7 @@ ...@@ -1430,7 +1433,7 @@
test('Load 2 concurrent gadgets in parallel', function () { test('Load 2 concurrent gadgets in parallel', function () {
// Check that dependencies are loaded once if 2 gadgets are created // Check that dependencies are loaded once if 2 gadgets are created
var gadget = new RenderJSGadget(), var gadget = new RenderJSGadget(),
server = this.sandbox.useFakeServer(), server = sinon.fakeServer.create(),
html_url = 'https://example.org/files/qunittest/test2.html', html_url = 'https://example.org/files/qunittest/test2.html',
mock, mock,
spy; spy;
...@@ -1457,4 +1460,4 @@ ...@@ -1457,4 +1460,4 @@
server.respond(); server.respond();
}); });
}(document, jQuery, renderJS, QUnit)); }(document, jQuery, renderJS, QUnit, sinon));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment