2018-04-03 15:38:09 +00:00
|
|
|
mocha.setup('bdd');
|
2014-10-31 00:57:37 +00:00
|
|
|
window.assert = chai.assert;
|
2017-05-18 01:01:33 +00:00
|
|
|
window.PROTO_ROOT = '../protos';
|
2014-11-04 22:59:48 +00:00
|
|
|
|
2014-11-25 01:28:51 +00: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 22:35:37 +00:00
|
|
|
// Override the database id.
|
|
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
window.Whisper.Database = window.Whisper.Database || {};
|
|
|
|
Whisper.Database.id = 'test';
|
|
|
|
|
2014-11-04 22:59:48 +00: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);
|
2016-02-18 01:08:50 +00:00
|
|
|
for (var i = 0; i < str.length/2; i++) {
|
2014-11-04 22:59:48 +00:00
|
|
|
array[i] = parseInt(str.substr(i*2, 2), 16);
|
2016-02-18 01:08:50 +00:00
|
|
|
}
|
2014-11-04 22:59:48 +00:00
|
|
|
return ret;
|
|
|
|
};
|
2014-11-16 21:19:51 +00:00
|
|
|
|
2015-04-16 01:02:44 +00:00
|
|
|
/* Delete the database before running any tests */
|
|
|
|
before(function(done) {
|
|
|
|
var idbReq = indexedDB.deleteDatabase('test');
|
|
|
|
idbReq.onsuccess = function() { done(); };
|
|
|
|
});
|
2014-11-16 21:19:51 +00:00
|
|
|
|
2018-04-03 15:39:08 +00:00
|
|
|
async function clearDatabase(done) {
|
|
|
|
await Signal.Migrations.Migrations0DatabaseWithAttachmentData.run({
|
|
|
|
Backbone,
|
|
|
|
databaseName: Whisper.Database.id,
|
|
|
|
});
|
|
|
|
|
|
|
|
const convos = new Whisper.ConversationCollection();
|
|
|
|
await convos.fetch();
|
|
|
|
await convos.destroyAll();
|
|
|
|
const messages = new Whisper.MessageCollection();
|
|
|
|
await messages.fetch();
|
|
|
|
await messages.destroyAll();
|
|
|
|
if (done) {
|
|
|
|
done();
|
|
|
|
};
|
2014-11-16 21:19:51 +00:00
|
|
|
}
|