// Polyfills for MSW 2.x - must be loaded before MSW
const { TextEncoder, TextDecoder } = require('util');

global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;

// Polyfill for fetch, Request, Response, Headers
const { fetch, Headers, Request, Response } = require('cross-fetch');

global.fetch = fetch;
global.Headers = Headers;
global.Request = Request;
global.Response = Response;

// BroadcastChannel polyfill for MSW
class BroadcastChannel {
  constructor(name) {
    this.name = name;
  }
  postMessage() {}
  close() {}
  addEventListener() {}
  removeEventListener() {}
}

global.BroadcastChannel = BroadcastChannel;
