|
|
import '@testing-library/jest-dom'; |
|
|
|
|
|
const nodeCrypto = require( 'node:crypto' ); |
|
|
const { ReadableStream, TransformStream } = require( 'node:stream/web' ); |
|
|
const { TextEncoder, TextDecoder } = require( 'util' ); |
|
|
const nock = require( 'nock' ); |
|
|
|
|
|
|
|
|
nock.disableNetConnect(); |
|
|
|
|
|
beforeAll( () => { |
|
|
|
|
|
if ( ! nock.isActive() ) { |
|
|
nock.activate(); |
|
|
} |
|
|
} ); |
|
|
|
|
|
afterAll( () => { |
|
|
|
|
|
nock.restore(); |
|
|
nock.cleanAll(); |
|
|
} ); |
|
|
|
|
|
|
|
|
global.TextEncoder = TextEncoder; |
|
|
global.TextDecoder = TextDecoder; |
|
|
|
|
|
|
|
|
|
|
|
global.CSS = { |
|
|
supports: jest.fn(), |
|
|
}; |
|
|
|
|
|
global.ResizeObserver = require( 'resize-observer-polyfill' ); |
|
|
|
|
|
global.fetch = jest.fn( () => |
|
|
Promise.resolve( { |
|
|
json: () => Promise.resolve(), |
|
|
} ) |
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
jest.mock( 'wpcom-proxy-request', () => ( { |
|
|
__esModule: true, |
|
|
canAccessWpcomApis: jest.fn(), |
|
|
reloadProxy: jest.fn(), |
|
|
requestAllBlogsAccess: jest.fn(), |
|
|
} ) ); |
|
|
|
|
|
|
|
|
global.crypto.randomUUID = () => nodeCrypto.randomUUID(); |
|
|
|
|
|
global.matchMedia = jest.fn( ( query ) => ( { |
|
|
matches: false, |
|
|
media: query, |
|
|
onchange: null, |
|
|
addListener: jest.fn(), |
|
|
removeListener: jest.fn(), |
|
|
addEventListener: jest.fn(), |
|
|
removeEventListener: jest.fn(), |
|
|
dispatchEvent: jest.fn(), |
|
|
} ) ); |
|
|
|
|
|
|
|
|
global.ReadableStream = ReadableStream; |
|
|
global.TransformStream = TransformStream; |
|
|
global.Worker = require( 'worker_threads' ).Worker; |
|
|
|
|
|
|
|
|
if ( typeof global.structuredClone !== 'function' ) { |
|
|
global.structuredClone = ( obj ) => JSON.parse( JSON.stringify( obj ) ); |
|
|
} |
|
|
|
|
|
|
|
|
if ( ! global.crypto.subtle ) { |
|
|
|
|
|
global.crypto.subtle = nodeCrypto.subtle; |
|
|
} |
|
|
|