Commit 50275cce authored by JC Brand's avatar JC Brand

Remove shared state between tests

Only a small subset of tests currently working with this.
parent d3090f80
This diff is collapsed.
This diff is collapsed.
...@@ -1950,6 +1950,15 @@ ...@@ -1950,6 +1950,15 @@
utils.merge(converse, settings); utils.merge(converse, settings);
utils.applyUserSettings(converse, settings, converse.user_settings); utils.applyUserSettings(converse, settings, converse.user_settings);
}; };
// If initialize gets called a second time (e.g. during tests), then we
// need to re-apply all plugins (for a new converse instance), and we
// therefore need to clear this array that prevents plugins from being
// initialized twice.
// If initialize is called for the first time, then this array is empty
// in any case.
converse.pluggable.initialized_plugins = [];
converse.pluggable.initializePlugins({ converse.pluggable.initializePlugins({
'updateSettings': updateSettings, 'updateSettings': updateSettings,
'converse': converse 'converse': converse
......
...@@ -45,36 +45,18 @@ require([ ...@@ -45,36 +45,18 @@ require([
window.localStorage.clear(); window.localStorage.clear();
window.sessionStorage.clear(); window.sessionStorage.clear();
converse.initialize({
i18n: window.locales.en,
auto_subscribe: false,
bosh_service_url: 'localhost',
connection: mock.mock_connection,
animate: false,
no_trimming: true,
auto_login: true,
jid: 'dummy@localhost',
password: 'secret',
debug: true
}).then(function (converse) {
window.converse = converse;
window.crypto = {
getRandomValues: function (buf) {
var i;
for (i=0, len=buf.length; i<len; i++) {
buf[i] = Math.floor(Math.random()*256);
}
}
};
require([ require([
"console-runner", "console-runner",
//"spec/transcripts", //"spec/transcripts",
"spec/utils", "spec/utils",
"spec/converse", "spec/converse",
/*
"spec/bookmarks", "spec/bookmarks",
"spec/headline", "spec/headline",
"spec/disco", "spec/disco",
*/
"spec/protocol", "spec/protocol",
/*
"spec/mam", "spec/mam",
"spec/otr", "spec/otr",
"spec/eventemitter", "spec/eventemitter",
...@@ -87,11 +69,8 @@ require([ ...@@ -87,11 +69,8 @@ require([
"spec/ping", "spec/ping",
"spec/register", "spec/register",
"spec/xmppstatus", "spec/xmppstatus",
*/
], function () { ], function () {
// Stub the trimChat method. It causes havoc when running with
// phantomJS.
converse.ChatBoxViews.prototype.trimChat = function () {};
// Jasmine stuff // Jasmine stuff
var jasmineEnv = jasmine.getEnv(); var jasmineEnv = jasmine.getEnv();
var reporter; var reporter;
...@@ -110,6 +89,5 @@ require([ ...@@ -110,6 +89,5 @@ require([
} }
jasmineEnv.execute(); jasmineEnv.execute();
}); });
});
} }
); );
(function (root, factory) { (function (root, factory) {
define("mock", define("mock", ['converse'], factory);
['converse'], }(this, function (converse_api) {
function(converse) { var Strophe = converse_api.env.Strophe;
return factory(converse); var $iq = converse_api.env.$iq;
});
}(this, function (converse) {
var Strophe = converse.env.Strophe;
var $iq = converse.env.$iq;
var mock = {}; var mock = {};
// Names from http://www.fakenamegenerator.com/ // Names from http://www.fakenamegenerator.com/
mock.req_names = [ mock.req_names = [
...@@ -48,6 +44,7 @@ ...@@ -48,6 +44,7 @@
}; };
mock.mock_connection = function () { mock.mock_connection = function () {
return function () {
Strophe.Bosh.prototype._processRequest = function () {}; // Don't attempt to send out stanzas Strophe.Bosh.prototype._processRequest = function () {}; // Don't attempt to send out stanzas
var c = new Strophe.Connection('jasmine tests'); var c = new Strophe.Connection('jasmine tests');
c.vcard = { c.vcard = {
...@@ -75,6 +72,26 @@ ...@@ -75,6 +72,26 @@
c._changeConnectStatus(Strophe.Status.CONNECTED); c._changeConnectStatus(Strophe.Status.CONNECTED);
}; };
return c; return c;
};
}(); }();
mock.initConverse = function (func) {
return function () {
var converse = converse_api.initialize({
i18n: window.locales.en,
auto_subscribe: false,
bosh_service_url: 'localhost',
connection: mock.mock_connection(),
animate: false,
no_trimming: true,
auto_login: true,
jid: 'dummy@localhost',
password: 'secret',
debug: true
});
converse.ChatBoxViews.prototype.trimChat = function () {};
return func(converse);
};
};
return mock; return mock;
})); }));
(function (root, factory) { (function (root, factory) {
define("test_utils", [ define("test_utils", ['converse', 'mock'], factory);
'jquery', }(this, function (converse_api, mock) {
'mock' var $ = converse_api.env.jQuery;
],
function($, mock) {
return factory($, mock);
});
}(this, function ($, mock) {
var $pres = converse_api.env.$pres; var $pres = converse_api.env.$pres;
var $iq = converse_api.env.$iq; var $iq = converse_api.env.$iq;
var Strophe = converse_api.env.Strophe; var Strophe = converse_api.env.Strophe;
...@@ -23,7 +18,7 @@ ...@@ -23,7 +18,7 @@
return req; return req;
}; };
utils.closeAllChatBoxes = function () { utils.closeAllChatBoxes = function (converse) {
var i, chatbox; var i, chatbox;
for (i=converse.chatboxes.models.length-1; i>-1; i--) { for (i=converse.chatboxes.models.length-1; i>-1; i--) {
chatbox = converse.chatboxes.models[i]; chatbox = converse.chatboxes.models[i];
...@@ -78,7 +73,7 @@ ...@@ -78,7 +73,7 @@
$('#controlbox').remove(); $('#controlbox').remove();
}; };
utils.openContactsPanel = function () { utils.openContactsPanel = function (converse) {
var cbview = converse.chatboxviews.get('controlbox'); var cbview = converse.chatboxviews.get('controlbox');
var $tabs = cbview.$el.find('#controlbox-tabs'); var $tabs = cbview.$el.find('#controlbox-tabs');
$tabs.find('li').first().find('a').click(); $tabs.find('li').first().find('a').click();
...@@ -100,7 +95,7 @@ ...@@ -100,7 +95,7 @@
return views; return views;
}; };
utils.openChatBoxFor = function (jid) { utils.openChatBoxFor = function (converse, jid) {
return converse.roster.get(jid).trigger("open"); return converse.roster.get(jid).trigger("open");
}; };
...@@ -172,7 +167,7 @@ ...@@ -172,7 +167,7 @@
view.model.messages.browserStorage._clear(); view.model.messages.browserStorage._clear();
}; };
utils.createContacts = function (type, length) { utils.createContacts = function (converse, type, length) {
/* Create current (as opposed to requesting or pending) contacts /* Create current (as opposed to requesting or pending) contacts
* for the user's roster. * for the user's roster.
* *
......
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