2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
2021-01-06 17:23:15 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-01-06 15:41:43 +00:00
|
|
|
/* eslint-disable no-console */
|
|
|
|
|
2021-05-28 19:11:19 +00:00
|
|
|
const chai = require('chai');
|
|
|
|
const chaiAsPromised = require('chai-as-promised');
|
2023-07-20 03:14:08 +00:00
|
|
|
const { usernames } = require('@signalapp/libsignal-client');
|
2021-05-28 19:11:19 +00:00
|
|
|
|
2021-10-07 23:28:47 +00:00
|
|
|
const { Crypto } = require('../ts/context/Crypto');
|
2021-02-04 19:54:03 +00:00
|
|
|
const { setEnvironment, Environment } = require('../ts/environment');
|
|
|
|
|
2021-05-28 19:11:19 +00:00
|
|
|
chai.use(chaiAsPromised);
|
|
|
|
|
2021-04-05 20:44:02 +00:00
|
|
|
setEnvironment(Environment.Test);
|
2021-02-04 19:54:03 +00:00
|
|
|
|
2021-05-28 19:11:19 +00:00
|
|
|
const storageMap = new Map();
|
|
|
|
|
2021-01-06 15:41:43 +00:00
|
|
|
// To replicate logic we have on the client side
|
|
|
|
global.window = {
|
2022-02-25 23:59:27 +00:00
|
|
|
Date,
|
|
|
|
performance,
|
2021-10-07 23:28:47 +00:00
|
|
|
SignalContext: {
|
|
|
|
crypto: new Crypto(),
|
2023-07-20 03:14:08 +00:00
|
|
|
usernames,
|
2021-09-17 18:27:53 +00:00
|
|
|
log: {
|
|
|
|
info: (...args) => console.log(...args),
|
|
|
|
warn: (...args) => console.warn(...args),
|
|
|
|
error: (...args) => console.error(...args),
|
|
|
|
},
|
2021-01-06 15:41:43 +00:00
|
|
|
},
|
|
|
|
i18n: key => `i18n(${key})`,
|
2021-05-28 19:11:19 +00:00
|
|
|
storage: {
|
|
|
|
get: key => storageMap.get(key),
|
|
|
|
put: async (key, value) => storageMap.set(key, value),
|
|
|
|
},
|
2023-03-02 18:43:25 +00:00
|
|
|
getPreferredSystemLocales: () => ['en'],
|
2021-01-06 15:41:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// For ducks/network.getEmptyState()
|
|
|
|
global.navigator = {};
|
|
|
|
global.WebSocket = {};
|
2022-09-15 20:10:46 +00:00
|
|
|
|
|
|
|
// For GlobalAudioContext.tsx
|
|
|
|
/* eslint max-classes-per-file: ["error", 2] */
|
|
|
|
global.AudioContext = class {};
|
|
|
|
global.Audio = class {
|
2023-02-24 23:18:57 +00:00
|
|
|
pause() {}
|
2022-09-15 20:10:46 +00:00
|
|
|
addEventListener() {}
|
|
|
|
};
|