1import HMRClient from '../../HMRClient';
2import LoadingView from '../../LoadingView';
3import { fetchThenEvalAsync } from '../fetchThenEval';
4import { loadBundleAsync } from '../loadBundle';
5
6jest.mock('../fetchThenEval', () => ({
7  fetchThenEvalAsync: jest.fn(async () => {}),
8}));
9
10jest.mock('../../HMRClient', () => ({
11  __esModule: true,
12  default: { registerBundle: jest.fn() },
13}));
14
15jest.mock('../../LoadingView');
16
17const originalEnv = process.env.NODE_ENV;
18afterEach(() => {
19  process.env.NODE_ENV = originalEnv;
20});
21
22it('loads a bundle', async () => {
23  process.env.NODE_ENV = 'development';
24  await loadBundleAsync('/Second.bundle?modulesOnly=true');
25  expect(LoadingView.showMessage).toBeCalledWith('Downloading...', 'load');
26  expect(LoadingView.hide).toBeCalledWith();
27  const url = `/Second.bundle?modulesOnly=true`;
28  expect(HMRClient.registerBundle).toBeCalledWith(url);
29  expect(fetchThenEvalAsync).toBeCalledWith(url);
30});
31it('loads a bundle in production', async () => {
32  process.env.NODE_ENV = 'production';
33  await loadBundleAsync('/Second.bundle?modulesOnly=true');
34  expect(LoadingView.showMessage).not.toBeCalled();
35  expect(LoadingView.hide).not.toBeCalled();
36  const url = `/Second.bundle?modulesOnly=true`;
37  expect(HMRClient.registerBundle).not.toBeCalled();
38  expect(fetchThenEvalAsync).toBeCalledWith(url);
39});
40