const {
  ClientRequestInterceptor,
} = require('@mswjs/interceptors/lib/interceptors/ClientRequest/index.js');
const {
  XMLHttpRequestInterceptor,
} = require('@mswjs/interceptors/lib/interceptors/XMLHttpRequest/index.js');
const { SetupServerApi } = require('msw/node');

exports.mswServer = new SetupServerApi(
  // do not use FetchInterceptors
  // Use something like whatwg-fetch in setupAfterEnv etc.
  // ex: https://github.com/mswjs/examples/blob/master/examples/with-jest/jest.setup.js#L1-L2
  [ClientRequestInterceptor, XMLHttpRequestInterceptor],
  // rest.get('*', () => console.log('caught')),
);

beforeAll(() =>
  exports.mswServer.listen({
    onUnhandledRequest: 'error',
  }),
);

afterEach(() => exports.mswServer.resetHandlers());

afterAll(() => exports.mswServer.close());
