Move configuration to module

Summary:
Moves the JSON config access to one module instead of
ad-hoc de-serialising the object all over the place.
This also adds a type for it so we hopefully won't typo things that easily.

Reviewed By: danielbuechele

Differential Revision: D13956612

fbshipit-source-id: 48098deafedf18cc86c8802a3c40fba9394b8262
This commit is contained in:
Pascal Hartig
2019-02-06 03:15:41 -08:00
committed by Facebook Github Bot
parent e78bd57514
commit 14ae2fea2c
4 changed files with 89 additions and 13 deletions

View File

@@ -0,0 +1,42 @@
/**
* 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
*/
import {default as config, resetConfigForTesting} from '../processConfig.js';
afterEach(() => {
resetConfigForTesting();
});
test('config is decoded from env', () => {
process.env.CONFIG = JSON.stringify({
disabledPlugins: ['pluginA', 'pluginB', 'pluginC'],
pluginPaths: ['/a/path', 'b/path'],
lastWindowPosition: {x: 4, y: 8, width: 15, height: 16},
updaterEnabled: false,
screenCapturePath: '/my/screenshot/path',
});
expect(config()).toEqual({
disabledPlugins: new Set(['pluginA', 'pluginB', 'pluginC']),
pluginPaths: ['/a/path', 'b/path'],
lastWindowPosition: {x: 4, y: 8, width: 15, height: 16},
updaterEnabled: false,
screenCapturePath: '/my/screenshot/path',
});
});
test('config is decoded from env with defaults', () => {
process.env.CONFIG = '{}';
expect(config()).toEqual({
disabledPlugins: new Set([]),
pluginPaths: [],
lastWindowPosition: undefined,
updaterEnabled: true,
screenCapturePath: undefined,
});
});