1 import '@testing-library/jest-dom';
2 import { TextDecoder, TextEncoder } from 'util';
5 // Getting ReferenceError: TextDecoder is not defined without
6 global.TextEncoder = TextEncoder;
7 global.TextDecoder = TextDecoder;
10 // Do not start crypto worker pool, let the single tests setup/mock the CryptoProxy as needed
11 jest.mock('@proton/shared/lib/helpers/setupCryptoWorker', () => ({
13 loadCryptoWorker: jest.fn(),
16 jest.mock('@proton/shared/lib/i18n/dateFnLocales', () => ({
20 jest.mock('@proton/shared/lib/pow/wasmWorkerWrapper.ts', () => ({
24 jest.mock('@proton/shared/lib/pow/pbkdfWorkerWrapper.ts', () => ({
28 jest.mock('loglevel');
29 jest.mock('@proton/pass/lib/core/core.ui');
31 // JSDom does not include webcrypto
32 const crypto = require('crypto').webcrypto;
33 global.crypto.subtle = crypto.subtle;
36 async toMatchResponse(received, expected) {
37 const compareProps = ['status', 'statusText', 'ok'];
38 const mismatchedProps = compareProps.filter((prop) => received[prop] !== expected[prop]);
40 const bodyReceived = await received.clone().text();
41 const bodyExpected = await expected.clone().text();
42 if (bodyExpected !== bodyReceived) mismatchedProps.push('body');
44 const headersReceived = JSON.stringify(received.headers);
45 const headersExpected = JSON.stringify(expected.headers);
46 if (headersExpected !== headersReceived) mismatchedProps.push('headers');
48 const pass = mismatchedProps.length === 0;
51 ? () => `expected Response not to match the received Response`
52 : () => `expected Response to match for properties: ${mismatchedProps.join(', ')}`;
54 return { message, pass };