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 @@
utils.merge(converse, 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({
'updateSettings': updateSettings,
'converse': converse
......
......@@ -45,36 +45,18 @@ require([
window.localStorage.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([
"console-runner",
//"spec/transcripts",
"spec/utils",
"spec/converse",
/*
"spec/bookmarks",
"spec/headline",
"spec/disco",
*/
"spec/protocol",
/*
"spec/mam",
"spec/otr",
"spec/eventemitter",
......@@ -87,11 +69,8 @@ require([
"spec/ping",
"spec/register",
"spec/xmppstatus",
*/
], function () {
// Stub the trimChat method. It causes havoc when running with
// phantomJS.
converse.ChatBoxViews.prototype.trimChat = function () {};
// Jasmine stuff
var jasmineEnv = jasmine.getEnv();
var reporter;
......@@ -110,6 +89,5 @@ require([
}
jasmineEnv.execute();
});
});
}
);
(function (root, factory) {
define("mock",
['converse'],
function(converse) {
return factory(converse);
});
}(this, function (converse) {
var Strophe = converse.env.Strophe;
var $iq = converse.env.$iq;
define("mock", ['converse'], factory);
}(this, function (converse_api) {
var Strophe = converse_api.env.Strophe;
var $iq = converse_api.env.$iq;
var mock = {};
// Names from http://www.fakenamegenerator.com/
mock.req_names = [
......@@ -48,6 +44,7 @@
};
mock.mock_connection = function () {
return function () {
Strophe.Bosh.prototype._processRequest = function () {}; // Don't attempt to send out stanzas
var c = new Strophe.Connection('jasmine tests');
c.vcard = {
......@@ -75,6 +72,26 @@
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;
}));
(function (root, factory) {
define("test_utils", [
'jquery',
'mock'
],
function($, mock) {
return factory($, mock);
});
}(this, function ($, mock) {
define("test_utils", ['converse', 'mock'], factory);
}(this, function (converse_api, mock) {
var $ = converse_api.env.jQuery;
var $pres = converse_api.env.$pres;
var $iq = converse_api.env.$iq;
var Strophe = converse_api.env.Strophe;
......@@ -23,7 +18,7 @@
return req;
};
utils.closeAllChatBoxes = function () {
utils.closeAllChatBoxes = function (converse) {
var i, chatbox;
for (i=converse.chatboxes.models.length-1; i>-1; i--) {
chatbox = converse.chatboxes.models[i];
......@@ -78,7 +73,7 @@
$('#controlbox').remove();
};
utils.openContactsPanel = function () {
utils.openContactsPanel = function (converse) {
var cbview = converse.chatboxviews.get('controlbox');
var $tabs = cbview.$el.find('#controlbox-tabs');
$tabs.find('li').first().find('a').click();
......@@ -100,7 +95,7 @@
return views;
};
utils.openChatBoxFor = function (jid) {
utils.openChatBoxFor = function (converse, jid) {
return converse.roster.get(jid).trigger("open");
};
......@@ -172,7 +167,7 @@
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
* 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