UNPKG

1.31 kBJavaScriptView Raw
1import _ from './wrap/lodash'
2import log from './log'
3import stringifyAnything from './stringify/anything'
4
5const DEFAULTS = {
6 ignoreWarnings: false,
7 promiseConstructor: global.Promise,
8 suppressErrors: false
9}
10const DELETED_OPTIONS = ['extendWhenReplacingConstructors']
11
12let configData = _.extend({}, DEFAULTS)
13
14export default _.tap((overrides) => {
15 deleteDeletedOptions(overrides)
16 ensureOverridesExist(overrides)
17 return _.extend(configData, overrides)
18}, (config) => {
19 config.reset = () => {
20 configData = _.extend({}, DEFAULTS)
21 }
22})
23
24const deleteDeletedOptions = (overrides) => {
25 _.each(overrides, (val, key) => {
26 if (_.includes(DELETED_OPTIONS, key)) {
27 log.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}`)
28 delete overrides[key]
29 }
30 })
31}
32
33var ensureOverridesExist = (overrides) => {
34 _.each(overrides, (val, key) => {
35 if (!Object.prototype.hasOwnProperty.call(configData, key)) {
36 log.error('td.config',
37 `"${key}" is not a valid configuration key (valid keys are: ${stringifyAnything(_.keys(configData))})`)
38 }
39 })
40}