2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
2022-06-13 21:39:35 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
/* eslint-disable no-console */
|
|
|
|
|
2024-06-28 00:22:06 +00:00
|
|
|
import { inspect, parseArgs } from 'node:util';
|
2022-06-13 21:39:35 +00:00
|
|
|
import { ipcRenderer as ipc } from 'electron';
|
|
|
|
import { sync } from 'fast-glob';
|
|
|
|
|
|
|
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
2024-07-22 19:27:09 +00:00
|
|
|
import chai, { assert, config as chaiConfig } from 'chai';
|
|
|
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
|
|
import chaiAsPromised from 'chai-as-promised';
|
2024-05-29 17:19:33 +00:00
|
|
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
2024-06-28 00:22:06 +00:00
|
|
|
import { reporters, type MochaOptions } from 'mocha';
|
2022-06-13 21:39:35 +00:00
|
|
|
|
2023-01-19 00:02:03 +00:00
|
|
|
import { getSignalProtocolStore } from '../../SignalProtocolStore';
|
2023-10-04 00:12:57 +00:00
|
|
|
import { initMessageCleanup } from '../../services/messageStateCleanup';
|
2023-04-11 03:54:43 +00:00
|
|
|
import { initializeMessageCounter } from '../../util/incrementMessageCounter';
|
2023-10-04 00:12:57 +00:00
|
|
|
import { initializeRedux } from '../../state/initializeRedux';
|
|
|
|
import * as Stickers from '../../types/Stickers';
|
2024-03-07 17:36:08 +00:00
|
|
|
import { ThemeType } from '../../types/Util';
|
2023-01-19 00:02:03 +00:00
|
|
|
|
2024-07-22 19:27:09 +00:00
|
|
|
chai.use(chaiAsPromised);
|
|
|
|
|
2024-05-29 17:19:33 +00:00
|
|
|
// Show actual objects instead of abbreviated errors
|
|
|
|
chaiConfig.truncateThreshold = 0;
|
|
|
|
|
|
|
|
function patchDeepEqual(method: 'deepEqual' | 'deepStrictEqual'): void {
|
|
|
|
const originalFn = assert[method];
|
|
|
|
assert[method] = (...args) => {
|
|
|
|
try {
|
|
|
|
return originalFn(...args);
|
|
|
|
} catch (error) {
|
|
|
|
reporters.base.useColors = false;
|
|
|
|
error.message = reporters.base.generateDiff(
|
|
|
|
inspect(error.actual, { depth: Infinity, sorted: true }),
|
|
|
|
inspect(error.expected, { depth: Infinity, sorted: true })
|
|
|
|
);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
patchDeepEqual('deepEqual');
|
|
|
|
patchDeepEqual('deepStrictEqual');
|
|
|
|
|
2022-06-13 21:39:35 +00:00
|
|
|
window.assert = assert;
|
|
|
|
|
|
|
|
// This is a hack to let us run TypeScript tests in the renderer process. See the
|
2023-10-04 00:12:57 +00:00
|
|
|
// code in `test/test.js`.
|
2022-06-13 21:39:35 +00:00
|
|
|
|
2024-06-28 00:22:06 +00:00
|
|
|
const setup: MochaOptions = {};
|
2024-07-22 19:27:09 +00:00
|
|
|
let worker = 0;
|
|
|
|
let workerCount = 1;
|
2024-06-28 00:22:06 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
const { values } = parseArgs({
|
|
|
|
args: ipc.sendSync('ci:test-electron:getArgv'),
|
|
|
|
options: {
|
|
|
|
grep: {
|
|
|
|
type: 'string',
|
|
|
|
},
|
2024-07-22 19:27:09 +00:00
|
|
|
worker: {
|
|
|
|
type: 'string',
|
|
|
|
},
|
|
|
|
'worker-count': {
|
|
|
|
type: 'string',
|
|
|
|
},
|
2024-06-28 00:22:06 +00:00
|
|
|
},
|
|
|
|
strict: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (typeof values.grep === 'string') {
|
|
|
|
setup.grep = values.grep;
|
|
|
|
}
|
2024-07-22 19:27:09 +00:00
|
|
|
if (typeof values.worker === 'string') {
|
|
|
|
worker = parseInt(values.worker, 10);
|
|
|
|
}
|
|
|
|
if (typeof values['worker-count'] === 'string') {
|
|
|
|
workerCount = parseInt(values['worker-count'], 10);
|
|
|
|
}
|
2024-06-28 00:22:06 +00:00
|
|
|
}
|
|
|
|
|
2022-06-13 21:39:35 +00:00
|
|
|
window.testUtilities = {
|
2024-06-28 00:22:06 +00:00
|
|
|
setup,
|
2023-10-04 00:12:57 +00:00
|
|
|
|
2024-06-28 00:22:06 +00:00
|
|
|
onTestEvent(event: unknown) {
|
|
|
|
return ipc.invoke('ci:test-electron:event', event);
|
2022-06-13 21:39:35 +00:00
|
|
|
},
|
2023-10-04 00:12:57 +00:00
|
|
|
|
2024-07-02 19:56:40 +00:00
|
|
|
debug(info) {
|
|
|
|
return ipc.invoke('ci:test-electron:debug', info);
|
|
|
|
},
|
|
|
|
|
2023-10-04 00:12:57 +00:00
|
|
|
async initialize() {
|
|
|
|
initMessageCleanup();
|
|
|
|
await initializeMessageCounter();
|
|
|
|
await Stickers.load();
|
|
|
|
|
|
|
|
initializeRedux({
|
2024-08-26 14:26:21 +00:00
|
|
|
badgesState: { byId: {} },
|
2024-04-01 19:19:35 +00:00
|
|
|
callLinks: [],
|
2024-08-26 14:26:21 +00:00
|
|
|
callHistory: [],
|
|
|
|
callHistoryUnreadCount: 0,
|
2023-10-04 00:12:57 +00:00
|
|
|
mainWindowStats: {
|
|
|
|
isFullScreen: false,
|
|
|
|
isMaximized: false,
|
|
|
|
},
|
|
|
|
menuOptions: {
|
|
|
|
development: false,
|
|
|
|
devTools: false,
|
|
|
|
includeSetup: false,
|
|
|
|
isProduction: false,
|
|
|
|
platform: 'test',
|
|
|
|
},
|
2024-08-26 14:26:21 +00:00
|
|
|
recentEmoji: {
|
|
|
|
recents: [],
|
|
|
|
},
|
2023-10-04 00:12:57 +00:00
|
|
|
stories: [],
|
|
|
|
storyDistributionLists: [],
|
2024-08-26 14:26:21 +00:00
|
|
|
stickers: {
|
|
|
|
installedPack: null,
|
|
|
|
packs: {},
|
|
|
|
recentStickers: [],
|
|
|
|
blessedPacks: {},
|
|
|
|
},
|
2024-03-07 17:36:08 +00:00
|
|
|
theme: ThemeType.dark,
|
2023-10-04 00:12:57 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2022-06-13 21:39:35 +00:00
|
|
|
prepareTests() {
|
|
|
|
console.log('Preparing tests...');
|
2024-07-22 19:27:09 +00:00
|
|
|
const files = sync('../../test-{both,electron}/**/*_test.js', {
|
2022-06-13 21:39:35 +00:00
|
|
|
absolute: true,
|
|
|
|
cwd: __dirname,
|
2024-07-22 19:27:09 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
for (let i = 0; i < files.length; i += 1) {
|
|
|
|
if (i % workerCount === worker) {
|
|
|
|
// eslint-disable-next-line import/no-dynamic-require, global-require
|
|
|
|
require(files[i]);
|
|
|
|
}
|
|
|
|
}
|
2022-06-13 21:39:35 +00:00
|
|
|
},
|
|
|
|
};
|
2023-01-19 00:02:03 +00:00
|
|
|
|
|
|
|
window.getSignalProtocolStore = getSignalProtocolStore;
|