1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const lodash_1 = require("./wrap/lodash");
|
4 | const log_1 = require("./log");
|
5 | const anything_1 = require("./stringify/anything");
|
6 | const DEFAULTS = {
|
7 | ignoreWarnings: false,
|
8 | promiseConstructor: Promise,
|
9 | suppressErrors: false
|
10 | };
|
11 | const DELETED_OPTIONS = ['extendWhenReplacingConstructors'];
|
12 | let configData = lodash_1.default.extend({}, DEFAULTS);
|
13 | exports.default = lodash_1.default.tap((overrides) => {
|
14 | deleteDeletedOptions(overrides);
|
15 | ensureOverridesExist(overrides);
|
16 | return lodash_1.default.extend(configData, overrides);
|
17 | }, (config) => {
|
18 | config.reset = () => {
|
19 | configData = lodash_1.default.extend({}, DEFAULTS);
|
20 | };
|
21 | });
|
22 | const deleteDeletedOptions = (overrides) => {
|
23 | lodash_1.default.each(overrides, (val, key) => {
|
24 | if (lodash_1.default.includes(DELETED_OPTIONS, key)) {
|
25 | log_1.default.warn('td.config', `"${key}" is no longer a valid configuration key. Remove it from your calls to td.config() or it may throw an error in the future. For more information, try hunting around our GitHub repo for it:\n\n https://github.com/testdouble/testdouble.js/search?q=${key}`);
|
26 | delete overrides[key];
|
27 | }
|
28 | });
|
29 | };
|
30 | const ensureOverridesExist = (overrides) => {
|
31 | lodash_1.default.each(overrides, (val, key) => {
|
32 | if (!Object.prototype.hasOwnProperty.call(configData, key)) {
|
33 | log_1.default.error('td.config', `"${key}" is not a valid configuration key (valid keys are: ${(0, anything_1.default)(lodash_1.default.keys(configData))})`);
|
34 | }
|
35 | });
|
36 | };
|