2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2015-2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-09-01 00:09:28 +00:00
|
|
|
/* global chai */
|
2018-11-02 18:02:53 +00:00
|
|
|
|
2018-05-02 16:51:22 +00:00
|
|
|
mocha.setup('bdd');
|
2015-01-14 01:04:21 +00:00
|
|
|
window.assert = chai.assert;
|
2017-12-01 21:35:39 +00:00
|
|
|
window.PROTO_ROOT = '../../protos';
|
2015-01-14 01:04:21 +00:00
|
|
|
|
2018-11-02 18:02:53 +00:00
|
|
|
const OriginalReporter = mocha._reporter;
|
|
|
|
|
2018-11-08 00:53:41 +00:00
|
|
|
const SauceReporter = function Constructor(runner) {
|
2018-11-02 18:02:53 +00:00
|
|
|
const failedTests = [];
|
|
|
|
|
|
|
|
runner.on('end', () => {
|
|
|
|
window.mochaResults = runner.stats;
|
|
|
|
window.mochaResults.reports = failedTests;
|
|
|
|
});
|
|
|
|
|
|
|
|
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),
|
2015-01-14 01:04:21 +00:00
|
|
|
});
|
2018-11-02 18:02:53 +00:00
|
|
|
});
|
2015-01-14 01:04:21 +00:00
|
|
|
|
2018-11-02 18:02:53 +00:00
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new OriginalReporter(runner);
|
|
|
|
};
|
2015-01-14 01:04:21 +00:00
|
|
|
|
2018-11-02 18:02:53 +00:00
|
|
|
SauceReporter.prototype = OriginalReporter.prototype;
|
2015-01-14 01:04:21 +00:00
|
|
|
|
2018-11-02 18:02:53 +00:00
|
|
|
mocha.reporter(SauceReporter);
|
2015-01-14 01:04:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* global helpers for tests
|
|
|
|
*/
|
2018-11-02 18:02:53 +00:00
|
|
|
window.assertEqualArrayBuffers = (ab1, ab2) => {
|
2015-01-14 01:04:21 +00:00
|
|
|
assert.deepEqual(new Uint8Array(ab1), new Uint8Array(ab2));
|
2018-11-02 18:02:53 +00:00
|
|
|
};
|
2015-01-14 01:04:21 +00:00
|
|
|
|
2018-11-02 18:02:53 +00:00
|
|
|
window.hexToArrayBuffer = str => {
|
2018-07-21 21:51:20 +00:00
|
|
|
const ret = new ArrayBuffer(str.length / 2);
|
|
|
|
const array = new Uint8Array(ret);
|
2018-11-02 18:02:53 +00:00
|
|
|
for (let i = 0; i < str.length / 2; i += 1)
|
2018-05-02 16:51:22 +00:00
|
|
|
array[i] = parseInt(str.substr(i * 2, 2), 16);
|
2015-01-14 01:04:21 +00:00
|
|
|
return ret;
|
2018-11-02 18:02:53 +00:00
|
|
|
};
|
2017-12-01 21:35:39 +00:00
|
|
|
|
2018-11-02 18:02:53 +00:00
|
|
|
window.MockSocket.prototype.addEventListener = () => null;
|
2020-09-14 22:16:57 +00:00
|
|
|
|
|
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
window.Whisper.events = {
|
|
|
|
on() {},
|
|
|
|
trigger() {},
|
|
|
|
};
|