2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2014-2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
/* global chai, Whisper, _, Backbone */
|
2018-11-02 18:02:53 +00:00
|
|
|
|
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
|
|
|
|
2018-11-02 18:02:53 +00:00
|
|
|
const OriginalReporter = mocha._reporter;
|
2014-11-25 01:28:51 +00:00
|
|
|
|
2018-11-08 00:53:41 +00:00
|
|
|
const SauceReporter = function Constructor(runner) {
|
2018-11-02 18:02:53 +00:00
|
|
|
const failedTests = [];
|
2014-11-25 01:28:51 +00:00
|
|
|
|
2018-11-02 18:02:53 +00:00
|
|
|
runner.on('end', () => {
|
|
|
|
window.mochaResults = runner.stats;
|
|
|
|
window.mochaResults.reports = failedTests;
|
|
|
|
});
|
2014-11-25 01:28:51 +00:00
|
|
|
|
2018-11-02 18:02:53 +00:00
|
|
|
runner.on('fail', (test, err) => {
|
|
|
|
const flattenTitles = item => {
|
|
|
|
const titles = [];
|
|
|
|
while (item.parent.title) {
|
|
|
|
titles.push(item.parent.title);
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
item = item.parent;
|
|
|
|
}
|
|
|
|
return titles.reverse();
|
|
|
|
};
|
|
|
|
failedTests.push({
|
|
|
|
name: test.title,
|
|
|
|
result: false,
|
|
|
|
message: err.message,
|
|
|
|
stack: err.stack,
|
|
|
|
titles: flattenTitles(test),
|
2014-11-25 01:28:51 +00:00
|
|
|
});
|
2018-11-02 18:02:53 +00:00
|
|
|
});
|
2014-11-25 01:28:51 +00:00
|
|
|
|
2018-11-02 18:02:53 +00:00
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new OriginalReporter(runner);
|
|
|
|
};
|
2014-11-25 01:28:51 +00:00
|
|
|
|
2018-11-02 18:02:53 +00:00
|
|
|
SauceReporter.prototype = OriginalReporter.prototype;
|
2014-11-25 01:28:51 +00:00
|
|
|
|
2018-11-02 18:02:53 +00:00
|
|
|
mocha.reporter(SauceReporter);
|
2014-11-25 01:28:51 +00:00
|
|
|
|
2014-11-13 22:35:37 +00:00
|
|
|
// Override the database id.
|
2018-04-27 21:25:04 +00:00
|
|
|
window.Whisper = window.Whisper || {};
|
2014-11-13 22:35:37 +00:00
|
|
|
window.Whisper.Database = window.Whisper.Database || {};
|
|
|
|
Whisper.Database.id = 'test';
|
|
|
|
|
2014-11-04 22:59:48 +00:00
|
|
|
/*
|
|
|
|
* global helpers for tests
|
|
|
|
*/
|
2018-11-02 18:02:53 +00:00
|
|
|
window.assertEqualArrayBuffers = (ab1, ab2) => {
|
2014-11-04 22:59:48 +00:00
|
|
|
assert.deepEqual(new Uint8Array(ab1), new Uint8Array(ab2));
|
2018-11-02 18:02:53 +00:00
|
|
|
};
|
2014-11-04 22:59:48 +00:00
|
|
|
|
2018-11-02 18:02:53 +00:00
|
|
|
window.hexToArrayBuffer = str => {
|
|
|
|
const ret = new ArrayBuffer(str.length / 2);
|
|
|
|
const array = new Uint8Array(ret);
|
|
|
|
for (let i = 0; i < str.length / 2; i += 1) {
|
2018-04-27 21:25:04 +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;
|
2018-11-02 18:02:53 +00:00
|
|
|
};
|
2014-11-16 21:19:51 +00:00
|
|
|
|
2018-11-02 18:02:53 +00:00
|
|
|
function deleteIndexedDB() {
|
2018-07-25 22:02:37 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
2018-11-08 00:53:41 +00:00
|
|
|
const idbReq = indexedDB.deleteDatabase('test');
|
2018-07-25 22:02:37 +00:00
|
|
|
idbReq.onsuccess = resolve;
|
|
|
|
idbReq.error = reject;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-04-16 01:02:44 +00:00
|
|
|
/* Delete the database before running any tests */
|
2018-07-25 22:02:37 +00:00
|
|
|
before(async () => {
|
2018-11-02 18:02:53 +00:00
|
|
|
await deleteIndexedDB();
|
2021-03-04 21:44:57 +00:00
|
|
|
try {
|
|
|
|
window.log.info('Initializing SQL in renderer');
|
|
|
|
await window.sqlInitializer.initialize();
|
|
|
|
window.log.info('SQL initialized in renderer');
|
|
|
|
} catch (err) {
|
|
|
|
window.log.error(
|
|
|
|
'SQL failed to initialize',
|
|
|
|
err && err.stack ? err.stack : err
|
|
|
|
);
|
|
|
|
}
|
2018-07-27 01:13:56 +00:00
|
|
|
await window.Signal.Data.removeAll();
|
2019-01-14 21:49:58 +00:00
|
|
|
await window.storage.fetch();
|
2018-07-25 22:02:37 +00:00
|
|
|
});
|
2018-04-03 15:39:08 +00:00
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
window.Whisper.events = _.clone(Backbone.Events);
|