Merge branch 'fix-typo-drive' into 'main'
[ProtonMail-WebClient.git] / packages / pass / jest.setup.js
blob66c4d95088c8e40a6f9ab098ce4f7102eaad0390
1 import '@testing-library/jest-dom';
2 import { TextDecoder, TextEncoder } from 'util';
3 import 'whatwg-fetch';
5 // Getting ReferenceError: TextDecoder is not defined without
6 global.TextEncoder = TextEncoder;
7 global.TextDecoder = TextDecoder;
8 global.ENV = 'test';
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', () => ({
12     __esModule: true,
13     loadCryptoWorker: jest.fn(),
14 }));
16 jest.mock('@proton/shared/lib/i18n/dateFnLocales', () => ({
17     __esModule: true,
18 }));
20 jest.mock('@proton/shared/lib/pow/wasmWorkerWrapper.ts', () => ({
21     __esModule: true,
22 }));
24 jest.mock('@proton/shared/lib/pow/pbkdfWorkerWrapper.ts', () => ({
25     __esModule: true,
26 }));
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;
35 expect.extend({
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;
50         const message = pass
51             ? () => `expected Response not to match the received Response`
52             : () => `expected Response to match for properties: ${mismatchedProps.join(', ')}`;
54         return { message, pass };
55     },
56 });