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,71 +45,49 @@ 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",
"spec/controlbox",
"spec/chatbox",
"spec/chatroom",
"spec/minchats",
"spec/notification",
"spec/profiling",
"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;
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();
});
require([
"console-runner",
//"spec/transcripts",
"spec/utils",
"spec/converse",
/*
"spec/bookmarks",
"spec/headline",
"spec/disco",
*/
"spec/protocol",
/*
"spec/mam",
"spec/otr",
"spec/eventemitter",
"spec/controlbox",
"spec/chatbox",
"spec/chatroom",
"spec/minchats",
"spec/notification",
"spec/profiling",
"spec/ping",
"spec/register",
"spec/xmppstatus",
*/
], 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) {
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,33 +44,54 @@
};
mock.mock_connection = function () {
Strophe.Bosh.prototype._processRequest = function () {}; // Don't attempt to send out stanzas
var c = new Strophe.Connection('jasmine tests');
c.vcard = {
'get': function (callback, jid) {
var fullname;
if (!jid) {
jid = 'dummy@localhost';
fullname = 'Max Mustermann' ;
} else {
var name = jid.split('@')[0].replace(/\./g, ' ').split(' ');
var last = name.length-1;
name[0] = name[0].charAt(0).toUpperCase()+name[0].slice(1);
name[last] = name[last].charAt(0).toUpperCase()+name[last].slice(1);
fullname = name.join(' ');
return function () {
Strophe.Bosh.prototype._processRequest = function () {}; // Don't attempt to send out stanzas
var c = new Strophe.Connection('jasmine tests');
c.vcard = {
'get': function (callback, jid) {
var fullname;
if (!jid) {
jid = 'dummy@localhost';
fullname = 'Max Mustermann' ;
} else {
var name = jid.split('@')[0].replace(/\./g, ' ').split(' ');
var last = name.length-1;
name[0] = name[0].charAt(0).toUpperCase()+name[0].slice(1);
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;
}));
(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