UNPKG

1.62 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const lodash_1 = require("./wrap/lodash");
4const log_1 = require("./log");
5const anything_1 = require("./stringify/anything");
6const DEFAULTS = {
7 ignoreWarnings: false,
8 promiseConstructor: Promise,
9 suppressErrors: false
10};
11const DELETED_OPTIONS = ['extendWhenReplacingConstructors'];
12let configData = lodash_1.default.extend({}, DEFAULTS);
13exports.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});
22const 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};
30const 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};