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,71 +45,49 @@ require([ ...@@ -45,71 +45,49 @@ require([
window.localStorage.clear(); window.localStorage.clear();
window.sessionStorage.clear(); window.sessionStorage.clear();
converse.initialize({ require([
i18n: window.locales.en, "console-runner",
auto_subscribe: false, //"spec/transcripts",
bosh_service_url: 'localhost', "spec/utils",
connection: mock.mock_connection, "spec/converse",
animate: false, /*
no_trimming: true, "spec/bookmarks",
auto_login: true, "spec/headline",
jid: 'dummy@localhost', "spec/disco",
password: 'secret', */
debug: true "spec/protocol",
}).then(function (converse) { /*
window.converse = converse; "spec/mam",
window.crypto = { "spec/otr",
getRandomValues: function (buf) { "spec/eventemitter",
var i; "spec/controlbox",
for (i=0, len=buf.length; i<len; i++) { "spec/chatbox",
buf[i] = Math.floor(Math.random()*256); "spec/chatroom",
} "spec/minchats",
} "spec/notification",
}; "spec/profiling",
require([ "spec/ping",
"console-runner", "spec/register",
//"spec/transcripts", "spec/xmppstatus",
"spec/utils", */
"spec/converse", ], function () {
"spec/bookmarks", // Jasmine stuff
"spec/headline", var jasmineEnv = jasmine.getEnv();
"spec/disco", var reporter;
"spec/protocol", if (/PhantomJS/.test(navigator.userAgent)) {
"spec/mam", reporter = new jasmine.ConsoleReporter();
"spec/otr", window.console_reporter = reporter;
"spec/eventemitter", jasmineEnv.addReporter(reporter);
"spec/controlbox", jasmineEnv.updateInterval = 0;
"spec/chatbox", } else {
"spec/chatroom", reporter = new jasmine.HtmlReporter();
"spec/minchats", jasmineEnv.addReporter(reporter);
"spec/notification", jasmineEnv.specFilter = function(spec) {
"spec/profiling", return reporter.specFilter(spec);
"spec/ping", };
"spec/register", jasmineEnv.updateInterval = 0;
"spec/xmppstatus", }
], function () { jasmineEnv.execute();
// Stub the trimChat method. It causes havoc when running with
// phantomJS.
converse.ChatBoxViews.prototype.trimChat = function () {};
// Jasmine stuff
var jasmineEnv = jasmine.getEnv();
var reporter;
if (/PhantomJS/.test(navigator.userAgent)) {
reporter = new jasmine.ConsoleReporter();
window.console_reporter = reporter;
jasmineEnv.addReporter(reporter);
jasmineEnv.updateInterval = 0;
} else {
reporter = new jasmine.HtmlReporter();
jasmineEnv.addReporter(reporter);
jasmineEnv.specFilter = function(spec) {
return reporter.specFilter(spec);
};
jasmineEnv.updateInterval = 0;
}
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,33 +44,54 @@ ...@@ -48,33 +44,54 @@
}; };
mock.mock_connection = function () { mock.mock_connection = function () {
Strophe.Bosh.prototype._processRequest = function () {}; // Don't attempt to send out stanzas return function () {
var c = new Strophe.Connection('jasmine tests'); Strophe.Bosh.prototype._processRequest = function () {}; // Don't attempt to send out stanzas
c.vcard = { var c = new Strophe.Connection('jasmine tests');
'get': function (callback, jid) { c.vcard = {
var fullname; 'get': function (callback, jid) {
if (!jid) { var fullname;
jid = 'dummy@localhost'; if (!jid) {
fullname = 'Max Mustermann' ; jid = 'dummy@localhost';
} else { fullname = 'Max Mustermann' ;
var name = jid.split('@')[0].replace(/\./g, ' ').split(' '); } else {
var last = name.length-1; var name = jid.split('@')[0].replace(/\./g, ' ').split(' ');
name[0] = name[0].charAt(0).toUpperCase()+name[0].slice(1); var last = name.length-1;
name[last] = name[last].charAt(0).toUpperCase()+name[last].slice(1); name[0] = name[0].charAt(0).toUpperCase()+name[0].slice(1);
fullname = name.join(' '); name[last] = name[last].charAt(0).toUpperCase()+name[last].slice(1);
fullname = name.join(' ');
}
var vcard = $iq().c('vCard').c('FN').t(fullname);
callback(vcard.tree());
} }
var vcard = $iq().c('vCard').c('FN').t(fullname); };
callback(vcard.tree()); c._proto._connect = function () {
} c.authenticated = true;
c.connected = true;
c.mock = true;
c.jid = 'dummy@localhost/resource';
c._changeConnectStatus(Strophe.Status.CONNECTED);
};
return c;
}; };
c._proto._connect = function () {
c.authenticated = true;
c.connected = true;
c.mock = true;
c.jid = 'dummy@localhost/resource';
c._changeConnectStatus(Strophe.Status.CONNECTED);
};
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