signal-desktop/test/setup-test-node.js

55 lines
1.4 KiB
JavaScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
/* 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
const { Crypto } = require('../ts/context/Crypto');
const { setEnvironment, Environment } = require('../ts/environment');
const { HourCyclePreference } = require('../ts/types/I18N');
2021-05-28 19:11:19 +00:00
chai.use(chaiAsPromised);
2021-04-05 20:44:02 +00:00
setEnvironment(Environment.Test);
2021-05-28 19:11:19 +00:00
const storageMap = new Map();
// To replicate logic we have on the client side
global.window = {
2022-02-25 23:59:27 +00:00
Date,
performance,
SignalContext: {
crypto: new Crypto(),
2023-07-20 03:14:08 +00:00
usernames,
log: {
info: (...args) => console.log(...args),
warn: (...args) => console.warn(...args),
error: (...args) => console.error(...args),
},
getResolvedMessagesLocale: () => 'en',
getResolvedMessagesLocaleDirection: () => 'ltr',
getHourCyclePreference: () => HourCyclePreference.UnknownPreference,
getPreferredSystemLocales: () => ['en'],
},
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),
},
};
// For ducks/network.getEmptyState()
global.navigator = {};
global.WebSocket = {};
// 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() {}
addEventListener() {}
};