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

49 lines
1.1 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');
const { Crypto } = require('../ts/context/Crypto');
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-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(),
log: {
info: (...args) => console.log(...args),
warn: (...args) => console.warn(...args),
error: (...args) => console.error(...args),
},
},
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),
},
getPreferredSystemLocales: () => ['en'],
};
// 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() {}
};