Export init function

Summary: This way we can mock it during tests.

Reviewed By: jknoxville

Differential Revision: D9788349

fbshipit-source-id: 55b2a61186e6294a8098db7add50fd8bbac7a680
This commit is contained in:
Pascal Hartig
2018-09-13 08:51:16 -07:00
committed by Facebook Github Bot
parent 5e0271cfc3
commit fc653d8057
3 changed files with 29 additions and 16 deletions

10
src/__mocks__/init.js Normal file
View File

@@ -0,0 +1,10 @@
/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
*/
export default function init() {
// no-op
}

View File

@@ -14,9 +14,10 @@ export {SonarBasePlugin, SonarPlugin, SonarDevicePlugin} from './plugin.js';
export {createTablePlugin} from './createTablePlugin.js';
export {default as SonarSidebar} from './chrome/SonarSidebar.js';
export * from './init.js';
export {default} from './init.js';
export {default as AndroidDevice} from './devices/AndroidDevice.js';
export {default as Device} from './devices/BaseDevice.js';
export {default as IOSDevice} from './devices/IOSDevice.js';
import init from './init.js';
init();

View File

@@ -62,10 +62,11 @@ const AppFrame = () => (
</TooltipProvider>
);
// $FlowFixMe: this element exists!
ReactDOM.render(<AppFrame />, document.getElementById('root'));
// $FlowFixMe: service workers exist!
navigator.serviceWorker
export default function init() {
// $FlowFixMe: this element exists!
ReactDOM.render(<AppFrame />, document.getElementById('root'));
// $FlowFixMe: service workers exist!
navigator.serviceWorker
.register(
process.env.NODE_ENV === 'production'
? path.join(__dirname, 'serviceWorker.js')
@@ -75,3 +76,4 @@ navigator.serviceWorker
(r.installing || r.active).postMessage({precachedIcons});
})
.catch(console.error);
}