2014-11-04 23:59:48 +01:00
|
|
|
/*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-10-31 01:57:37 +01:00
|
|
|
mocha.setup("bdd");
|
|
|
|
window.assert = chai.assert;
|
2014-11-04 23:59:48 +01:00
|
|
|
|
2014-11-25 02:28:51 +01:00
|
|
|
(function() {
|
|
|
|
var OriginalReporter = mocha._reporter;
|
|
|
|
|
|
|
|
var SauceReporter = function(runner) {
|
|
|
|
var failedTests = [];
|
|
|
|
|
|
|
|
runner.on('end', function() {
|
|
|
|
window.mochaResults = runner.stats;
|
|
|
|
window.mochaResults.reports = failedTests;
|
|
|
|
});
|
|
|
|
|
|
|
|
runner.on('fail', function(test, err) {
|
|
|
|
var flattenTitles = function(test) {
|
|
|
|
var titles = [];
|
|
|
|
while (test.parent.title) {
|
|
|
|
titles.push(test.parent.title);
|
|
|
|
test = test.parent;
|
|
|
|
}
|
|
|
|
return titles.reverse();
|
|
|
|
};
|
|
|
|
failedTests.push({
|
|
|
|
name: test.title,
|
|
|
|
result: false,
|
|
|
|
message: err.message,
|
|
|
|
stack: err.stack,
|
|
|
|
titles: flattenTitles(test)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
new OriginalReporter(runner);
|
|
|
|
};
|
|
|
|
|
|
|
|
SauceReporter.prototype = OriginalReporter.prototype;
|
|
|
|
|
|
|
|
mocha.reporter(SauceReporter);
|
|
|
|
}());
|
|
|
|
|
2014-11-13 23:35:37 +01:00
|
|
|
// Override the database id.
|
|
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
window.Whisper.Database = window.Whisper.Database || {};
|
|
|
|
Whisper.Database.id = 'test';
|
|
|
|
|
2014-11-04 23:59:48 +01:00
|
|
|
/*
|
|
|
|
* global helpers for tests
|
|
|
|
*/
|
|
|
|
function assertEqualArrayBuffers(ab1, ab2) {
|
|
|
|
assert.deepEqual(new Uint8Array(ab1), new Uint8Array(ab2));
|
|
|
|
};
|
|
|
|
|
|
|
|
function hexToArrayBuffer(str) {
|
|
|
|
var ret = new ArrayBuffer(str.length / 2);
|
|
|
|
var array = new Uint8Array(ret);
|
|
|
|
for (var i = 0; i < str.length/2; i++)
|
|
|
|
array[i] = parseInt(str.substr(i*2, 2), 16);
|
|
|
|
return ret;
|
|
|
|
};
|
2014-11-16 22:19:51 +01:00
|
|
|
|
|
|
|
function deleteDatabase(done) {
|
|
|
|
indexedDB.deleteDatabase('test').then(done);
|
|
|
|
};
|
|
|
|
|
|
|
|
function clearDatabase(done) {
|
|
|
|
var convos = new Whisper.ConversationCollection();
|
|
|
|
return convos.fetch().then(function() {
|
|
|
|
convos.destroyAll().then(function() {
|
|
|
|
var messages = new Whisper.MessageCollection();
|
|
|
|
return messages.fetch().then(function() {
|
|
|
|
messages.destroyAll().then(function() {
|
|
|
|
if (done) {
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|